【发布时间】:2021-07-06 00:46:57
【问题描述】:
我已经设置了一个以 pm2 开头的 node.js 应用程序,一切正常
我也尝试过添加监视和保存选项(请参阅下面有关 Windows 服务的更多信息)
pm2 start app.js --watch
pm2 save
但最终在我从 Windows 注销 RDP 后应用程序不再运行。
在pm2 report的相关输出下方
==
PM2 | 2021-04-10T11:26:39: PM2 log: --- New PM2 Daemon started ----------------------------------------------------
PM2 | 2021-04-10T11:26:39: PM2 log: Time : Sat Apr 10 2021 11:26:39 GMT+0200 (Central European Summer Time)
PM2 | 2021-04-10T11:26:39: PM2 log: PM2 version : 4.5.6
PM2 | 2021-04-10T11:26:39: PM2 log: Node.js version : 14.16.1
PM2 | 2021-04-10T11:26:39: PM2 log: Current arch : x64
PM2 | 2021-04-10T11:26:39: PM2 log: PM2 home : V:\.pm2
PM2 | 2021-04-10T11:26:39: PM2 log: PM2 PID file : V:\.pm2\pm2.pid
PM2 | 2021-04-10T11:26:39: PM2 log: RPC socket file : \\.\pipe\rpc.sock
PM2 | 2021-04-10T11:26:39: PM2 log: BUS socket file : \\.\pipe\pub.sock
PM2 | 2021-04-10T11:26:39: PM2 log: Application log path : V:\.pm2\logs
PM2 | 2021-04-10T11:26:39: PM2 log: Worker Interval : 30000
PM2 | 2021-04-10T11:26:39: PM2 log: Process dump file : V:\.pm2\dump.pm2
PM2 | 2021-04-10T11:26:39: PM2 log: Concurrent actions : 2
PM2 | 2021-04-10T11:26:39: PM2 log: SIGTERM timeout : 1600
PM2 | 2021-04-10T11:26:39: PM2 log: ===============================================================================
Please copy/paste the above report in your issue on https://github.com/Unitech/pm2/issues
我想知道 pm2 主路径是否可能是根本原因,因为它是一个用户共享,但我找到了如何通过 PM2_HOME env var 在 Windows 上更改它,它也没有解决问题.
我已经搜索了 github 问题,那里似乎已经有类似的未解决问题,例如 this one:
如果我直接进入服务器启动 pm2 并注销用户,也会发生同样的情况 进程将消失。有没有办法在全球寡妇上启动 pm2 所以当用户注销时它不会退出?或者我正在做某事 错了吗?
和
我也想了解是否可以选择保留应用 从 Windows 服务中注销用户后运行
这里有人有解决办法吗?
我还尝试使用 admin cmd 设置 pm2-windows-service,如 readme here 中所述。
我已经在 express 应用中为 SIGTERM 添加了一个处理程序:
app.listen(HTTP_PORT, () => {
console.log("Server is listening on port " + HTTP_PORT);
});
process.on('SIGINT', function() {
console.log('Do not shut down the app on user log-off');
//server.close();
});
【问题讨论】:
标签: node.js express pm2 windows-server-2016