1
0
Fork 0

Use healthcheck for systemd watchdog

This commit is contained in:
Guilhem Lettron 2017-11-23 16:10:04 +01:00 committed by Traefiker
parent 66591cf216
commit 24368747ab
2 changed files with 31 additions and 18 deletions

View file

@ -153,10 +153,12 @@ func run(globalConfiguration *configuration.GlobalConfiguration, configFile stri
svr := server.NewServer(*globalConfiguration)
svr.Start()
defer svr.Close()
sent, err := daemon.SdNotify(false, "READY=1")
if !sent && err != nil {
log.Error("Fail to notify", err)
}
t, err := daemon.SdWatchdogEnabled(false)
if err != nil {
log.Error("Problem with watchdog", err)
@ -167,12 +169,18 @@ func run(globalConfiguration *configuration.GlobalConfiguration, configFile stri
safe.Go(func() {
tick := time.Tick(t)
for range tick {
if ok, _ := daemon.SdNotify(false, "WATCHDOG=1"); !ok {
log.Error("Fail to tick watchdog")
_, errHealthCheck := healthCheck(*globalConfiguration)
if globalConfiguration.Ping == nil || errHealthCheck == nil {
if ok, _ := daemon.SdNotify(false, "WATCHDOG=1"); !ok {
log.Error("Fail to tick watchdog")
}
} else {
log.Error(errHealthCheck)
}
}
})
}
svr.Wait()
log.Info("Shutting down")
logrus.Exit(0)