From 9b2dce5763de16e2374428884ec6cf8072256337 Mon Sep 17 00:00:00 2001 From: Ekaterina Lebedeva Date: Thu, 16 Nov 2023 02:48:05 +0300 Subject: [PATCH] [#552] Add status notification to systemd Signed-off-by: Ekaterina Lebedeva --- cmd/frostfs-node/control.go | 17 +++++++++++++++++ debian/frostfs-ir.service | 3 ++- debian/frostfs-storage.service | 3 ++- go.mod | 1 + go.sum | Bin 45864 -> 46999 bytes internal/logs/logs.go | 1 + 6 files changed, 23 insertions(+), 2 deletions(-) diff --git a/cmd/frostfs-node/control.go b/cmd/frostfs-node/control.go index 4f5c5d78..fcd84db3 100644 --- a/cmd/frostfs-node/control.go +++ b/cmd/frostfs-node/control.go @@ -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)]) +} diff --git a/debian/frostfs-ir.service b/debian/frostfs-ir.service index b59295ac..304017f6 100644 --- a/debian/frostfs-ir.service +++ b/debian/frostfs-ir.service @@ -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 diff --git a/debian/frostfs-storage.service b/debian/frostfs-storage.service index 6e7d1dd5..57396175 100644 --- a/debian/frostfs-storage.service +++ b/debian/frostfs-storage.service @@ -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 diff --git a/go.mod b/go.mod index 3e79f7ff..3037a616 100644 --- a/go.mod +++ b/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 diff --git a/go.sum b/go.sum index 15ae22422585062b9c83d02a3b832152a1cfb18f..780bdbcdbd1cc9f32d367400a9efc03fb377e0c2 100644 GIT binary patch delta 990 zcmb`_J93*)6b9gl(`6M(8;#*!-ee{PMhKxNvJ8^k@w|Y6D*+b?H!MO$wvaM2NtyMe z^%fGRi7bx_O|pRVo&WrEzWluU{B-qImJUC}_bm%}hJzBvF#L7kxE_#Y7Xrtn5vDTi zcOv)^?Zsk;?Z^v>J<@s7IP#!m7yCrij5_sg94br0s&q_tpWdOkiik^jIHO}koIEIT zN~##=Z%&{Vwvx7JWuO^pb31?(-63zhMRnQ?ga1|7Q6 z2N_VuMVkBV#t7;dH5#Lfgq^O2#vP+fn~IoyICF{_*He0#$mY`X^jko|!*{9oO_rV> Fe*t3SOf>)i delta 14 WcmbRKo@vE1rVW-Bn^)MpuL1xzTL(G- diff --git a/internal/logs/logs.go b/internal/logs/logs.go index c996e830..1775b18c 100644 --- a/internal/logs/logs.go +++ b/internal/logs/logs.go @@ -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" )