NAME
Ubic::Daemon - toolkit for creating daemonized process
VERSION
version 1.13
SYNOPSIS
use Ubic::Daemon qw(start_daemon stop_daemon check_daemon);
start_daemon({bin => '/bin/sleep', pidfile => "/var/lib/something/pid"});
stop_daemon("/var/lib/something/pid");
check_daemon("/var/lib/something/pid");
DESCRIPTION
This module tries to safely start and daemonize any binary or any perl function.
Main source of knowledge if daemon is still running is pidfile, which is locked all the time after daemon was created.
Pidfile format is unreliable and can change in future releases. If you really need to get daemon's pid, save it from daemon or ask me for public pidfile-reading API in this module.
- stop_daemon($pidfile)
- stop_daemon($pidfile, $options)
-
Stop daemon which was started with
$pidfile
.It sends SIGTERM to process with pid specified in
$pidfile
until it will stop to exist (according tocheck_daemon()
method). If it fails to stop process after several seconds, exception will be raised.Options:
- timeout
-
Number of seconds to wait before raising exception that daemon can't be stopped.
Return value:
not running
if daemon is already not running;stopped
if daemon is stopped by SIGTERM. - start_daemon($params)
-
Start daemon. Params:
- bin
-
Binary which will be daemonized.
Can be string or arrayref with arguments. Arrayref-style values are recommended in complex cases, because otherwise
exec()
can invoke sh shell which will immediately exit on sigterm. - function
-
Function which will be daemonized. One and only one of function and bin must be specified.
Function daemonization is a dangerous feature and will probably be deprecated and removed in future.
- name
-
Name of guardian process. Guardian will be named "ubic-guardian $name".
If not specified, bin's value will be assumed, or
anonymous
when daemonizing perl code. - pidfile
-
Pidfile. It will be locked for a whole time of service's work. It will contain pid of daemon.
- stdout
-
Write all daemon's output to given file. If not specified, all output will be redirected to
/dev/null
. - stderr
-
Write all daemon's error output to given file. If not specified, all stderr will be redirected to
/dev/null
. - ubic_log
-
Filename of ubic log. It will contain some technical information about running daemon.
If not specified,
/dev/null
will be assumed. - term_timeout
-
Can contain integer number of seconds to wait between sending SIGTERM and SIGKILL to daemon.
Zero value means that guardian will send sigkill to daemon immediately.
Default is 10 seconds.
- check_daemon($pidfile)
-
Check whether daemon is running.
Returns true if it is so.
BUGS
Probably lots of them.
SEE ALSO
AUTHOR
Vyacheslav Matjukhin <mmcleric@yandex-team.ru>