NAME

daemon.pm - simple daemon controlling object


SYNOPSIS

my $daemon = new daemon;

$daemon-datach;>

open LOGFILE, ">daemon.log";

while (sleep 5) { print LOGFILE "Hallo, ich arbeite\n"; };


COPYRIGHT

daemon.pm is Copyright (C) 2001-2002 Baltasar Cevc and Walter Werther.


DESCRIPTION

Using this object, you can create a simple daemon. The module provides a straight-forward interface to start, detach and stop the daemon.


Method overview

new([daemon-name] Create a new daemon-controller object
Creates a new object to controll a daemon, using the given name. If no name is given, the name of the program that calls this function is used.

inthandler_quit(<signame>) Handler for the quit signal (will exit daemon)
This is a handler for a quit signal, which will call all methods needed for a clean exit, afterwards, it will quit the daemon.

loglevel([level]) Set or get the maximum log level
Get/Set the log level (higher level means more output). You can define the maximum at will.

logto([destination]) Set/get the current log destination
If you specify an argument, the log destination will be changed, otherwise it will return the current destination. Possible destinations are ``//syslog'' (log to syslog), ``//debug'' (log to STDERR), ``//file'' (log goes to a file) - to set the log to a file, you just have to call logto (<filename>);. This function will also open the log destination.

dolog(<text>[, <level>]) Do logging
This function will log the specified text; if a level is given, the text will only be logged if the level is smaller or equal to the maximum log level.

logclose() Close log destination(s)
Closes all opened log destinations. This method is called automatically by the stop or DESTROY methods. You should not use this unless you really know what you are doing.

pidfile([pidfilename]) Get / Set PID file name
This function can be used to set the PID file path. If it is called without arguments, it will return the name of the PID file. This method MUST NOT BE USED after having used detach or debug.

detach
Detach the daemon from the tty. If the logging destination is ``//debug'', ``//syslog'' will be used instead.

wait_seconds(int value)
Sleeps for a specified number of seconds (give a fractional value if you want to sleep less than a second). This function uses the select call.


BUGS

kill function and check_running will not work for programs that use the detach or debug functions more than once, because they relay on the PID file which will be overwritten be further detaches or debugs.


CHANGES