|
| 1 | +# daemon.node |
| 2 | + |
| 3 | +A C++ add-on for Node.js to enable simple daemons in Javascript plus some useful wrappers in Javascript. |
| 4 | + |
| 5 | +## Installation |
| 6 | + |
| 7 | +### Installing npm (node package manager) |
| 8 | +<pre> |
| 9 | + curl http://npmjs.org/install.sh | sh |
| 10 | +</pre> |
| 11 | + |
| 12 | +### Installing daemon.node with npm |
| 13 | +<pre> |
| 14 | + [sudo] npm install daemon |
| 15 | +</pre> |
| 16 | + |
| 17 | +### Installing daemon.node locally |
| 18 | +<pre> |
| 19 | + node-waf configure build |
| 20 | +</pre> |
| 21 | + |
| 22 | +## Usage |
| 23 | + |
| 24 | +There is a great getting started article on daemons and node.js by Slashed that you [can read here][0]. The API has changed slightly from that version thanks to contributions from ptge and [fugue][1]; there is no longer a daemon.closeIO() method, this is done automatically for you. |
| 25 | + |
| 26 | +### Starting a daemon: |
| 27 | +Starting a daemon is easy, just call daemon.start() and daemon.lock(). |
| 28 | +<pre> |
| 29 | + var daemon = require('daemon'); |
| 30 | + |
| 31 | + // Your awesome code here |
| 32 | + |
| 33 | + fs.open('somefile.log', 'w+', function (err, fd) { |
| 34 | + daemon.start(); |
| 35 | + daemon.lock('/tmp/yourprogram.pid'); |
| 36 | + }); |
| 37 | +</pre> |
| 38 | + |
| 39 | +This library also exposes a higher level facility through javascript for starting daemons: |
| 40 | +<pre> |
| 41 | + var sys = require('sys'), |
| 42 | + daemon = require('daemon'); |
| 43 | + |
| 44 | + // Your awesome code here |
| 45 | + |
| 46 | + daemon.run('somefile.log', '/tmp/yourprogram.pid', function (err, started) { |
| 47 | + // We are now in the daemon process |
| 48 | + if (err) return sys.puts('Error starting daemon: ' + err); |
| 49 | + |
| 50 | + sys.puts('Daemon started successfully'); |
| 51 | + }); |
| 52 | +</pre> |
| 53 | + |
| 54 | +### The Fine Print |
| 55 | +This library is available under the MIT LICENSE. See the LICENSE file for more details. It was created by [Slashed][2] and [forked][3] / [improved][4] / [hacked upon][1] by a lot of good people. Special thanks to [Isaacs][5] for npm and a great example in [glob][6]. |
| 56 | + |
| 57 | +#### Author: [Slashed](http://github.com/slashed) |
| 58 | +#### Contributors: [Charlie Robbins](http://nodejitsu.com), [Pedro Teixeira](https://github.com/pgte), [James Halliday](https://github.com/substack), [Zak Taylor](https://github.com/dobl) |
| 59 | + |
| 60 | +[0]: http://slashed.posterous.com/writing-daemons-in-javascript-with-nodejs-0 |
| 61 | +[1]: https://github.com/pgte/fugue/blob/master/deps/daemon.cc |
| 62 | +[2]: https://github.com/slashed/daemon.node |
| 63 | +[3]: https://github.com/substack/daemon.node/ |
| 64 | +[4]: https://github.com/dobl/daemon.node |
| 65 | +[5]: https://github.com/isaacs/npm |
| 66 | +[6]: |
0 commit comments