mirror of
https://github.com/wneessen/logranger.git
synced 2024-11-22 21:00:50 +01:00
Implemented ReloadConfig method in server
A new ReloadConfig function has been added to the Server in server.go which reloads server configurations and updates the Server's conf field as well as the configured Ruleset. Changes have also been made to the handling of the SIGHUP signal in main.go, using this new function to reload configurations and updating the logs accordingly.
This commit is contained in:
parent
fa527345a3
commit
dd8d660571
2 changed files with 25 additions and 14 deletions
|
@ -58,20 +58,12 @@ func main() {
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
if rc == syscall.SIGHUP {
|
if rc == syscall.SIGHUP {
|
||||||
l.Info(`received "SIGHUP" signal - reloading rules...`)
|
l.Info(`received signal`,
|
||||||
/*
|
slog.String("signal", "SIGHUP"),
|
||||||
_, nr, err := config.New(config.WithConfFile(*cf), config.WithRulesFile(*rf))
|
slog.String("action", "reloading config/ruleset"))
|
||||||
if err != nil {
|
if err = s.ReloadConfig(p, f); err != nil {
|
||||||
s.Log.Errorf("%s - skipping reload", err)
|
l.Error("failed to reload config", LogErrKey, 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)
|
|
||||||
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
19
server.go
19
server.go
|
@ -255,3 +255,22 @@ func (s *Server) setRules() error {
|
||||||
s.ruleset = rs
|
s.ruleset = rs
|
||||||
return nil
|
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
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue