Standardised code to daemonise a process and run a timed loop.
Go to file
2022-11-17 16:51:45 +00:00
dist Add explicit Provides to spec 2022-11-17 16:51:45 +00:00
lib/Proc/Simple Initial Checkin 2017-08-13 22:06:28 +01:00
LICENSE Initial Checkin 2017-08-13 22:06:28 +01:00
Makefile.PL Correct URLs in Makefile.PL 2021-02-18 16:50:46 +00:00
README.md Regenerate README.md 2017-08-13 22:07:10 +01:00

NAME

Proc::Simple::Daemon - Provide a standard daemonised loop method

VERSION

version 1.0

SYNOPSIS

my $loop = Proc::Simple::Daemon->new;

my $vars->{'loop'} = $loop;

$loop->foreground(1)
    if $vars->{'run_in_foreground'};

$loop->run( \&mycallback, $vars );

# This will be executed as a different process ID unless we are
# set for foreground
sub
mycallback
{
    my $vars = shift;
    # do stuff
    $vars->{'loop'}->stop
        if $vars->{'need_to_stop'};
    return;
}

DESCRIPTION

Proc::Simple::Daemon is a module to provide a standard daemon framework with timed loop with a callback and parameter.

PROPERTIES

  • poll_period

    Get or set the poll period in seconds. Defaults to 1 second. Sleep period is calculated based on when the run starts and when the next period would be. If the callback takes longer than a poll period then it does not sleep but recalculates the next wake time and runs the callback again.

METHODS

  • run

    Run the loop. Initialise as a new daemon process if this is the first call and we are not running in the foreground.

  • stop

    Signal the loop to terminate. Would normally be called from within callback routine or interrupt handler to allow clean unwrap from original caller.

COMPATIBILITY

  • Proc::Simple::Daemon requires Class::Accessorize, Proc::PID::File, File::Basename and Sys::Syslog.

AUTHOR

Bernard Quatermass toolsmith@quatermass.co.uk

COPYRIGHT AND LICENSE

This software is copyright (c) 2017 by Bernard Quatermass.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.