停止节点Windows服务不会杀死所有群集进程

时间:2019-11-25 07:41:35

标签: node.js node-windows

除了使用node-windows将其作为多线程运行之外,我还使用cluster软件包将我的 node 应用程序作为Windows服务运行。

通过 CMD 运行代码时,它的效果非常好,并且使用 CTRL + C 停止该进程将按预期终止所有进程。

但是当我通过服务运行它并尝试停止它时,应用程序将继续工作!

顺便说一句,如果我在不使用群集的情况下运行服务;它按预期工作!

app.js

const cluster = require('cluster');
// used to run the application through multiple threads
if (cluster.isMaster) {
    // run threads as cors as server has
    let cors = process.env.CORS;

    while (cors) {
        cluster.fork();
        cors--;
    }

    return;
}

// ... some code here

app.listen(process.env.PORT)

function shutdown() {
    // i tried to log something on shutingdown, but it's not called through the service
}

// listen for TERM signal, e.g: kill
process.on('SIGTERM', shutdown);

// listen for INT signal, e.g: CTRL + C
process.on('SIGINT', shutdown);

因此,如何 node-windows 停止应用程序,我该怎么做才能解决此问题?

0 个答案:

没有答案