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

Forever.stop() Terminates Main Forever/Server Process #811

Open
xeaone opened this issue Feb 16, 2016 · 3 comments
Open

Forever.stop() Terminates Main Forever/Server Process #811

xeaone opened this issue Feb 16, 2016 · 3 comments

Comments

@xeaone
Copy link

xeaone commented Feb 16, 2016

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);
});
@fresheneesz
Copy link

@AlexanderElias Your links are all broken for some reason, they all link to "https://github.com/foreverjs/forever/issues/url", which doesn't exist.

@xeaone
Copy link
Author

xeaone commented Feb 16, 2016

@fresheneesz Thanks I believe it it fixed now.

@xeaone
Copy link
Author

xeaone commented Feb 16, 2016

Created pull request fixing part of the issue with Forever.exit()

Link: #812

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants