forked from TrueCloudLab/frostfs-node
[#552] Add status notification to systemd
Signed-off-by: Ekaterina Lebedeva <ekaterina.lebedeva@yadro.com>
This commit is contained in:
parent
05f8f49289
commit
9b2dce5763
6 changed files with 23 additions and 2 deletions
|
@ -2,6 +2,7 @@ package main
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net"
|
||||
|
||||
controlconfig "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-node/config/control"
|
||||
|
@ -10,6 +11,7 @@ import (
|
|||
controlSvc "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/control/server"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/tree"
|
||||
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
||||
sysdnotify "github.com/iguanesolutions/go-systemd/v5/notify"
|
||||
"go.uber.org/zap"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
@ -83,12 +85,14 @@ func (c *cfg) NetmapStatus() control.NetmapStatus {
|
|||
}
|
||||
|
||||
func (c *cfg) setHealthStatus(st control.HealthStatus) {
|
||||
c.notifySystemd(st)
|
||||
c.healthStatus.Store(int32(st))
|
||||
c.metricsCollector.State().SetHealth(int32(st))
|
||||
}
|
||||
|
||||
func (c *cfg) compareAndSwapHealthStatus(oldSt, newSt control.HealthStatus) (swapped bool) {
|
||||
if swapped = c.healthStatus.CompareAndSwap(int32(oldSt), int32(newSt)); swapped {
|
||||
c.notifySystemd(newSt)
|
||||
c.metricsCollector.State().SetHealth(int32(newSt))
|
||||
}
|
||||
return
|
||||
|
@ -96,6 +100,7 @@ func (c *cfg) compareAndSwapHealthStatus(oldSt, newSt control.HealthStatus) (swa
|
|||
|
||||
func (c *cfg) swapHealthStatus(st control.HealthStatus) (old control.HealthStatus) {
|
||||
old = control.HealthStatus(c.healthStatus.Swap(int32(st)))
|
||||
c.notifySystemd(st)
|
||||
c.metricsCollector.State().SetHealth(int32(st))
|
||||
return
|
||||
}
|
||||
|
@ -103,3 +108,15 @@ func (c *cfg) swapHealthStatus(st control.HealthStatus) (old control.HealthStatu
|
|||
func (c *cfg) HealthStatus() control.HealthStatus {
|
||||
return control.HealthStatus(c.healthStatus.Load())
|
||||
}
|
||||
|
||||
func (c *cfg) notifySystemd(st control.HealthStatus) string {
|
||||
status := fmt.Sprintf("%v, %v", st.Number(), st)
|
||||
err := sysdnotify.Status(status)
|
||||
if err == nil {
|
||||
c.log.Info(fmt.Sprintf("reported STATUS=\"%v\" to systemd", status))
|
||||
}
|
||||
if err != nil {
|
||||
c.log.Error(logs.FailedToReportStatusToSystemd, zap.String("error", err.Error()))
|
||||
}
|
||||
return fmt.Sprintf("%v, %v", st, control.HealthStatus_name[int32(st)])
|
||||
}
|
||||
|
|
3
debian/frostfs-ir.service
vendored
3
debian/frostfs-ir.service
vendored
|
@ -3,7 +3,8 @@ Description=FrostFS InnerRing node
|
|||
Requires=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
Type=notify
|
||||
NotifyAccess=all
|
||||
ExecStart=/usr/bin/frostfs-ir --config /etc/frostfs/ir/config.yml
|
||||
User=frostfs-ir
|
||||
Group=frostfs-ir
|
||||
|
|
3
debian/frostfs-storage.service
vendored
3
debian/frostfs-storage.service
vendored
|
@ -3,7 +3,8 @@ Description=FrostFS Storage node
|
|||
Requires=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
Type=notify
|
||||
NotifyAccess=all
|
||||
ExecStart=/usr/bin/frostfs-node --config /etc/frostfs/storage/config.yml
|
||||
User=frostfs-storage
|
||||
Group=frostfs-storage
|
||||
|
|
1
go.mod
1
go.mod
|
@ -16,6 +16,7 @@ require (
|
|||
github.com/flynn-archive/go-shlex v0.0.0-20150515145356-3f9db97f8568
|
||||
github.com/google/uuid v1.4.0
|
||||
github.com/hashicorp/golang-lru/v2 v2.0.7
|
||||
github.com/iguanesolutions/go-systemd/v5 v5.1.1
|
||||
github.com/klauspost/compress v1.17.4
|
||||
github.com/mitchellh/go-homedir v1.1.0
|
||||
github.com/mr-tron/base58 v1.2.0
|
||||
|
|
BIN
go.sum
BIN
go.sum
Binary file not shown.
|
@ -554,4 +554,5 @@ const (
|
|||
BlobovniczaSavingCountersToMetaSuccess = "saving counters to blobovnicza's meta completed successfully"
|
||||
BlobovniczaSavingCountersToMetaFailed = "saving counters to blobovnicza's meta failed"
|
||||
ObjectRemovalFailureExistsInWritecache = "can't remove object: object must be flushed from writecache"
|
||||
FailedToReportStatusToSystemd = "failed to report status to systemd"
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue