forked from TrueCloudLab/frostfs-node
[#1770] node: Reread config files on SIGHUP
Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>support/v0.34
parent
6fc3268ebf
commit
ab3ef7110e
|
@ -154,6 +154,11 @@ func (a *applicationConfiguration) readConfig(c *config.Config) error {
|
|||
if a._read {
|
||||
// clear if it is rereading
|
||||
*a = applicationConfiguration{}
|
||||
|
||||
err := c.Reload()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
// update the status
|
||||
a._read = true
|
||||
|
|
|
@ -17,6 +17,8 @@ import (
|
|||
type Config struct {
|
||||
v *viper.Viper
|
||||
|
||||
opts opts
|
||||
|
||||
defaultPath []string
|
||||
path []string
|
||||
}
|
||||
|
@ -54,5 +56,19 @@ func New(_ Prm, opts ...Option) *Config {
|
|||
|
||||
return &Config{
|
||||
v: v,
|
||||
opts: *o,
|
||||
}
|
||||
}
|
||||
|
||||
// Reload reads configuration path if any was provided
|
||||
// to the New. Returns any
|
||||
func (x *Config) Reload() error {
|
||||
if x.opts.path != "" {
|
||||
err := x.v.ReadInConfig()
|
||||
if err != nil {
|
||||
return fmt.Errorf("rereading configuration file: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue