Skip to content

Commit

Permalink
[refactor] Replace daemon.node with child_process.fork
Browse files Browse the repository at this point in the history
It isn't perfect yet, but it works in `node v0.6`.
  • Loading branch information
mmalecki authored and indexzero committed Dec 2, 2011
1 parent 0812449 commit c18993c
Showing 1 changed file with 9 additions and 23 deletions.
32 changes: 9 additions & 23 deletions lib/forever.js
Expand Up @@ -10,9 +10,9 @@ var fs = require('fs'),
path = require('path'),
events = require('events'),
exec = require('child_process').exec,
fork = require('child_process').fork,
net = require('net'),
cliff = require('cliff'),
daemon = require('daemon'),
nconf = require('nconf'),
portfinder = require('portfinder'),
timespan = require('timespan'),
Expand Down Expand Up @@ -341,29 +341,15 @@ forever.startDaemon = function (script, options) {
options.logFile = forever.logFilePath(options.logFile || options.uid + '.log');
options.pidFile = forever.pidFilePath(options.pidFile || options.uid + '.pid');

var monitor = new forever.Monitor(script, options);

fs.open(options.logFile, options.appendLog ? 'a+' : 'w+', function (err, fd) {
if (err) {
return monitor.emit('error', err);
}

var pid = daemon.start(fd);
daemon.lock(options.pidFile);

//
// Remark: This should work, but the fd gets screwed up
// with the daemon process.
//
// process.on('exit', function () {
// fs.unlinkSync(options.pidFile);
// });

process.pid = pid;
if (!process.send) {
fork(process.argv[1], ['start', script], {env: process.env});
process.exit(0);
}
else {
var monitor = new forever.Monitor(script, options);
monitor.start();
});

return monitor;
return monitor;
}
};

//
Expand Down

0 comments on commit c18993c

Please sign in to comment.