[#552] Add sysd notifications to storage service

Signed-off-by: Ekaterina Lebedeva <ekaterina.lebedeva@yadro.com>
This commit is contained in:
Ekaterina Lebedeva 2023-11-21 15:07:37 +03:00
parent eca7ac9f0d
commit ef07c1a3c9
3 changed files with 29 additions and 5 deletions

View file

@ -110,12 +110,21 @@ func (c *cfg) HealthStatus() control.HealthStatus {
}
func (c *cfg) notifySystemd(st control.HealthStatus) {
status := fmt.Sprintf("%v, %v", st.Number(), st)
err := sdnotify.Status(status)
if err == nil {
c.log.Info(fmt.Sprintf("reported STATUS=\"%v\" to systemd", status))
if !c.sdNotify {
return
}
var err error
switch st {
case control.HealthStatus_READY:
err = sdnotify.FlagAndStatus(sdnotify.ReadyEnabled)
case control.HealthStatus_SHUTTING_DOWN:
err = sdnotify.FlagAndStatus(sdnotify.StoppingEnabled)
case control.HealthStatus_RECONFIGURING:
err = sdnotify.FlagAndStatus(sdnotify.ReloadingEnabled)
default:
err = sdnotify.Status(fmt.Sprintf("%v", st))
}
if err != nil {
c.log.Error(logs.FailedToReportStatusToSystemd, zap.String("error", err.Error()))
c.log.Error(logs.FailedToReportStatusToSystemd, zap.Error(err))
}
}