X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=senf%2FUtils%2FDaemon%2FDaemon.hh;h=9c824fe06aa2d4be3f968a2dfffbcfd61103dac5;hb=4101c2b818ec67e7469ebb44f030eed2185c4ab0;hp=f0d3e6b50c8fc86b0ce2da51210fc54d0c3015c0;hpb=601d1f509f5bb24df167a4dd5a20da67a0af9af8;p=senf.git diff --git a/senf/Utils/Daemon/Daemon.hh b/senf/Utils/Daemon/Daemon.hh index f0d3e6b..9c824fe 100644 --- a/senf/Utils/Daemon/Daemon.hh +++ b/senf/Utils/Daemon/Daemon.hh @@ -28,23 +28,24 @@ // Custom includes #include -#include "../Logger/SenfLog.hh" +#include //#include "Daemon.mpp" -///////////////////////////////hh.p//////////////////////////////////////// +//-///////////////////////////////////////////////////////////////////////////////////////////////// namespace senf { /** \brief %Daemon process - The %Daemon class provides simple management for daemon processes. Specifically, it implements + The %Daemon class provides simple management for daemon processes. Specifically, it + implements \li Safe startup. If the startup fails, the foreground process which launches the daemon will terminate with an appropriate error exit code. \li Straight forward application initialization. The daemon process is forked before - even initializing the application. The initialization procedure must not cater for a - later fork(). - \li Automatic pid file management. The daemon will not be started, if a valid pid file is - found. Stale pid files are automatically removed. + even initializing the application. The initialization procedure doesn't need to cater + for a later fork(). + \li Automatic pid file management. The daemon will not be started, if a valid pid + file is found. Stale pid files are automatically removed. \li Console log management. It is possible, to redirect standard output and error to one or two log files. Messages pertaining to application initialization will be written to both the console and the log file whereas later messages will be directed to the log @@ -52,7 +53,7 @@ namespace senf { \li Optional foreground execution. The daemon may be started in the foreground for debugging purposes. In this case, the console log file(s) is/are automatically suppressed. - + Starting the daemon process proceeds along the following steps: \li The daemon is started by calling the daemon class instances start() member. This normally happens from the \c main() function generated by \ref SENF_DAEMON_MAIN(). @@ -62,7 +63,7 @@ namespace senf { created. The parent (foreground) process keeps running overseeing the daemon process. \li main() is called. This virtual member may optionally be overridden in the derived class. Here we assume, main() is not overridden so the default implementation is used. - \li main() calls init(). + \li main() calls init(). \li after init() returns, main() calls detach(). \li detach() signals successful startup to the parent process. The parent process terminates leaving the daemon process running in the background. @@ -98,42 +99,42 @@ namespace senf { arguments. It just checks, if any of above arguments are present and precesses them. Other arguments are completely ignored. The command line parameters should be completely processed within init(). - + */ class Daemon : boost::noncopyable { public: SENF_LOG_CLASS_AREA(); - /////////////////////////////////////////////////////////////////////////// + //-///////////////////////////////////////////////////////////////////////// // Types - + /// Select standard stream to redirect - enum StdStream { + enum StdStream { StdOut /** Standard output stream */ , StdErr /** Standard error stream */ , Both /** Both, standard output and error stream */ - }; + }; - /////////////////////////////////////////////////////////////////////////// + //-///////////////////////////////////////////////////////////////////////// ///\name Structors and default members - ///\{ + //\{ virtual ~Daemon(); - ///\} + //\} ///\name Parameters - ///\{ + //\{ void daemonize(bool); ///< Configure whether to run in fore- or background bool daemon(); ///< \c true, if running as daemon - void consoleLog(std::string const &, StdStream which = Both); + void consoleLog(std::string const &, StdStream which = Both); ///< Configure console log file /**< May be called multiple times to set the log file for stdout and stderr seperately. Any standard stream not assigned to a log file will be redirected to - /dev/null. + /dev/null. When running in the foreground, the log files will be ignored. */ @@ -143,9 +144,9 @@ namespace senf { daemon startup. If another running instance of the daemon is detected, starting the daemon will fail. */ - ///\} + //\} ///\name Auxiliary helpers - ///\{ + //\{ void detach(); ///< Detach into background now /**< This is \e not the same as forking. The process will @@ -165,8 +166,8 @@ namespace senf { /**< This is used when rotating the logs. By default, SIGHUP calls logReopen. */ - ///\} - + //\} + int start(int argc, char const ** argv); ///< Called from main() to launch daemon. /**< Normally not called directly but from the \ref SENF_DAEMON_MAIN macro. */ @@ -241,7 +242,7 @@ namespace senf { } -///////////////////////////////hh.e//////////////////////////////////////// +//-///////////////////////////////////////////////////////////////////////////////////////////////// #include "Daemon.cci" //#include "Daemon.ct" //#include "Daemon.cti"