Skip to content

Commit

Permalink
[refactor api] Start using native fork
Browse files Browse the repository at this point in the history
Get rid of `node-fork`.

So far this only works on `node v0.7.x` due to usage of `silent` option
in `child_process.fork` options.

This also adds a `fork-shim`, which allows us to spawn arbitrary
commands using `child_process.fork`.
  • Loading branch information
mmalecki authored and AvianFlu committed Jun 26, 2012
1 parent d000278 commit 16d1419
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
5 changes: 5 additions & 0 deletions bin/fork-shim
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env node
var spawn = require('child_process').spawn;
spawn(process.argv[2], process.argv.slice(3), {
customFds: [0, 1, 2]
});
22 changes: 7 additions & 15 deletions lib/forever/monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
var events = require('events'),
fs = require('fs'),
path = require('path'),
nodeFork = require('node-fork'),
fork = nodeFork.fork,
spawn = require('child_process').spawn,
child_process = require('child_process'),
fork = child_process.fork,
spawn = child_process.spawn,
broadway = require('broadway'),
psTree = require('ps-tree'),
winston = require('winston'),
Expand Down Expand Up @@ -75,7 +75,6 @@ var Monitor = exports.Monitor = function (script, options) {
this.spawnWith = options.spawnWith || {};
this.sourceDir = options.sourceDir;
this.fork = options.fork || false;
this.forkShim = options.forkShim || false;
this.cwd = options.cwd || null;
this.hideEnv = options.hideEnv || [];
this._env = options.env || {};
Expand Down Expand Up @@ -216,17 +215,10 @@ Monitor.prototype.trySpawn = function () {

if (this.fork) {
this.spawnWith.silent = true;
this.spawnWith.command = this.command;

if (this.forkShim) {
if (typeof this.forkShim === 'string') {
this.spawnWith.forkModule = this.forkShim;
}
this.spawnWith.env['FORK_SHIM'] = true;
return nodeFork.shim.fork(this.args[0], this.args.slice(1), this.spawnWith);
}

return fork(this.args[0], this.args.slice(1), this.spawnWith);
return fork(
path.join(__dirname, '..', '..', 'bin', 'fork-shim'),
[this.command].concat(this.args), this.spawnWith
);
}

return spawn(this.command, this.args, this.spawnWith);
Expand Down

0 comments on commit 16d1419

Please sign in to comment.