From ab3ef7110e2e927215f624ef45b922fd6297cf79 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Fri, 30 Sep 2022 16:33:30 +0300 Subject: [PATCH] [#1770] node: Reread config files on SIGHUP Signed-off-by: Pavel Karpy --- cmd/neofs-node/config.go | 5 +++++ cmd/neofs-node/config/config.go | 18 +++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/cmd/neofs-node/config.go b/cmd/neofs-node/config.go index 203c15747e..6c1eb412ed 100644 --- a/cmd/neofs-node/config.go +++ b/cmd/neofs-node/config.go @@ -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 diff --git a/cmd/neofs-node/config/config.go b/cmd/neofs-node/config/config.go index 609cef113e..0cb79be9df 100644 --- a/cmd/neofs-node/config/config.go +++ b/cmd/neofs-node/config/config.go @@ -17,6 +17,8 @@ import ( type Config struct { v *viper.Viper + opts opts + defaultPath []string path []string } @@ -53,6 +55,20 @@ func New(_ Prm, opts ...Option) *Config { } return &Config{ - v: v, + 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 +}