|
Proc::Daemontools - Perl interface for the functionalities of Daemontools |
Proc::Daemontools - Perl interface for the functionalities of Daemontools
use Proc::Daemontools;
my $svc = new Proc::Daemontools; # default directories assumed
or
my $svc = new Proc::Daemontools (
DAEMONTOOLS_DIR => "/some-non-default-dir",
SERVICE_DIR => "/some-non-default-dir",
DAEMON => "daemon-name" # optional: a default daemon
);
if ( $svc->is_up() ) {
print $svc->daemon(), " IS UP!\n";
}
my $daemon="qmail-send";
# We want to stop $daemon instead of the default daemon
if ( $svc->is_up($daemon) ) {
if ( $svc->down($daemon) ) {
print "OK, $daemon stopped. \n";
} else {
print "Ops, $daemon didnīt stop yet. Maybe it is waiting" .
" for some child to exit. Perhaps you want to kill" .
" that child by yourself... \n";
}
}
# Now we want it to start
if ( $svc->up($daemon) ) {
print "OK, $daemon started. \n".
}
# Letīs set the default daemon to be qmail-smtpd
$svc->daemon("qmail-smtpd");
# Letīs see what svstat says about it:
print "The current status of " . $svc->daemon() . " " .
"reported by svstat is: " . $svc->status() . "\n";
This module is a Perl interface for Daemontools package. Daemontools was written by Dan Bernstein and is intended to control Unix/Linux daemons.
Proc::Daemontools requires that the Daemontools package be installed on your machine in order to function. It wonīt even instantiate its object if it canīt find the Daemontools executables.
It assumes 2 default directories:
/usr/local/bin
the directory containing svc, svstat, supervise, etc
/service
the directory monitored by supervise to start/stop
the daemons
If youīre not using these default directories you can specify them explicilty
within the new() function.
The main goal of Proc::Daemontools is to start/stop the daemons managed by Daemontools, what is done internally with the ``svc'' command using the options ``-u'' and ``-d''.
The other functionalities provided by Daemontools can be implemented later if people require it.
new()Instantiate a Proc::Daemontools object. Without arguments it assumes its default values for the important directories. Also no default daemon is set.
Returns: object: A Proc::Daemontools object.
Atributes:
SERVICE_DIR : path to service dir
DAEMONTOOLS_DIR : path to executables dir
DAEMON : a the default daemon
To set your directories:
my $svc = new Proc::Daemontools (
SERVICE_DIR => "/my_path",
DAEMONTOOLS_DIR => "/my_path/bin"
);
To clone an existing object:
my $svc2 = $svc->new(); # $svc2 has the same atributes of $svc
To set a default daemon:
my $send = $svc2->new( DAEMON => "qmail-send" );
daemon()Set/get the default daemon.
Returns: string: containing the default daemon or undef if none was set.
up()Starts the default daemon. It not only issues a ``svc -u'' on the daemon, but it also checks with svstat to see if the daemon really was brought up. So you donīt want to check it again by yourself, ok?
If you pass it a daemon name as an argument it will start the passed daemon instead of the default one.
Returns: boolean: 1 if the daemon is up, 0 otherwise.
down()Works just like up() but issues a ``svc -d'' to stop the daemon.
Returns: boolean: 1 if the daemon is down, 0 otherwise.
status()Prints the output of svstat for the default daemon. It also accepts the name of a daemon as an argument.
Returns: string: the same output of svstat
is_up()Returns if the default daemon is up. It also accepts the name of a daemon as an argument.
Returns: boolean: 1 if the daemon is up, 0 otherwise.
Daemontools web site: http://cr.yp.to/daemontools.html
Bruno Negrao, bnegrao@engepel.com.br
Copyright 2003 by Bruno Negrao
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
|
Proc::Daemontools - Perl interface for the functionalities of Daemontools |