WvStreams
|
WvDaemon - High-level abstraction for creating daemon processes. More...
#include <wvdaemon.h>
Public Member Functions | |
WvDaemon (WvStringParm _name, WvStringParm _version, WvDaemonCallback _start_callback, WvDaemonCallback _run_callback, WvDaemonCallback _stop_callback) | |
Construct a new daemon; requires the name, version, and optional userdata to be passed to the callbacks. | |
int | run (const char *argv0) |
Run the daemon with no argument processing. Returns exit status. | |
int | run (int argc, char **argv) |
Run the daemon after doing argument processing. Returns exit status. | |
void | restart () |
Force the daemon to restart as soon as the run callback exits. | |
void | die (int status=0) |
Force the daemon to exit as soon as the run callback exits. | |
bool | want_to_restart () const |
Whether the daemon will restart when the run callback exits. | |
bool | want_to_die () const |
Whether the daemon will quit when the run callback exits. | |
bool | should_run () const |
Whether the daemon should continue runnning. | |
const WvStringList & | extra_args () const |
Remaining args. | |
const char * | wstype () const |
Static Public Member Functions | |
static WvDaemon * | me () |
Public Attributes | |
WvString | name |
The name and version of the daemon; used for -V and logging. | |
WvString | version |
WvString | pid_file |
The path to the pid file to use for the daemon; defaults to /var/run/name.pid, where name is above. | |
bool | daemonize |
Whether the daemon should daemonize by default (it can be changed by the default options); defaults to false. | |
WvArgs | args |
The arguments the daemon accepts; the defaults are described above. | |
WvLog | log |
The daemon's log mechanism. | |
WvLog::LogLevel | log_level |
bool | syslog |
WvDaemonCallback | load_callback |
See the class description. | |
WvDaemonCallback | start_callback |
WvDaemonCallback | run_callback |
WvDaemonCallback | stop_callback |
WvDaemonCallback | unload_callback |
Protected Attributes | |
WvStringList | _extra_args |
WvDaemon - High-level abstraction for creating daemon processes.
WvDaemon makes it easy to create daemon processes that support forking into the background and detaching from terminals, management of the .pid file and the log file, and handling of the SIGTERM|SIGINT|SIGQUIT and SIGHUP signals.
By default, daemons implemented through WvDaemon provide the following command line options:
-q|–quiet: decrease the log level by one -v|–verbose: increase the log level by one -d|–daemonize: fork into the background (implies –syslog) -s|–syslog: write log entries to the syslog() facility –no-syslog: do not write log entries to the syslog() facility -V|–version: print the program name and version number and exit immediately
These default arguments can be changed or appended to through the public member WvDaemon::args of type WvArgs.
By default, daemons run in the foreground for debugging purposes; you must pass the -d parameter to force them into the background.
The actual functionality of WvDaemon is implemented through five protected member callbacks:
WvDaemon::load_callback: Called as soon as the arguments are processed and the process has (optionally) daemonized WvDaemon::start_callback: Called after WvDaemon::load_callback and after restarting due to SIGHUP WvDaemon::run_callback: The main loop callback.
Sample usage:
!
Definition at line 85 of file wvdaemon.h.