From 16d141983897be382d2a6c5022ed1e3dddffb8ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Ma=C5=82ecki?= Date: Sat, 5 May 2012 02:46:01 +0200 Subject: [PATCH] [refactor api] Start using native fork 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`. --- bin/fork-shim | 5 +++++ lib/forever/monitor.js | 22 +++++++--------------- 2 files changed, 12 insertions(+), 15 deletions(-) create mode 100644 bin/fork-shim diff --git a/bin/fork-shim b/bin/fork-shim new file mode 100644 index 00000000..3ca31b8b --- /dev/null +++ b/bin/fork-shim @@ -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] +}); diff --git a/lib/forever/monitor.js b/lib/forever/monitor.js index 7707cfac..6c021fee 100644 --- a/lib/forever/monitor.js +++ b/lib/forever/monitor.js @@ -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'), @@ -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 || {}; @@ -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);