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 committed Dec 1, 2011
1 parent 24176b1 commit 31fcd47
Showing 1 changed file with 9 additions and 23 deletions.
32 changes: 9 additions & 23 deletions lib/forever.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ var fs = require('fs'),
path = require('path'),
events = require('events'),
exec = require('child_process').exec,
fork = require('child_process').fork,
net = require('net'),
async = require('async'),
colors = require('colors'),
cliff = require('cliff'),
daemon = require('daemon'),
nconf = require('nconf'),
mkdirp = require('mkdirp').mkdirp,
portfinder = require('portfinder'),
Expand Down Expand Up @@ -326,29 +326,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

3 comments on commit 31fcd47

@coolsp
Copy link

@coolsp coolsp commented on 31fcd47 Dec 8, 2011

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

daemon.node was not working on OpenBSD 5.0 (undefined symbol 'ev_default_loop_ptr').
So, this rewrite is perfect, no longer getting the undefined symbol runtime-error (limited testing so far).
Hope it makes it to the official version so I can use npm to install.

@mmalecki
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course it will! :)

We're doing quite a different thing now which should make forever more stable (see rewrite branch). Stay tuned!

@coolsp
Copy link

@coolsp coolsp commented on 31fcd47 Dec 8, 2011

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the tip.
I fetched the rewrite branch, applied this fix + the cli.js fix (to get it working on OpenBSD 5.0 / node v0.6.5).
The thing I can't seem to get working are the log-files don't see any being created (-l forever.log -o out.log -e err.log).

Please sign in to comment.