d8d8ce7526
watch if chain head changes in a given window of api polls allows setting a threshold of how many times the chain head can remain unchanged before failing health check also can set interval for polling chain head on failure, restarts systemd unit
25 lines
410 B
Go
25 lines
410 B
Go
package main
|
|
|
|
import (
|
|
"github.com/coreos/go-systemd/dbus"
|
|
)
|
|
|
|
func alertHandler(n string, ch chan interface{}) (string, error) {
|
|
select {
|
|
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
|
|
}
|
|
}
|
|
}
|