Daemon

Template for describing daemon in the package. * To describe new daemon you should set unique name and signal -> callbacks mapping. * name is used to name default pid and lock files of the daemon and also it is a service name in Windows. * pSignalMap is a KeyValueList template where keys are Signal values and values are delegates of type:

bool delegate(shared IDaemonLogger)

If the delegate returns false, daemon terminates. *

template Daemon (
string name
alias pSignalMap
alias pMainFunc
) {
enum daemonName;
}

Examples

1    alias daemon = Daemon!(
2        "DaemonizeExample1",
3 
4        KeyValueList!(
5            Signal.Terminate, (logger)
6            {
7                logger.logInfo("Exiting...");
8                return false; // returning false will terminate daemon
9            },
10            Signal.HangUp, (logger)
11            {
12                logger.logInfo("Hello World!");
13                return true; // continue execution
14            }
15        ),
16 *
17        (logger, shouldExit) 
18        {
19            // will stop the daemon in 5 minutes
20            auto time = Clock.currSystemTick + cast(TickDuration)5.dur!"minutes";
21            bool timeout = false;
22            while(!shouldExit() && time > Clock.currSystemTick) {  }
23        
24            logger.logInfo("Exiting main function!");
25        
26            return 0;
27        }
28    );

Meta