[#552] Add systemd notifications to ir service
DCO action / DCO (pull_request) Successful in 3m19s Details
Vulncheck / Vulncheck (pull_request) Successful in 3m25s Details
Build / Build Components (1.21) (pull_request) Successful in 4m27s Details
Build / Build Components (1.20) (pull_request) Successful in 4m41s Details
Tests and linters / Staticcheck (pull_request) Successful in 5m5s Details
Tests and linters / Lint (pull_request) Successful in 5m57s Details
Tests and linters / Tests (1.20) (pull_request) Successful in 13m25s Details
Tests and linters / Tests (1.21) (pull_request) Successful in 14m13s Details
Tests and linters / Tests with -race (pull_request) Successful in 16m15s Details

Signed-off-by: Ekaterina Lebedeva <ekaterina.lebedeva@yadro.com>
pull/810/head
Ekaterina Lebedeva 2023-12-05 17:05:34 +03:00
parent ef07c1a3c9
commit 2d4c0a0f4a
3 changed files with 37 additions and 0 deletions

View File

@ -119,3 +119,6 @@ prometheus:
enabled: true
address: localhost:9090 # Endpoint for application prometheus metrics; disabled by default
shutdown_timeout: 30s # Timeout for metrics HTTP server graceful shutdown
systemdnotify:
enabled: true

View File

@ -24,6 +24,7 @@ import (
control "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/control/ir"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/precision"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/sdnotify"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/state"
"github.com/nspcc-dev/neo-go/pkg/core/block"
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
@ -73,6 +74,7 @@ type (
predefinedValidators keys.PublicKeys
initialEpochTickDelta uint32
withoutMainNet bool
sdNotify bool
// runtime processors
netmapProcessor *netmap.Processor
@ -336,6 +338,11 @@ func New(ctx context.Context, log *logger.Logger, cfg *viper.Viper, errChan chan
irMetrics: metrics,
}
server.sdNotify, err = server.initSdNotify(cfg)
if err != nil {
return nil, err
}
server.setHealthStatus(control.HealthStatus_HEALTH_STATUS_UNDEFINED)
// parse notary support
@ -404,6 +411,13 @@ func New(ctx context.Context, log *logger.Logger, cfg *viper.Viper, errChan chan
return server, nil
}
func (s *Server) initSdNotify(cfg *viper.Viper) (bool, error) {
if cfg.GetBool("systemdnotify.enabled") {
return true, sdnotify.InitSocket()
}
return false, nil
}
func createListener(ctx context.Context, cli *client.Client, p *chainParams) (event.Listener, error) {
var (
sub subscriber.Subscriber

View File

@ -7,6 +7,7 @@ import (
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/innerring/processors/governance"
control "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/control/ir"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/sdnotify"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/state"
"github.com/nspcc-dev/neo-go/pkg/util"
"github.com/spf13/viper"
@ -154,6 +155,7 @@ func (s *Server) ResetEpochTimer(h uint32) error {
func (s *Server) setHealthStatus(hs control.HealthStatus) {
s.healthStatus.Store(int32(hs))
s.notifySystemd(hs)
if s.irMetrics != nil {
s.irMetrics.SetHealth(int32(hs))
}
@ -173,3 +175,21 @@ func initPersistentStateStorage(cfg *viper.Viper) (*state.PersistentStorage, err
return persistStorage, nil
}
func (s *Server) notifySystemd(st control.HealthStatus) {
if !s.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)
default:
err = sdnotify.Status(fmt.Sprintf("%v", st))
}
if err != nil {
s.log.Error(logs.FailedToReportStatusToSystemd, zap.Error(err))
}
}