如何阻止 pm2 杀死分离的子进程

How to stop pm2 from killing detached child processes

pm2 正在 watch 重启时杀死分离的子进程(即使用 detached:true、stdio:'ignore' 和 child.unref() 产生的子进程。

有没有办法告诉 pm2 在重启时不要杀死子进程树?

答案是将以下内容放入生态系统文件(应用程序的主要部分,不在手表设置下):

"treekill": false

我最终使用了

pm2 restart myapp --no-treekill

pm2 stop myapp --no-treekill

我使用 pm2 API 从内部重新启动我的 nodejs 应用程序。这是我使用的函数,这样分离的子进程就不会被杀死(注意 treekill: false 选项)。

function restartPm2() {
    pm2.connect(function(err) {
        if (err) {
            console.error("PM2 FAILED TO CONNECT:", err);
        } else {
            pm2.restart('myapp.js', { treekill: false }, function() {});            
        }
    });

    pm2.disconnect();
}