Ubic::Daemon - toolkit for creating daemonized process
version 1.10
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");
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 which was started with $pidfile.
$pidfile
It sends SIGTERM to process with pid specified in $pidfile until it will stop to exist (according to check_daemon() method). If it fails to stop process after several seconds, exception will be raised.
check_daemon()
Options:
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.
not running
stopped
Start daemon. Params:
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.
exec()
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 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.
anonymous
Pidfile. It will be locked for a whole time of service's work. It will contain pid of daemon.
Write all daemon's output to given file. If not specified, all output will be redirected to /dev/null.
/dev/null
Write all daemon's error output to given file. If not specified, all stderr will be redirected to /dev/null.
Filename of ubic log. It will contain some technical information about running daemon.
If not specified, /dev/null will be assumed.
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 whether daemon is running.
Returns true if it is so.
Probably lots of them.
Ubic::Service::SimpleDaemon
Vyacheslav Matjukhin <mmcleric@yandex-team.ru>
To install Ubic, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Ubic
CPAN shell
perl -MCPAN -e shell install Ubic
For more information on module installation, please visit the detailed CPAN module installation guide.