buildDaemon.run

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:

C:\Windows\System32\sc.exe delete <daemonName>

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.

template buildDaemon(alias DaemonInfo, DWORD startType = SERVICE_DEMAND_START)
int
run
(
,
string pidFilePath = ""
,
string lockFilePath = ""
,
int userId = -1
,
int groupId = -1
)
if (
isDaemon!DaemonInfo ||
isDaemonClient!DaemonInfo
)

Examples

1 // First you need to describe your daemon via template
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 //...
33 buildDaemon!daemon.run(new shared DloggLogger(logFilePath));

See Also

uninstall

Meta