From Code to Community: Sponsoring The Perl and Raku Conference 2025 Learn more

NAME

System::Daemon

DESCRIPTION

Swiss-knife for daemonization

SYNOPSIS

See little example:

$0 = 'my_daemon_process_name';
my $daemon = System::Daemon->new(
user => 'username',
group => 'groupname',
pidfile => 'path/to/pidfile',
daemonize => 0,
);
$daemon->daemonize();
your_cool_code();
$daemon->exit(0);

METHODS

new(%params)

Constructor, returns System::Daemon object. Available parameters:

user => desired_username,
group => desired_groupname,
pidfile => '/path/to/pidfile',
procname => process name for ps output,
mkdir => tries to create directory for pid files,
daemonize => if not true, will not daemonize, for debug reasons,
procname => after daemonize $0 will be updated to desired name,
new => Write pid to newpidfile=pidfile.".new", if newpidfile
dissapears or changed during daemon life, switch back to pidfile
Note that even without this option, if pidfile.".new" found during destruction
pidfile.".new" moved to pidfile location. These tools are for grace restart.
daemonize

Call it to become a daemon.

exit($exit_code)

An exit wrapper, also, it performing cleanup before exit.

finish

Performing cleanup. At now cleanup is just pid file removing.

cleanup

Same as finish.

process_object

Returns System::Process object of daemon instance.