Add systemd watchdog feature
This commit is contained in:
parent
da5eba17d8
commit
d324040adc
3 changed files with 24 additions and 3 deletions
|
@ -4,7 +4,8 @@ Description=Traefik
|
||||||
[Service]
|
[Service]
|
||||||
Type=notify
|
Type=notify
|
||||||
ExecStart=/usr/bin/traefik --configFile=/etc/traefik.toml
|
ExecStart=/usr/bin/traefik --configFile=/etc/traefik.toml
|
||||||
Restart=on-failure
|
Restart=always
|
||||||
|
WatchdogSec=1s
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
|
|
|
@ -108,7 +108,7 @@ import:
|
||||||
- package: github.com/mitchellh/mapstructure
|
- package: github.com/mitchellh/mapstructure
|
||||||
version: f3009df150dadf309fdee4a54ed65c124afad715
|
version: f3009df150dadf309fdee4a54ed65c124afad715
|
||||||
- package: github.com/coreos/go-systemd
|
- package: github.com/coreos/go-systemd
|
||||||
version: v12
|
version: v14
|
||||||
subpackages:
|
subpackages:
|
||||||
- daemon
|
- daemon
|
||||||
- package: github.com/google/go-github
|
- package: github.com/google/go-github
|
||||||
|
|
22
traefik.go
22
traefik.go
|
@ -244,10 +244,30 @@ func run(traefikConfiguration *TraefikConfiguration) {
|
||||||
server := NewServer(globalConfiguration)
|
server := NewServer(globalConfiguration)
|
||||||
server.Start()
|
server.Start()
|
||||||
defer server.Close()
|
defer server.Close()
|
||||||
sent, err := daemon.SdNotify("READY=1")
|
sent, err := daemon.SdNotify(true, "READY=1")
|
||||||
if !sent && err != nil {
|
if !sent && err != nil {
|
||||||
log.Error("Fail to notify", err)
|
log.Error("Fail to notify", err)
|
||||||
}
|
}
|
||||||
|
t, err := daemon.SdWatchdogEnabled(true)
|
||||||
|
if err != nil {
|
||||||
|
log.Error("Problem with watchdog", err)
|
||||||
|
} else if t != 0 {
|
||||||
|
// Send a ping each half time given
|
||||||
|
t = t / 2
|
||||||
|
go func(interval time.Duration) {
|
||||||
|
tick := time.Tick(interval)
|
||||||
|
for range tick {
|
||||||
|
if server.globalConfiguration.Web != nil {
|
||||||
|
if _, err := http.Head("http://" + server.globalConfiguration.Web.Address + "/ping"); err == nil {
|
||||||
|
daemon.SdNotify(true, "WATCHDOG=1")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
daemon.SdNotify(true, "WATCHDOG=1")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}(t)
|
||||||
|
}
|
||||||
|
log.Info(t.String())
|
||||||
server.Wait()
|
server.Wait()
|
||||||
log.Info("Shutting down")
|
log.Info("Shutting down")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue