Skip to content

Commit

Permalink
[api] Expose Monitor.killTree for killing process trees for process…
Browse files Browse the repository at this point in the history
…es spawned by forever
  • Loading branch information
indexzero committed Oct 9, 2011
1 parent a83a1e1 commit 4e27e3d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
22 changes: 15 additions & 7 deletions lib/forever/monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ var Monitor = exports.Monitor = function (script, options) {
options = options || {};
this.silent = options.silent || false;
this.forever = options.forever || false;
this.killTree = options.killTree !== false;
this.uid = options.uid || forever.randomString(24);
this.pidFile = options.pidFile || path.join(forever.config.get('pidPath'), this.uid + '.pid');
this.max = options.max;
Expand Down Expand Up @@ -373,13 +374,20 @@ Monitor.prototype.kill = function (forceStop) {
if (forceStop) {
this.forceStop = true;
}
psTree(this.child.pid, function (err, children) {
var pids = children.map(function (p) { return p.PID })
pids.shift(self.child.pid)
spawn('kill', ['-9'].concat(pids)).on('exit', function () {
self.emit('stop', self.childData);
})
})

if (this.killTree) {
psTree(this.child.pid, function (err, children) {
var pids = children.map(function (p) { return p.PID })
pids.shift(self.child.pid)
spawn('kill', ['-9'].concat(pids)).on('exit', function () {
self.emit('stop', self.childData);
})
});
}
else {
this.child.kill();
this.emit('stop', this.childData);
}

}

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@
"dnode": "0.8.x",
"eyes": "0.1.x",
"daemon": "0.3.x",
"minimatch": "0.0.x",
"mkdirp": "0.x.x",
"nconf": "0.x.x",
"optimist": "0.2.x",
"pkginfo": "0.x.x",
"portfinder": "0.x.x",
"ps-tree": "0.0.x",
"timespan": "2.0.x",
"watch": "0.3.x",
"minimatch": "0.0.x",
"ps-tree": "0.0.x",
"winston": "0.5.x"
},
"devDependencies": {
Expand Down

0 comments on commit 4e27e3d

Please sign in to comment.