Browse files

[minor] Small updates to 0.2.0

  • Loading branch information...
1 parent 9dc933e commit 78e53a21f022e5948e8c393a74f8e37aa4d7251b @indexzero indexzero committed Feb 5, 2011
Showing with 12 additions and 4 deletions.
  1. +3 −3 README.md
  2. +9 −1 lib/daemon.js
View
6 README.md
@@ -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>
@@ -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>
View
10 lib/daemon.js
@@ -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);

0 comments on commit 78e53a2

Please sign in to comment.