1
0
mirror of https://github.com/DNSCrypt/dnscrypt-proxy.git synced 2024-12-28 00:20:13 +01:00

feature: service_linux: Support systemd watchdog

This commit is contained in:
Markus Linnala 2019-10-03 15:39:09 +03:00 committed by Frank Denis
parent 18ba5fe528
commit 0058bc063e
7 changed files with 41 additions and 8 deletions

View File

@ -47,7 +47,9 @@ func (proxy *Proxy) dropPrivilege(userStr string, fds []*os.File) {
dlog.Fatal(err)
}
ServiceManagerReadyNotify()
if err := ServiceManagerReadyNotify(); err != nil {
dlog.Fatal(err)
}
args = append(args, "-child")

View File

@ -48,7 +48,9 @@ func (proxy *Proxy) dropPrivilege(userStr string, fds []*os.File) {
dlog.Fatal(err)
}
ServiceManagerReadyNotify()
if err := ServiceManagerReadyNotify(); err != nil {
dlog.Fatal(err)
}
args = append(args, "-child")

View File

@ -166,7 +166,9 @@ func (proxy *Proxy) StartProxy() {
if liveServers > 0 {
dlog.Noticef("dnscrypt-proxy is ready - live servers: %d", liveServers)
if !proxy.child {
ServiceManagerReadyNotify()
if err := ServiceManagerReadyNotify(); err != nil {
dlog.Fatal(err)
}
}
} else if err != nil {
dlog.Error(err)

View File

@ -6,5 +6,6 @@ func ServiceManagerStartNotify() error {
return nil
}
func ServiceManagerReadyNotify() {
func ServiceManagerReadyNotify() error {
return nil
}

View File

@ -2,13 +2,36 @@
package main
import "github.com/coreos/go-systemd/daemon"
import (
"github.com/coreos/go-systemd/daemon"
clocksmith "github.com/jedisct1/go-clocksmith"
)
func ServiceManagerStartNotify() error {
daemon.SdNotify(false, "STATUS=Starting")
return nil
}
func ServiceManagerReadyNotify() {
func ServiceManagerReadyNotify() error {
daemon.SdNotify(false, "READY=1")
return systemDWatchdog()
}
func systemDWatchdog() error {
watchdogFailureDelay, err := daemon.SdWatchdogEnabled(false)
if err != nil || watchdogFailureDelay == 0 {
return err
}
refreshInterval := watchdogFailureDelay / 3
go func() {
for {
// TODO There could be other checks this just
// checks program is not totally stuck and can
// run this goroutine
daemon.SdNotify(false, "WATCHDOG=1")
clocksmith.Sleep(refreshInterval)
}
}()
return nil
}

View File

@ -6,5 +6,6 @@ func ServiceManagerStartNotify() error {
return nil
}
func ServiceManagerReadyNotify() {
func ServiceManagerReadyNotify() error {
return nil
}

View File

@ -11,4 +11,6 @@ func ServiceManagerStartNotify() error {
return nil
}
func ServiceManagerReadyNotify() {}
func ServiceManagerReadyNotify() error {
return nil
}