-
Notifications
You must be signed in to change notification settings - Fork 939
Description
I found an issue that I believe is related to many others with similar and open issues. I think I also know how to solve it.
The Issue
So the issues is that Forever.stop(index | UID, false) kills the current or parent server/script. Instead of simply stopping the child process. Is there a killSignal that could also enable the main script to continue running.
Possibly Due To
killSignal not detecting signals correctly ar and the following line:
https://github.com/foreverjs/forever/blob/master/lib/forever.js#L519
Possible Fix
forever.config.get('exitOnStop')
https://github.com/foreverjs/forever/blob/master/lib/forever.js#L519
https://github.com/foreverjs/forever/blob/master/lib/forever/worker.js#L14
Example
Note: When you run the example you will notice that the parent process is killed. Instead of simply stopping the child process.
var Forever = require('forever');
var path = __dirname + '/test';
var file = 'app.js';
var options1 = {
max: 5,
uid: 'test1',
cwd: path,
silent: true,
killTree: true,
// killSignal: ' ', // Is there a killSignal that might fix this?
sourceDir: path,
env: { port: 8001 }
};
var options2 = {
max: 5,
uid: 'test2',
cwd: path,
silent: true,
killTree: true,
// killSignal: ' ', // Is there a killSignal that might fix this?
sourceDir: path,
env: { port: 8002 }
};
var monitor1 = new Forever.Monitor(file, options1);
var monitor2 = new Forever.Monitor(file, options2);
monitor1.on('start', function (process) {
console.log('started');
// correctly kill just the app process
// console.log(process);
// process.stop();
});
monitor1.on('restart', function () {
console.log('restart');
});
monitor1.on('stop', function () {
console.log('stopped');
});
monitor1.on('exit', function () {
console.log('exit');
});
monitor1.on('error', function (error) {
console.log('error: ' + error);
});
monitor2.on('start', function (process) {
console.log('started');
});
monitor2.on('restart', function () {
console.log('restart');
});
monitor2.on('stop', function () {
console.log('stopped');
});
monitor2.on('exit', function () {
console.log('exit');
});
monitor2.on('error', function (error) {
console.log('error: ' + error);
});
monitor1.start();
monitor2.start();
Forever.startServer(monitor1, monitor2);
Forever.list(false, function (error, list) {
if (error) console.log(error);
setTimeout(function () {
/*
THE ISSUE
This triggers an exit which kills the current process script/server
*/
Forever.stop('test2', false);
// this correctly stops the app process and does not trigger exit then restarts
// Forever.restart('test2', false);
// console.log(list);
}, 3000);
});