简体   繁体   English

nodejs永久监控不会杀死fork进程

[英]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() ) 我正在nodejs中建立一个应用程序,它由一个主进程(api.js)组成,另一个由该主进程派生(使用.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. 因此,经过一段时间的错误仿真,ps aux中的过程堆栈会变得越来越大,而无需任何控制。

I'm using the killTree parameter without any luck. 我正在使用killTree参数,没有任何运气。

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. forever-monitor在分离的子状态下启动子进程,因此这是预期的行为。您的自定义forever-monitor脚本必须处理来自您正在使用的任何信号,并适当地操纵该子进程。

Refer this article : https://github.com/foreverjs/forever-monitor/issues/5 请参阅此文章: 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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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