Skip to content

Commit

Permalink
[minor] Small updates to 0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
indexzero committed Feb 5, 2011
1 parent 9dc933e commit 78e53a2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -31,7 +31,7 @@ Starting a daemon is easy, just call daemon.start() and daemon.lock().
// Your awesome code here

fs.open('somefile.log', 'w+', function (err, fd) {
daemon.daemonize();
daemon.daemonize(fd);
daemon.lock('/tmp/yourprogram.pid');
});
</pre>
Expand All @@ -43,11 +43,11 @@ This library also exposes a higher level facility through javascript for startin

// Your awesome code here

daemon.daemonize('somefile.log', '/tmp/yourprogram.pid', function (err, started) {
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');
sys.puts('Daemon started successfully with pid: ' + pid);
});
</pre>

Expand Down
10 changes: 9 additions & 1 deletion lib/daemon.js
Expand Up @@ -16,11 +16,19 @@ var fs = require('fs'),
Object.keys(binding).forEach(function (k) { daemon[k] = binding[k] });

//
// function run (out, lock, callback)
// function daemonize ([out, lock, callback])
// Run is designed to encapsulate the basic daemon operation in a single async call.
// When the callback returns you are in the the child process.
//
daemon.daemonize = function (out, lock, callback) {
//
// If we only get one argument assume it's an fd and
// simply return with the pid from binding.daemonize(fd);
//
if (arguments.length === 1) {
return binding.daemonize(out);
}

fs.open(out, 'w+', function (err, fd) {
if (err) return callback(err);

Expand Down

0 comments on commit 78e53a2

Please sign in to comment.