From ccf4f8e1c2fd681c8186e51fc1df93f42ef6e8bb Mon Sep 17 00:00:00 2001 From: Stefan Schantl Date: Wed, 9 Dec 2015 14:46:17 +0100 Subject: [PATCH] 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 --- guardian | 10 ++++++++++ 1 file changed, 10 insertions(+) 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(); -- 2.39.5