diff --git a/cmd/circologd/main.go b/cmd/circologd/main.go index cf0a202..41fb95b 100644 --- a/cmd/circologd/main.go +++ b/cmd/circologd/main.go @@ -9,8 +9,10 @@ import ( "os" "os/signal" "syscall" + "time" "git.lattuga.net/boyska/circolog" + "github.com/coreos/go-systemd/daemon" syslog "gopkg.in/mcuadros/go-syslog.v2" ) @@ -103,10 +105,17 @@ func main() { }() } - // TODO: now we are ready + daemon.SdNotify(false, daemon.SdNotifyReady) + var wdTick <-chan time.Time + if watchdogTime, err := daemon.SdWatchdogEnabled(false); err == nil && watchdogTime != 0 { + fmt.Println("systemd watchdog enabled") + wdTick = time.Tick(watchdogTime / 2) // much less than systemd default of 30s; TODO: make it configurable + } for { select { + case <-wdTick: + daemon.SdNotify(false, daemon.SdNotifyWatchdog) case sig := <-interrupt: if sig == syscall.SIGUSR1 { response := make(chan circolog.CommandResponse) @@ -130,6 +139,7 @@ func main() { } if sig == syscall.SIGTERM || sig == syscall.SIGINT { log.Println("Quitting because of signal", sig) + daemon.SdNotify(false, daemon.SdNotifyStopping) server.Kill() if err := httpQueryServer.Shutdown(nil); err != nil { fmt.Fprintln(os.Stderr, "Error closing http server:", err)