我在nodejs中设置了一个应用程序,它由一个主进程(api.js)组成,另一个是从这个进程中分叉的(使用.fork())
此外,我还有永远监控以确保一切正常运行。
当主应用程序发生某些事情时,问题就出现了,永远就是表现,重新产生它。但它不会杀死二级分叉线程。
因此,在某些时候模拟错误后,ps aux中的进程堆栈变得越来越大,没有任何控制。
我正在使用killTree参数而没有任何运气。
任何帮助??
答案 0 :(得分:1)
forever-monitor以分离的子状态启动子进程,因此这是预期的行为。您的自定义永久监视脚本必须处理来自您正在使用和适当操作子进程的信号。
参考此文章: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();