Beekeeper
view release on metacpan or search on metacpan
lib/Beekeeper/WorkerPool/Daemon.pm view on Meta::CPAN
sub main {
my $self = shift;
print "\nStarted...\n";
my $quit = 0;
$SIG{'TERM'} = sub { $quit = 1 }; # SIGTERM terminate request
$SIG{'INT'} = sub { $quit = 1 }; # SIGINT interrupt request, Ctrl-C
while (!$quit) {
# Do something here...
sleep 1;
}
print "Stopped\n";
}
1;
__END__
=pod
=encoding utf8
=head1 NAME
Beekeeper::WorkerPool::Daemon - Daemonize processes
=head1 VERSION
Version 0.09
=head1 SYNOPSIS
package MyDaemon;
use base 'Beekeeper::WorkerPool::Daemon';
sub main {
my $self = shift;
my $quit = 0;
$SIG{'TERM'} = sub { $quit = 1 };
$SIG{'INT'} = sub { $quit = 1 };
while (!$quit) {
# Do something here...
sleep 1;
}
}
Then, the daemon can be executed with a script like this:
#!/usr/bin/perl -wT
use strict;
use warnings;
use MyDaemon;
$ENV{PATH} = '/bin'; # untaint
my $daemon = MyDaemon->new->run;
=head1 DESCRIPTION
This is a base module for creating daemons. It takes care of daemonization tasks
commonly found in init.d scripts: forking, redirecting output, writing pid files,
start/stop/restart control commands, etc.
It is used by the command line tool C<bkpr> to daemonize itself.
=head1 AUTHOR
José Micó, C<jose.mico@gmail.com>
=head1 COPYRIGHT AND LICENSE
Copyright 2015-2023 José Micó.
This is free software; you can redistribute it and/or modify it under the same
terms as the Perl 5 programming language itself.
This software is distributed in the hope that it will be useful, but it is
provided âas isâ and without any express or implied warranties. For details,
see the full text of the license in the file LICENSE.
=cut
( run in 1.263 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )