445b7f3388
add retry logic when calls to API fail. if API reconnects fail, restart lotus-daemon as it means lotus-daemon is likely unhealthy. wait for lotus node's chain to sync during each check cycle, to avoid restarting lotus-daemon if needing to sync. handle SIGTERM properly. general cleanup and refactor of code, getting ready of unnecessary channels
32 lines
528 B
Go
32 lines
528 B
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
|
|
"github.com/coreos/go-systemd/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
|
|
}
|
|
}
|