diff --git a/cmd/server/main.go b/cmd/server/main.go index cf0eece..6f99ff3 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -58,20 +58,12 @@ func main() { os.Exit(0) } if rc == syscall.SIGHUP { - l.Info(`received "SIGHUP" signal - reloading rules...`) - /* - _, nr, err := config.New(config.WithConfFile(*cf), config.WithRulesFile(*rf)) - if err != nil { - s.Log.Errorf("%s - skipping reload", err) - continue - } - if err := nr.CheckRegEx(); err != nil { - s.Log.Errorf("ruleset validation failed for new ruleset - skipping reload: %s", err) - continue - } - s.SetRules(nr) - - */ + l.Info(`received signal`, + slog.String("signal", "SIGHUP"), + slog.String("action", "reloading config/ruleset")) + if err = s.ReloadConfig(p, f); err != nil { + l.Error("failed to reload config", LogErrKey, err) + } } } } diff --git a/server.go b/server.go index b2f406f..f6ed071 100644 --- a/server.go +++ b/server.go @@ -255,3 +255,22 @@ func (s *Server) setRules() error { s.ruleset = rs return nil } + +// ReloadConfig reloads the configuration of the Server with the specified +// path and filename. +// It creates a new Config using the NewConfig method and updates the Server's +// conf field. It also reloads the configured Ruleset. +// If an error occurs while reloading the configuration, an error is returned. +func (s *Server) ReloadConfig(p, f string) error { + c, err := NewConfig(p, f) + if err != nil { + return fmt.Errorf("failed to reload config: %w", err) + } + s.conf = c + + if err := s.setRules(); err != nil { + return fmt.Errorf("failed to reload ruleset: %w", err) + } + + return nil +}