I shipped a tiny daemon in Go this week and the whole thing is faintly anticlimactic, in the best way. It watches a spool directory, and every thirty seconds it counts what's in there and posts the number to our metrics endpoint. That's it. Forty-odd lines. The kind of job I'd previously have done with a cron script and a prayer.
The reason I reached for Go rather than the shell-and-cron approach is the deployment story. go build, scp one static binary to the box, drop in a systemd unit, done. No interpreter to match, no virtualenv, no "which version of Python is on this host". The binary brings everything with it. For a thing that needs to sit there for months without anyone thinking about it, that self-containment is the whole point.
The bit that made it feel finished rather than hacked-together was handling shutdown properly, so that when systemd stops it the daemon finishes its current tick and exits cleanly instead of being killed mid-write.
sig := make(chan os.Signal, 1)
signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM)
ticker := time.NewTicker(30 * time.Second)
for {
select {
case <-ticker.C:
report()
case <-sig:
log.Println("shutting down")
return
}
}
Nothing clever, and that's rather the appeal. A select over a ticker and a signal channel is the boring correct shape for this, and Go hands it to you without ceremony. It's been running since Tuesday, posting its little number every thirty seconds, and I've already half forgotten it exists. That's the highest compliment I can pay a daemon.