pgator

Boilerplate code to start linux  daemon. Other platforms will fallback to terminal mode.

See Also
terminal
License
Subject to the terms of the MIT license, as written in the included LICENSE file.
Authors
NCrashed

int  runDaemon(shared ILogger logger, int delegate(string[]) progMain, string[] args, void delegate() listener, void delegate() termListener, void delegate() rotateListener, string pidfile, string lockfile, int groupid = -1, int userid = -1);

Forks daemon process with progMain main function and passes args to it. If daemon catches SIGHUP signal, listener delegate is called. If daemon catches SIGQUIT, SIGABRT, or any other terminating sygnal, the termListener is called.

If application receives "real-time" signal SIGROTATE defined as SIGRTMIN+10, then rotateListener is called to handle 'logrotate' utility.

Daemon writes log message into provided logger and will close it while exiting.

File pidfile is used to write down PID of detached daemon. This file is usefull for interfacing with external tools thus it is only way to know daemon PID (for this moment). This file is removed while exiting.

File lockfile is used to track multiple daemon instances. If this file is exists, the another daemon is running and pgator should exit immediately.

groupid and userid are used to low privileges with run as root.