lotus/cmd/lotus-health/notify.go
Jakub Sztandera 14580b6144
Import go-systemd properly
Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
2020-02-12 20:44:35 +01:00

32 lines
532 B
Go

package main
import (
"os"
"github.com/coreos/go-systemd/v22/dbus"
)
func notifyHandler(n string, ch chan interface{}, sCh chan os.Signal) (string, error) {
select {
// alerts to restart systemd unit
case <-ch:
statusCh := make(chan string, 1)
c, err := dbus.New()
if err != nil {
return "", err
}
_, err = c.TryRestartUnit(n, "fail", statusCh)
if err != nil {
return "", err
}
select {
case result := <-statusCh:
return result, nil
}
// SIGTERM
case <-sCh:
os.Exit(1)
return "", nil
}
}