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:
parent
18ba5fe528
commit
0058bc063e
@ -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")
|
||||
|
||||
|
@ -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")
|
||||
|
||||
|
@ -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)
|
||||
|
@ -6,5 +6,6 @@ func ServiceManagerStartNotify() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func ServiceManagerReadyNotify() {
|
||||
func ServiceManagerReadyNotify() error {
|
||||
return nil
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -6,5 +6,6 @@ func ServiceManagerStartNotify() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func ServiceManagerReadyNotify() {
|
||||
func ServiceManagerReadyNotify() error {
|
||||
return nil
|
||||
}
|
||||
|
@ -11,4 +11,6 @@ func ServiceManagerStartNotify() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func ServiceManagerReadyNotify() {}
|
||||
func ServiceManagerReadyNotify() error {
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user