Skip to content

Commit 4e27e3d

Browse files
committed
[api] Expose Monitor.killTree for killing process trees for processes spawned by forever
1 parent a83a1e1 commit 4e27e3d

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

lib/forever/monitor.js

+15-7
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ var Monitor = exports.Monitor = function (script, options) {
3333
options = options || {};
3434
this.silent = options.silent || false;
3535
this.forever = options.forever || false;
36+
this.killTree = options.killTree !== false;
3637
this.uid = options.uid || forever.randomString(24);
3738
this.pidFile = options.pidFile || path.join(forever.config.get('pidPath'), this.uid + '.pid');
3839
this.max = options.max;
@@ -373,13 +374,20 @@ Monitor.prototype.kill = function (forceStop) {
373374
if (forceStop) {
374375
this.forceStop = true;
375376
}
376-
psTree(this.child.pid, function (err, children) {
377-
var pids = children.map(function (p) { return p.PID })
378-
pids.shift(self.child.pid)
379-
spawn('kill', ['-9'].concat(pids)).on('exit', function () {
380-
self.emit('stop', self.childData);
381-
})
382-
})
377+
378+
if (this.killTree) {
379+
psTree(this.child.pid, function (err, children) {
380+
var pids = children.map(function (p) { return p.PID })
381+
pids.shift(self.child.pid)
382+
spawn('kill', ['-9'].concat(pids)).on('exit', function () {
383+
self.emit('stop', self.childData);
384+
})
385+
});
386+
}
387+
else {
388+
this.child.kill();
389+
this.emit('stop', this.childData);
390+
}
383391

384392
}
385393

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@
3232
"dnode": "0.8.x",
3333
"eyes": "0.1.x",
3434
"daemon": "0.3.x",
35+
"minimatch": "0.0.x",
3536
"mkdirp": "0.x.x",
3637
"nconf": "0.x.x",
3738
"optimist": "0.2.x",
3839
"pkginfo": "0.x.x",
3940
"portfinder": "0.x.x",
41+
"ps-tree": "0.0.x",
4042
"timespan": "2.0.x",
4143
"watch": "0.3.x",
42-
"minimatch": "0.0.x",
43-
"ps-tree": "0.0.x",
4444
"winston": "0.5.x"
4545
},
4646
"devDependencies": {

0 commit comments

Comments
 (0)