NAME
Daemon::Daemonize - An easy-to-use daemon(izing) toolkit
VERSION
version 0.0052
SYNOPSIS
use Daemon::Daemonize qw/ :all /
daemonize( %options, run => sub {
# Daemon code in here...
} )
# Do some non-daemon stuff here...
You can also use it in the traditional way, daemonizing the current
process:
daemonize( %options )
# Daemon code in here...
and use it to check up on your daemon:
# In your daemon
use Daemon::Daemonize qw/ :all /
write_pidfile( $pidfile )
$SIG{INT} = sub { delete_pidfile( $pidfile ) }
... Elsewhere ...
use Daemon::Daemonize qw/ :all /
# Return the pid from $pidfile if it contains a pid AND
# the process is running (even if you don't own it), 0 otherwise
my $pid = check_pidfile( $pidfile )
# Return the pid from $pidfile, or undef if the
# file doesn't exist, is unreadable, etc.
# This will return the pid regardless of if the process is running
my $pid = read_pidfile( $pidfile )
DESCRIPTION
Daemon::Daemonize is a toolkit for daemonizing processes and checking up
on them. It takes inspiration from
, MooseX::Daemon,
Net::Server::Daemon
A note about the "close" option
If you're having trouble with IPC in a daemon, try closing only STD*
instead of everything:
daemonize( ..., close => std, ... )
This is a workaround for a problem with using "Net::Server" and
"IPC::Open3" in a daemonized process
USAGE
You can use the following functions in two ways, by either importing
them:
use Daemon::Daemonize qw/ daemonize /
daemonize( ... )
or calling them as a class method:
use Daemon::Daemonize
Daemon::Daemonize->daemonize
daemonize( %options )
Daemonize the current process, according to %options:
chdir
Change to when daemonizing. Pass undef for *no* chdir.
Default is '/' (to prevent a umount conflict)
close