]> git.ipfire.org Git - people/stevee/guardian.git/commitdiff
Add support to daemonize guardian.
authorStefan Schantl <stefan.schantl@ipfire.org>
Wed, 9 Dec 2015 13:46:17 +0000 (14:46 +0100)
committerStefan Schantl <stefan.schantl@ipfire.org>
Wed, 9 Dec 2015 13:46:17 +0000 (14:46 +0100)
Guardian now will be launched in daemon mode as default. Using the
"--foreground (-f)" command line switch will prevent the process from
forking into the background.

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

index 22856c9395b087be9caffb8072775ce920bed307..acbd5453563001322d7f9ed44305784a40ec96bc 100644 (file)
--- a/guardian
+++ b/guardian
@@ -29,6 +29,7 @@ use Time::HiRes qw[ time sleep ];
 
 require Guardian::Base;
 require Guardian::Config;
+require Guardian::Daemon;
 require Guardian::Logger;
 require Guardian::Parser;
 require Guardian::Socket;
@@ -92,6 +93,15 @@ my $queue :shared = new Thread::Queue or die "Could not create new, empty queue.
 # (Does not include the socket thread)
 my @running_workers;
 
+# Check if guardian should be daemonized or keep in the foreground.
+unless (defined($cmdargs{"foreground"})) {
+       # Fork into background.
+       &Guardian::Daemon::Daemonize();
+} else {
+       # Write PID (process-id).
+       &Guardian::Daemon::WritePID();
+}
+
 # Call Init function to initzialize guardian.
 &Init();