From 3a69c17e4d88a0650eec79fa19a991dce3a82eb6 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 4 Feb 2014 20:32:15 +0000 Subject: [PATCH] Support signalling the daemon on demand. --- Webperl/Daemon.pm | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Webperl/Daemon.pm b/Webperl/Daemon.pm index 11d9ab1..1e0c916 100644 --- a/Webperl/Daemon.pm +++ b/Webperl/Daemon.pm @@ -36,6 +36,7 @@ use constant STATE_OK => 0; use constant STATE_DEAD_PID_EXISTS => 1; use constant STATE_NOT_RUNNING => 3; use constant STATE_ALREADY_RUNNING => 100; +use constant STATE_SIGNAL_ERROR => 101; # ============================================================================ # Constructor @@ -208,4 +209,24 @@ sub kill { return STATE_DEAD_PID_EXISTS; } + +## @method $ signal($signal) +# Signal the running daemon with the specified signal. +# +# @param signal The signal to send to the daemon +# @return STATE_OK on success, STATE_NOT_RUNNING if the daemon is +# not running, otherwise STATE_SIGNAL_ERROR. +sub signal { + my $self = shift; + my $signal = shift; + my $pid = $self -> running(); + + return STATE_NOT_RUNNING if(!$pid); + + my $sent = kill($signal, $pid); + return STATE_OK if($sent); + + return STATE_SIGNAL_ERROR; +} + 1;