From ba734c53cc0f9a01e8c077065bc9949c03dc6716 Mon Sep 17 00:00:00 2001 From: Stefan Schantl Date: Wed, 25 Nov 2015 12:21:34 +0100 Subject: [PATCH] Add support to reload the service. When sending a "SIGHUP" signal to the guardian process, we now doing a complete reload of the configuration. Signed-off-by: Stefan Schantl --- guardian | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/guardian b/guardian index 2326684..d3f7de0 100644 --- a/guardian +++ b/guardian @@ -265,6 +265,7 @@ sub SignalHandler { $SIG{INT} = \&Shutdown; $SIG{TERM} = \&Shutdown; $SIG{QUIT} = \&Shutdown; + $SIG{HUP} = \&Reload; } # @@ -298,6 +299,27 @@ sub StopWorkers () { } } +# +## Reload function. +# +## This function will get called if the signal handler recieves a "SIGHUP" signal, +## or the reload command will be sent via socket connection. It is responsible for +## reloading all configure options and stopping/starting the worker threads. +# +sub Reload () { + # Stop all running workers. + &StopWorkers(); + + # Re-read configuration file. + %mainsettings = &Guardian::Config::UseConfig($cmdargs{"config"}); + + # Re-generate hash of monitored files. + %monitored_files = &Guardian::Base::GenerateMonitoredFiles(\%mainsettings, \%monitored_files); + + # Restart the worker threads. + &StartWorkers(); +} + # ## Shutdown function. # -- 2.39.5