Skip to content

Commit

Permalink
fix: switch to killing using numericals
Browse files Browse the repository at this point in the history
Fixes #956
Fixes #813
  • Loading branch information
remy committed Dec 15, 2017
1 parent 770c90d commit e9129c0
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/monitor/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var noop = function () { };
var restart = null;
var psTree = require('@remy/pstree');
var path = require('path');
var signals = require('./signals');

function run(options) {
var cmd = config.command.raw;
Expand Down Expand Up @@ -290,9 +291,13 @@ function kill(child, signal, callback) {
// configured signal (default: SIGUSR2) signal, which fixes #335
// note that psTree also works if `ps` is missing by looking in /proc
psTree(child.pid, function (err, kids) {
spawn('kill', ['-s', signal, child.pid].concat(kids.map(function (p) {
return p.PID;
}))).on('close', callback);
// make sure we kill from smallest to largest
const pids = kids.map(p => p.PID).concat(child.pid).sort();

pids.forEach(pid => {
exec('kill -' + signals[signal] + ' ' + pid, () => {});
});
callback();
});
}
}
Expand Down
34 changes: 34 additions & 0 deletions lib/monitor/signals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
module.exports = {
"SIGHUP": "1",
"SIGINT": "2",
"SIGQUIT": "3",
"SIGILL": "4",
"SIGTRAP": "5",
"SIGABRT": "6",
"SIGBUS": "7",
"SIGFPE": "8",
"SIGKILL": "9",
"SIGUSR1": "10",
"SIGSEGV": "11",
"SIGUSR2": "12",
"SIGPIPE": "13",
"SIGALRM": "14",
"SIGTERM": "15",
"SIGSTKFLT": "16",
"SIGCHLD": "17",
"SIGCONT": "18",
"SIGSTOP": "19",
"SIGTSTP": "20",
"SIGTTIN": "21",
"SIGTTOU": "22",
"SIGURG": "23",
"SIGXCPU": "24",
"SIGXFSZ": "25",
"SIGVTALRM": "26",
"SIGPROF": "27",
"SIGWINCH": "28",
"SIGIO": "29",
"SIGPWR": "30",
"SIGSYS": "31",
"SIGRTMIN": "35"
}

0 comments on commit e9129c0

Please sign in to comment.