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 ILogger)

If the delegate returns false, daemon terminates.

template Daemon (
string name
alias pSignalMap
alias pMainFunc
) {}

Members

Aliases

mainFunc
alias mainFunc = pMainFunc
Undocumented in source.
signalMap
alias signalMap = pSignalMap
Undocumented in source.

Manifest constants

daemonName
enum daemonName;
Undocumented in source.

Examples

alias daemon = Daemon!(
    "DaemonizeExample1",

    KeyValueList!(
        Signal.Terminate, (logger)
        {
            logger.logInfo("Exiting...");
            return false; // returning false will terminate daemon
        },
        Signal.HangUp, (logger)
        {
            logger.logInfo("Hello World!");
            return true; // continue execution
        }
    ),

    (logger, shouldExit) 
    {
        // will stop the daemon in 5 minutes
        auto time = Clock.currSystemTick + cast(TickDuration)5.dur!"minutes";
        bool timeout = false;
        while(!shouldExit() && time > Clock.currSystemTick) {  }

        logger.logInfo("Exiting main function!");

        return 0;
    }
);

Meta