Add support to reload the service.
authorStefan Schantl <stefan.schantl@ipfire.org>
Wed, 25 Nov 2015 11:21:34 +0000 (12:21 +0100)
committerStefan Schantl <stefan.schantl@ipfire.org>
Wed, 25 Nov 2015 11:21:34 +0000 (12:21 +0100)
When sending a "SIGHUP" signal to the guardian process,
we now doing a complete reload of the configuration.

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
guardian

index 2326684..d3f7de0 100644 (file)
--- 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.
 #