Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Process exit signals on Windows #778

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 17 additions & 1 deletion lib/forever.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,18 @@ forever.cli = require('./forever/cli');
//
exports.version = require('../package').version;


//
// ### function exit ()
// Kills child process if available and exit
//
function exit() {
if (childProcess) {
childProcess.stop();
}
process.exit(0);
}

//
// ### function getSockets (sockPath, callback)
// #### @sockPath {string} Path in which to look for UNIX domain sockets
Expand Down Expand Up @@ -432,7 +444,7 @@ forever.start = function (script, options) {
//
// Create the monitor, log events, and start.
//
var monitor = new forever.Monitor(script, options);
var monitor = childProcess = new forever.Monitor(script, options);
forever.logEvents(monitor);
return monitor.start();
};
Expand Down Expand Up @@ -974,6 +986,7 @@ forever.logEvents = function (monitor) {
});

monitor.on('exit:code', function (code, signal) {
childProcess = null;
forever.out.error((code !== null && code !== undefined)
? 'Forever detected script exited with code: ' + code
: 'Forever detected script was killed by signal: ' + signal);
Expand Down Expand Up @@ -1041,3 +1054,6 @@ forever.columns = {
}
}
};

process.on('SIGTERM', exit);
process.on('SIGINT', exit);