From: Stefan Schantl Date: Wed, 9 Dec 2015 13:46:17 +0000 (+0100) Subject: Add support to daemonize guardian. X-Git-Tag: 2.0~54 X-Git-Url: http://git.ipfire.org/?p=people%2Fstevee%2Fguardian.git;a=commitdiff_plain;h=ccf4f8e1c2fd681c8186e51fc1df93f42ef6e8bb Add support to daemonize guardian. 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 --- diff --git a/guardian b/guardian index 22856c9..acbd545 100644 --- 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();