lotus/cmd/lotus-health/notify.go
Peter Rabbitson 8b01725129 Dep upgrade pass
Touching just the seemingly non-controversial ones
2021-10-08 12:37:40 +02:00

33 lines
590 B
Go

package main
import (
"context"
"os"
"github.com/coreos/go-systemd/v22/dbus"
)
func notifyHandler(ctx context.Context, 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.NewWithContext(ctx)
if err != nil {
return "", err
}
_, err = c.TryRestartUnitContext(ctx, n, "fail", statusCh)
if err != nil {
return "", err
}
select {
case result := <-statusCh:
return result, nil
}
// SIGTERM
case <-sCh:
os.Exit(1)
return "", nil
}
}