简体   繁体   中英

nodejs forever-monitor not killing fork processes

I'm setting up an app in nodejs, its made up form one main process (api.js) and another one which is forked from this one (using .fork() )

Also I have forever-monitor to guarantee everything is running if anything occur.

The problem comes when something happen in the main app, forever is behaving, re spawning it. But its its not killing the secondary forked thread.

So after sometime simulating errors the process stack in ps aux is getting bigger without any control.

I'm using the killTree parameter without any luck.

Any help??

forever-monitor starts the child process in a detached child state so this is the expected behavior.Your custom forever-monitor script has to handle the signals from whatever you're using and manipulate the child process appropriately.

Refer this article : https://github.com/foreverjs/forever-monitor/issues/5

var forever = require('forever-monitor');
process.stdin.resume();

var child = new(forever.Monitor)('Index.js', {
    max: 5,
    silent: false,
    minUptime: 2000,
    spinSleepTime: 5000
});

child.on('start', function() {
    console.log('Forever started for first time.');
});

child.on('exit', function() {
    console.error('Index.js file has exited after '+child.max+' restarts');
});

//Exit handler.
function exitHandler(options, err) {
    try{
        //Killing node process manually that is running "Index.js" file.
        process.kill(child.childData.pid);
        console.log("Child process killed succesfully!!");
        console.log("Forever exit!!");
    }
    catch(err){
        console.log("Child process already stopped!!");
        console.log("Forever exit!!");
    }

    //Killing forever process.
    process.exit();
}

//Handling user exit events like Ctrl+C.
process.on('SIGINT', exitHandler.bind(null, {exit: true}));    

child.start();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM