2023-04-25 10:10:24 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2024-10-21 07:22:54 +00:00
|
|
|
"context"
|
2023-04-25 10:10:24 +00:00
|
|
|
"os"
|
|
|
|
"os/signal"
|
|
|
|
"syscall"
|
|
|
|
|
|
|
|
configViper "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/internal/common/config"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
|
2024-08-14 10:47:50 +00:00
|
|
|
control "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/control/ir"
|
2023-04-25 10:10:24 +00:00
|
|
|
"github.com/spf13/viper"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
|
|
|
func newConfig() (*viper.Viper, error) {
|
|
|
|
var err error
|
2023-10-31 11:56:55 +00:00
|
|
|
dv := viper.New()
|
2023-04-25 10:10:24 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
2024-04-04 08:05:25 +00:00
|
|
|
cmode.Store(cfg.GetBool("node.kludge_compatibility_mode"))
|
2024-06-18 09:40:38 +00:00
|
|
|
audit.Store(cfg.GetBool("audit.enabled"))
|
2023-04-25 10:10:24 +00:00
|
|
|
err = logPrm.SetLevelString(cfg.GetString("logger.level"))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2024-09-16 07:46:26 +00:00
|
|
|
logPrm.PrependTimestamp = cfg.GetBool("logger.timestamp")
|
|
|
|
|
2023-04-25 10:10:24 +00:00
|
|
|
return logPrm.Reload()
|
|
|
|
}
|
|
|
|
|
2024-10-21 08:30:31 +00:00
|
|
|
func watchForSignal(ctx context.Context, cancel func()) {
|
2023-04-25 10:10:24 +00:00
|
|
|
ch := make(chan os.Signal, 1)
|
2024-06-24 12:05:25 +00:00
|
|
|
signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM)
|
|
|
|
|
|
|
|
sighupCh := make(chan os.Signal, 1)
|
|
|
|
signal.Notify(sighupCh, syscall.SIGHUP)
|
2023-04-25 10:10:24 +00:00
|
|
|
|
|
|
|
for {
|
|
|
|
select {
|
2024-06-24 12:05:25 +00:00
|
|
|
// signals causing application to shut down should have priority over
|
|
|
|
// reconfiguration signal
|
|
|
|
case <-ch:
|
2024-10-21 08:30:31 +00:00
|
|
|
log.Info(ctx, logs.FrostFSNodeTerminationSignalHasBeenReceivedStopping)
|
2024-06-24 12:05:25 +00:00
|
|
|
cancel()
|
2024-10-21 08:30:31 +00:00
|
|
|
shutdown(ctx)
|
|
|
|
log.Info(ctx, logs.FrostFSNodeTerminationSignalProcessingIsComplete)
|
2024-06-24 12:05:25 +00:00
|
|
|
return
|
|
|
|
case err := <-intErr: // internal application error
|
2024-10-21 08:30:31 +00:00
|
|
|
log.Info(ctx, logs.FrostFSIRInternalError, zap.String("msg", err.Error()))
|
2023-04-25 10:10:24 +00:00
|
|
|
cancel()
|
2024-10-21 08:30:31 +00:00
|
|
|
shutdown(ctx)
|
2023-04-25 10:10:24 +00:00
|
|
|
return
|
2024-06-24 12:05:25 +00:00
|
|
|
default:
|
|
|
|
// block until any signal is receieved
|
|
|
|
select {
|
|
|
|
case <-ch:
|
2024-10-21 08:30:31 +00:00
|
|
|
log.Info(ctx, logs.FrostFSNodeTerminationSignalHasBeenReceivedStopping)
|
2024-06-24 12:05:25 +00:00
|
|
|
cancel()
|
2024-10-21 08:30:31 +00:00
|
|
|
shutdown(ctx)
|
|
|
|
log.Info(ctx, logs.FrostFSNodeTerminationSignalProcessingIsComplete)
|
2024-06-24 12:05:25 +00:00
|
|
|
return
|
|
|
|
case err := <-intErr: // internal application error
|
2024-10-21 08:30:31 +00:00
|
|
|
log.Info(ctx, logs.FrostFSIRInternalError, zap.String("msg", err.Error()))
|
2024-06-24 12:05:25 +00:00
|
|
|
cancel()
|
2024-10-21 08:30:31 +00:00
|
|
|
shutdown(ctx)
|
2024-06-24 12:05:25 +00:00
|
|
|
return
|
|
|
|
case <-sighupCh:
|
2024-10-21 08:30:31 +00:00
|
|
|
log.Info(ctx, logs.FrostFSNodeSIGHUPHasBeenReceivedRereadingConfiguration)
|
|
|
|
if !innerRing.CompareAndSwapHealthStatus(ctx, control.HealthStatus_READY, control.HealthStatus_RECONFIGURING) {
|
|
|
|
log.Info(ctx, logs.FrostFSNodeSIGHUPSkip)
|
2024-08-14 10:47:50 +00:00
|
|
|
break
|
|
|
|
}
|
2023-04-25 10:10:24 +00:00
|
|
|
err := reloadConfig()
|
|
|
|
if err != nil {
|
2024-10-21 08:30:31 +00:00
|
|
|
log.Error(ctx, logs.FrostFSNodeConfigurationReading, zap.Error(err))
|
2023-04-25 10:10:24 +00:00
|
|
|
}
|
2023-04-26 12:45:57 +00:00
|
|
|
pprofCmp.reload()
|
|
|
|
metricsCmp.reload()
|
2024-10-21 08:30:31 +00:00
|
|
|
log.Info(ctx, logs.FrostFSIRReloadExtraWallets)
|
2023-05-12 07:41:04 +00:00
|
|
|
err = innerRing.SetExtraWallets(cfg)
|
|
|
|
if err != nil {
|
2024-10-21 08:30:31 +00:00
|
|
|
log.Error(ctx, logs.FrostFSNodeConfigurationReading, zap.Error(err))
|
2023-05-12 07:41:04 +00:00
|
|
|
}
|
2024-10-21 08:30:31 +00:00
|
|
|
innerRing.CompareAndSwapHealthStatus(ctx, control.HealthStatus_RECONFIGURING, control.HealthStatus_READY)
|
|
|
|
log.Info(ctx, logs.FrostFSNodeConfigurationHasBeenReloadedSuccessfully)
|
2023-04-25 10:10:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|