mirror of
https://github.com/wneessen/logranger.git
synced 2024-12-23 02:20:39 +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)
|
||||
}
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
19
server.go
19
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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue