2023-04-25 10:10:24 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"os/signal"
|
|
|
|
"syscall"
|
|
|
|
|
|
|
|
configViper "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/internal/common/config"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
|
2023-11-01 11:57:23 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client"
|
2023-04-25 10:10:24 +00:00
|
|
|
"github.com/spf13/viper"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
|
|
|
func newConfig() (*viper.Viper, error) {
|
|
|
|
var err error
|
|
|
|
var 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
|
|
|
|
}
|
|
|
|
err = logPrm.SetLevelString(cfg.GetString("logger.level"))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return logPrm.Reload()
|
|
|
|
}
|
|
|
|
|
|
|
|
func watchForSignal(cancel func()) {
|
|
|
|
ch := make(chan os.Signal, 1)
|
|
|
|
signal.Notify(ch, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM)
|
|
|
|
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case err := <-intErr:
|
|
|
|
log.Info(logs.FrostFSIRInternalError, zap.String("msg", err.Error()))
|
|
|
|
cancel()
|
|
|
|
shutdown()
|
|
|
|
return
|
|
|
|
case sig := <-ch:
|
|
|
|
switch sig {
|
|
|
|
case syscall.SIGHUP:
|
|
|
|
log.Info(logs.FrostFSNodeSIGHUPHasBeenReceivedRereadingConfiguration)
|
|
|
|
err := reloadConfig()
|
|
|
|
if err != nil {
|
|
|
|
log.Error(logs.FrostFSNodeConfigurationReading, zap.Error(err))
|
|
|
|
}
|
2023-04-26 12:45:57 +00:00
|
|
|
pprofCmp.reload()
|
|
|
|
metricsCmp.reload()
|
2023-05-12 07:41:04 +00:00
|
|
|
log.Info(logs.FrostFSIRReloadExtraWallets)
|
|
|
|
err = innerRing.SetExtraWallets(cfg)
|
|
|
|
if err != nil {
|
|
|
|
log.Error(logs.FrostFSNodeConfigurationReading, zap.Error(err))
|
|
|
|
}
|
2023-12-12 09:01:10 +00:00
|
|
|
client.CleanInvScript = cfg.GetBool("morph.cleaninvscript")
|
2023-04-25 10:10:24 +00:00
|
|
|
log.Info(logs.FrostFSNodeConfigurationHasBeenReloadedSuccessfully)
|
|
|
|
case syscall.SIGTERM, syscall.SIGINT:
|
|
|
|
log.Info(logs.FrostFSNodeTerminationSignalHasBeenReceivedStopping)
|
|
|
|
cancel()
|
|
|
|
shutdown()
|
|
|
|
log.Info(logs.FrostFSNodeTerminationSignalProcessingIsComplete)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|