Skip to content

Commit

Permalink
feat: add support for customisable signal
Browse files Browse the repository at this point in the history
  • Loading branch information
stelcheck authored and remy committed Oct 6, 2016
1 parent af66ae6 commit 2cd85b1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
6 changes: 5 additions & 1 deletion lib/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var config = {
dirs: [],
timeout: 1000,
options: {},
signal: 'SIGUSR2',
};

/**
Expand Down Expand Up @@ -58,6 +59,9 @@ config.load = function (settings, ready) {
}

config.watchInterval = options.watchInterval || null;
if (options['signal']) { // jshint ignore:line
config.signal = options.signal;
}

var cmd = command(config.options);
config.command = {
Expand All @@ -83,4 +87,4 @@ config.load = function (settings, ready) {

config.reset = reset;

module.exports = config;
module.exports = config;
14 changes: 7 additions & 7 deletions lib/monitor/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,20 +130,20 @@ function run(options) {
// In case we killed the app ourselves, set the signal thusly
if (killedAfterChange) {
killedAfterChange = false;
signal = 'SIGUSR2';
signal = config.signal;
}
// this is nasty, but it gives it windows support
if (utils.isWindows && signal === 'SIGTERM') {
signal = 'SIGUSR2';
signal = config.signal;
}

if (signal === 'SIGUSR2' || code === 0) {
if (signal === config.signal || code === 0) {
// this was a clean exit, so emit exit, rather than crash
debug('bus.emit(exit) via SIGUSR2');
debug('bus.emit(exit) via ' + config.signal);
bus.emit('exit');

// exit the monitor, but do it gracefully
if (signal === 'SIGUSR2') {
if (signal === config.signal) {
return restart();
} else if (code === 0) { // clean exit - wait until file change to restart
if (runCmd) {
Expand Down Expand Up @@ -201,7 +201,7 @@ function run(options) {
/* Now kill the entire subtree of processes belonging to nodemon */
var oldPid = child.pid;
if (child) {
kill(child, 'SIGUSR2', function () {
kill(child, config.signal, function () {
// this seems to fix the 0.11.x issue with the "rs" restart command,
// though I'm unsure why. it seems like more data is streamed in to
// stdin after we close.
Expand Down Expand Up @@ -267,7 +267,7 @@ function kill(child, signal, callback) {
// spawning processes like `coffee` under the `--debug` flag, it'll spawn
// it's own child, and that can't be killed by nodemon, so psTree gives us
// an array of PIDs that have spawned under nodemon, and we send each the
// SIGUSR2 signal, which fixes #335
// configured signal (defaul: SIGUSR2) signal, which fixes #335
psTree(child.pid, function (err, kids) {
spawn('kill', ['-s', signal, child.pid].concat(kids.map(function (p) {
return p.PID;
Expand Down

0 comments on commit 2cd85b1

Please sign in to comment.