// First you need to describe your daemon via template alias daemon = Daemon!( "DaemonizeExample1", // unique name // Setting associative map signal -> callbacks KeyValueList!( Composition!(Signal.Terminate, Signal.Quit, Signal.Shutdown, Signal.Stop), (logger, signal) { logger.logInfo("Exiting..."); return false; // returning false will terminate daemon }, Signal.HangUp, (logger) { logger.logInfo("Hello World!"); return true; // continue execution } ), // Main function where your code is (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; } ); //... buildDaemon!daemon.run(new shared StrictLogger(logFilePath));
uninstall
Starts daemon that is described by DaemonInfo. Daemon is implemented as windows service and auto-installed in SC manager. If you want to uninstall the service, you can use uninstall function or system call:
If the service is already installed and is stopped, the function tries to start daemon. Otherwise it fails and returns EXIT_FAILURE code.
logger is a initialized logger for the daemon, you should use absolute names for Windows for logger files.
pidFilePath, lockFilePath, userId and groupId are ignored for Windows platform.