From 321c182b8558bb32d95ff7a58a30eb8b93f1665b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Ma=C5=82ecki?= Date: Fri, 11 Nov 2011 23:26:00 +0100 Subject: [PATCH] [refactor] Replace `daemon.node` with `child_process.fork` It isn't perfect yet, but it works in `node v0.6`. --- lib/forever.js | 32 +++++++++----------------------- 1 file changed, 9 insertions(+), 23 deletions(-) diff --git a/lib/forever.js b/lib/forever.js index 74017a75..ecff1a2c 100644 --- a/lib/forever.js +++ b/lib/forever.js @@ -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'), @@ -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; + } }; //