systemd notify and watchdog (closes #12)
This commit is contained in:
parent
eff3998eb7
commit
0121ba64b5
1 changed files with 11 additions and 1 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue