diff --git a/lib/monitor/run.js b/lib/monitor/run.js index ab890ec9..9815af49 100644 --- a/lib/monitor/run.js +++ b/lib/monitor/run.js @@ -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; @@ -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(); }); } } diff --git a/lib/monitor/signals.js b/lib/monitor/signals.js new file mode 100644 index 00000000..c54d2e02 --- /dev/null +++ b/lib/monitor/signals.js @@ -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" +}