Daemonize v0.1 - simple way to create cross-platform daemons

NCrashed via Digitalmars-d-announce digitalmars-d-announce at puremagic.com
Sun Aug 31 04:27:41 PDT 2014


Finally I've finished library for wrapping applications into 
daemons or services (Windows). The library hides 
platform-specific boilerplate behind compile-time API:
```
// First you need to describe your daemon via template
alias daemon = Daemon!(
     "DaemonizeExample1", // unique name

     // Setting associative map signal -> callbacks
     KeyValueList!(
         // You can bind same delegate for several signals by 
Composition template
         // delegate can take additional argument to know which 
signal is caught
         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";
         while(!shouldExit() && time > Clock.currSystemTick) {  }

         return 0;
     }
);

int main()
{
     return buildDaemon!daemon.run(new shared 
StrictLogger("logfile.log"));
}
```

At the moment daemonize has following features:
* Daemons for GNU/Linux, services for Windows
* Custom signals
* Signal composition
* Client for sending signals to defined daemons
* Auto installing and uninstalling for Windows services
* Usage of .pid and .lock files (GNU/Linux)
* Privileges lowing (GNU/Linux)

Daemonize operates well with vibe.d (example - 
https://github.com/NCrashed/daemonize/tree/master/examples/03.Vibed)

P.S. At the moment library doesn't support Mac and other Posix 
systems, the support is going to be added at next releases.


More information about the Digitalmars-d-announce mailing list