A C++ add-on for Node.js to enable simple daemons in Javascript plus some useful wrappers in Javascript.
curl http://npmjs.org/install.sh | sh
[sudo] npm install daemon
node-waf configure build
There is a great getting started article on daemons and node.js by Slashed that you can read here. The API has changed slightly from that version thanks to contributions from ptge and fugue; there is no longer a daemon.closeIO() method, this is done automatically for you.
Starting a daemon is easy, just call daemon.start() and daemon.lock().
var daemon = require('daemon'); // Your awesome code here fs.open('somefile.log', 'w+', function (err, fd) { daemon.start(fd); daemon.lock('/tmp/yourprogram.pid'); });
This library also exposes a higher level facility through javascript for starting daemons:
var sys = require('sys'), daemon = require('daemon'); // Your awesome code here daemon.daemonize('somefile.log', '/tmp/yourprogram.pid', function (err, pid) { // We are now in the daemon process if (err) return sys.puts('Error starting daemon: ' + err); sys.puts('Daemon started successfully with pid: ' + pid); });
This library is available under the MIT LICENSE. See the LICENSE file for more details. It was created by Slashed and forked / improved / hacked upon by a lot of good people. Special thanks to Isaacs for npm and a great example in [glob][6].