Saves info about exception into daemon logger
As custom signals are mapped to realtime signals at runtime, it is complicated to calculate signal number by hands. The function simplifies sending signals to daemons that were created by the package.
As custom signals are mapped to realtime signals at runtime, it is complicated to calculate signal number by hands. The function simplifies sending signals to daemons that were created by the package.
Actual signal handler
In GNU/Linux daemon doesn't require deinstallation.
1 * 2 alias daemon = Daemon!( 3 "DaemonizeExample1", // unique name 4 * 5 // Setting associative map signal -> callbacks 6 KeyValueList!( 7 Composition!(Signal.Terminate, Signal.Quit, Signal.Shutdown, Signal.Stop), (logger, signal) 8 { 9 logger.logInfo("Exiting..."); 10 return false; // returning false will terminate daemon 11 }, 12 Signal.HangUp, (logger) 13 { 14 logger.logInfo("Hello World!"); 15 return true; // continue execution 16 } 17 ), 18 * 19 // Main function where your code is 20 (logger, shouldExit) { 21 // will stop the daemon in 5 minutes 22 auto time = Clock.currSystemTick + cast(TickDuration)5.dur!"minutes"; 23 bool timeout = false; 24 while(!shouldExit() && time > Clock.currSystemTick) { } 25 * 26 logger.logInfo("Exiting main function!"); 27 * 28 return 0; 29 } 30 ); 31 * 32 return buildDaemon!daemon.run(logger);
Main template in the module that actually creates daemon process. DaemonInfo is a Daemon instance that holds name of the daemon and hooks for numerous Signals. * Daemon is detached from terminal, therefore it needs a preinitialized logger. * As soon as daemon is ready the function executes main delegate that returns application return code. * Daemon uses pid and lock files. Pid file holds process id for communications with other applications. If pidFilePath isn't set, the default path to pid file is '~/.daemonize/<daemonName>.pid'. Lock file prevents from execution of numerous copies of daemons. If lockFilePath isn't set, the default path to lock file is '~/.daemonize/<daemonName>.lock'. If you want several instances of one daemon, redefine pid and lock files paths. * Sometimes lock and pid files are located at /var/run directory and needs a root access. If userId and groupId parameters are set, daemon tries to create lock and pid files and drops root privileges. *