All checks were successful
Vulncheck / Vulncheck (push) Successful in 1m45s
Build / Build Components (push) Successful in 2m22s
Pre-commit hooks / Pre-commit (push) Successful in 2m25s
Tests and linters / gopls check (push) Successful in 4m16s
OCI image / Build container images (push) Successful in 5m26s
Tests and linters / Lint (push) Successful in 6m0s
Tests and linters / Run gofumpt (push) Successful in 6m45s
Tests and linters / Tests (push) Successful in 7m8s
Tests and linters / Tests with -race (push) Successful in 7m6s
Tests and linters / Staticcheck (push) Successful in 7m10s
Change-Id: Ide892b250304b8cdb6c279f5f728c3b35f05df54 Signed-off-by: Anton Nikiforov <an.nikiforov@yadro.com>
110 lines
3.2 KiB
Go
110 lines
3.2 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"os/signal"
|
|
"syscall"
|
|
|
|
configViper "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/internal/common/config"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
|
|
control "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/control/ir"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger"
|
|
"github.com/spf13/viper"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
func newConfig() (*viper.Viper, error) {
|
|
var err error
|
|
dv := viper.New()
|
|
|
|
defaultConfiguration(dv)
|
|
|
|
_, err = configViper.CreateViper(configViper.WithConfigFile(*configFile),
|
|
configViper.WithConfigDir(*configDir), configViper.WithEnvPrefix(EnvPrefix),
|
|
configViper.WithViper(dv))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return dv, err
|
|
}
|
|
|
|
func reloadConfig() error {
|
|
err := configViper.ReloadViper(configViper.WithConfigFile(*configFile),
|
|
configViper.WithConfigDir(*configDir), configViper.WithEnvPrefix(EnvPrefix),
|
|
configViper.WithViper(cfg))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
cmode.Store(cfg.GetBool("node.kludge_compatibility_mode"))
|
|
audit.Store(cfg.GetBool("audit.enabled"))
|
|
var logPrm logger.Prm
|
|
err = logPrm.SetLevelString(cfg.GetString("logger.level"))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
log.Reload(logPrm)
|
|
|
|
return nil
|
|
}
|
|
|
|
func watchForSignal(ctx context.Context, cancel func()) {
|
|
ch := make(chan os.Signal, 1)
|
|
signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM)
|
|
|
|
sighupCh := make(chan os.Signal, 1)
|
|
signal.Notify(sighupCh, syscall.SIGHUP)
|
|
|
|
for {
|
|
select {
|
|
// signals causing application to shut down should have priority over
|
|
// reconfiguration signal
|
|
case <-ch:
|
|
log.Info(ctx, logs.FrostFSNodeTerminationSignalHasBeenReceivedStopping)
|
|
cancel()
|
|
shutdown(ctx)
|
|
log.Info(ctx, logs.FrostFSNodeTerminationSignalProcessingIsComplete)
|
|
return
|
|
case err := <-intErr: // internal application error
|
|
log.Info(ctx, logs.FrostFSIRInternalError, zap.String("msg", err.Error()))
|
|
cancel()
|
|
shutdown(ctx)
|
|
return
|
|
default:
|
|
// block until any signal is receieved
|
|
select {
|
|
case <-ch:
|
|
log.Info(ctx, logs.FrostFSNodeTerminationSignalHasBeenReceivedStopping)
|
|
cancel()
|
|
shutdown(ctx)
|
|
log.Info(ctx, logs.FrostFSNodeTerminationSignalProcessingIsComplete)
|
|
return
|
|
case err := <-intErr: // internal application error
|
|
log.Info(ctx, logs.FrostFSIRInternalError, zap.String("msg", err.Error()))
|
|
cancel()
|
|
shutdown(ctx)
|
|
return
|
|
case <-sighupCh:
|
|
log.Info(ctx, logs.FrostFSNodeSIGHUPHasBeenReceivedRereadingConfiguration)
|
|
if !innerRing.CompareAndSwapHealthStatus(ctx, control.HealthStatus_READY, control.HealthStatus_RECONFIGURING) {
|
|
log.Info(ctx, logs.FrostFSNodeSIGHUPSkip)
|
|
break
|
|
}
|
|
err := reloadConfig()
|
|
if err != nil {
|
|
log.Error(ctx, logs.FrostFSNodeConfigurationReading, zap.Error(err))
|
|
}
|
|
pprofCmp.reload(ctx)
|
|
metricsCmp.reload(ctx)
|
|
log.Info(ctx, logs.FrostFSIRReloadExtraWallets)
|
|
err = innerRing.SetExtraWallets(cfg)
|
|
if err != nil {
|
|
log.Error(ctx, logs.FrostFSNodeConfigurationReading, zap.Error(err))
|
|
}
|
|
innerRing.CompareAndSwapHealthStatus(ctx, control.HealthStatus_RECONFIGURING, control.HealthStatus_READY)
|
|
log.Info(ctx, logs.FrostFSNodeConfigurationHasBeenReloadedSuccessfully)
|
|
}
|
|
}
|
|
}
|
|
}
|