NAME
Proc::tored::Role::Running
SYNOPSIS
package Some::Thing;
use Moo;
with 'Proc::tored::Running';
sub run {
my $self = shift;
$self->start;
while ($self->is_running) {
do_stuff(...);
}
}
DESCRIPTION
Classes consuming this role are provided with controls to "start" and "stop" voluntarily, along with a SIGTERM handler that is active while the class "is_running". If a SIGTERM is received via another process (by calling "stop_running_process"), the class will voluntarily "stop" itself.
ATTRIBUTES
run_guard
A Guard used to ensure signal handlers are restored when the object is destroyed.
METHODS
is_running
Returns true while the service is running in the current process.
start
Flags the current process as running. While running, handlers for SIGTERM, SIGINT, SIGPIPE, and SIGHUP are installed. After calling this method, "is_running" will return true.
stop
Flags the current process as not running and restores any previously configured signal handlers. Once this method has been called, "is_running" will return false.
stop_running_process
Issues a SIGTERM to the active process. Returns 0 immediately if the pid file does not exist or is empty. Otherwise, polls the running process until the OS reports that it is no longer able to receive signals (with `kill(0, $pid)`).
Optional parameter $timeout may be specified in fractional seconds, causing stop_running_process to block up to (around) $timeout seconds waiting for the signaled process to exit.
Returns the pid of the completed process otherwise.