Dmitrii Stepanov
692749dba1
Some checks failed
DCO action / DCO (pull_request) Failing after 1m30s
Tests and linters / Run gofumpt (pull_request) Successful in 1m26s
Vulncheck / Vulncheck (pull_request) Successful in 2m11s
Pre-commit hooks / Pre-commit (pull_request) Successful in 2m25s
Build / Build Components (pull_request) Successful in 2m29s
Tests and linters / Lint (pull_request) Failing after 2m26s
Tests and linters / gopls check (pull_request) Successful in 2m43s
Tests and linters / Staticcheck (pull_request) Successful in 2m56s
Tests and linters / Tests (pull_request) Successful in 4m22s
Tests and linters / Tests with -race (pull_request) Successful in 5m58s
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
108 lines
3.3 KiB
Go
108 lines
3.3 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"
|
|
"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"))
|
|
err = logPrm.SetLevelString(cfg.GetString("logger.level"))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
logPrm.PrependTimestamp = cfg.GetBool("logger.timestamp")
|
|
|
|
return logPrm.Reload()
|
|
}
|
|
|
|
func watchForSignal(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(context.Background(), logs.FrostFSNodeTerminationSignalHasBeenReceivedStopping)
|
|
cancel()
|
|
shutdown()
|
|
log.Info(context.Background(), logs.FrostFSNodeTerminationSignalProcessingIsComplete)
|
|
return
|
|
case err := <-intErr: // internal application error
|
|
log.Info(context.Background(), logs.FrostFSIRInternalError, zap.String("msg", err.Error()))
|
|
cancel()
|
|
shutdown()
|
|
return
|
|
default:
|
|
// block until any signal is receieved
|
|
select {
|
|
case <-ch:
|
|
log.Info(context.Background(), logs.FrostFSNodeTerminationSignalHasBeenReceivedStopping)
|
|
cancel()
|
|
shutdown()
|
|
log.Info(context.Background(), logs.FrostFSNodeTerminationSignalProcessingIsComplete)
|
|
return
|
|
case err := <-intErr: // internal application error
|
|
log.Info(context.Background(), logs.FrostFSIRInternalError, zap.String("msg", err.Error()))
|
|
cancel()
|
|
shutdown()
|
|
return
|
|
case <-sighupCh:
|
|
log.Info(context.Background(), logs.FrostFSNodeSIGHUPHasBeenReceivedRereadingConfiguration)
|
|
if !innerRing.CompareAndSwapHealthStatus(control.HealthStatus_READY, control.HealthStatus_RECONFIGURING) {
|
|
log.Info(context.Background(), logs.FrostFSNodeSIGHUPSkip)
|
|
break
|
|
}
|
|
err := reloadConfig()
|
|
if err != nil {
|
|
log.Error(context.Background(), logs.FrostFSNodeConfigurationReading, zap.Error(err))
|
|
}
|
|
pprofCmp.reload()
|
|
metricsCmp.reload()
|
|
log.Info(context.Background(), logs.FrostFSIRReloadExtraWallets)
|
|
err = innerRing.SetExtraWallets(cfg)
|
|
if err != nil {
|
|
log.Error(context.Background(), logs.FrostFSNodeConfigurationReading, zap.Error(err))
|
|
}
|
|
innerRing.CompareAndSwapHealthStatus(control.HealthStatus_RECONFIGURING, control.HealthStatus_READY)
|
|
log.Info(context.Background(), logs.FrostFSNodeConfigurationHasBeenReloadedSuccessfully)
|
|
}
|
|
}
|
|
}
|
|
}
|