]> git.ipfire.org Git - people/stevee/guardian.git/blobdiff - guardian
Just send "KILL" signal to the worker threads.
[people/stevee/guardian.git] / guardian
index cf759b04821511c5394567dadf0e28f1e3522d81..f3c287b593305caf7769618a3439d33c5131cbf8 100644 (file)
--- a/guardian
+++ b/guardian
@@ -265,6 +265,7 @@ sub SignalHandler {
        $SIG{INT} = \&Shutdown;
        $SIG{TERM} = \&Shutdown;
        $SIG{QUIT} = \&Shutdown;
+       $SIG{HUP} = \&Reload;
 }
 
 #
@@ -294,10 +295,31 @@ sub StopWorkers () {
        foreach my $worker (@running_workers) {
                # Send the worker the "KILL" signal and detach the
                # thread so perl can do an automatically clean-up.
-               $worker->kill('KILL')->detach();
+               $worker->kill('KILL');
        }
 }
 
+#
+## 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.
 #
@@ -311,6 +333,11 @@ sub Shutdown () {
        # Remove socket file on exit.
        &Guardian::Socket::RemoveSocketFile();
 
+       # Sleep for one second to give perl some
+       # time to proper clean up everything before
+       # exiting.
+       sleep(1);
+
        # Exit guardian.
        exit;
 }