【发布时间】:2021-03-12 20:00:16
【问题描述】:
我正在使用 PM2 来管理我的流程。目前,我有一系列的机器人,每个机器人都有以下基本配置:
{
"apps" : [
{
"name" : "rasa_bot-rasa",
"script" : "python",
"pid_file" : "~/rasa_bot/rasa_bot.pid",
"out_file" : "~/logs/rasa_bot/rasa_bot.log"
"cron_restart": "0 23 * * Sat"
},
#other supporting processes go here, with the same cron_restart
]
}
每个机器人都有大约三个支持进程,并且都具有相同的 cron 重启。因此,10 个程序意味着 30 个进程,所有进程同时重新启动。因此,当重新启动时,会使用大量资源,这似乎导致了这个间歇性错误:
2020-11-28T23:00:16: PM2 log: Process with pid <PID here> could not be killed
2020-11-28T23:00:16: PM2 error: app=rasa_bot-rasa id=45 pid=<PID here> could not be stopped
2020-11-28T23:00:16: PM2 error: Process with pid <PID here> already exists
2020-11-28T23:00:16: PM2 error: Error: Process with pid <PID here> already exists
2020-11-28T23:00:16: PM2 log: App [rasa_bot-rasa:45] exited with code [0] via signal [SIGKILL]
这会导致机器人退出,而不是重新启动;它只会有一个“错误”状态。为了解决这个问题,我想设置两件事:
- 在 pm2 中滚动重启,它将重新启动一个进程,等待它完成,然后继续下一个进程。
- 一种让 pm2 以“错误”状态重新启动进程的方法。
到目前为止,我仍在研究滚动重启,我发现最接近的是集群模式,这似乎不是我想要的。有人对此有什么建议吗?
编辑:有人可以帮忙吗?现在,PM2 没有自动重新启动它,所以我必须解决这个问题的唯一方法是在每个进程出现错误后手动重新启动它。如果我能让它在出现“错误”时重新启动;状态,或者错开重启,这样每个进程就不会一次全部重启,那就太好了。
我在 pm2 日志中遇到这样的错误:
2021-01-17T02:00:11: PM2 log: Process with pid 2627 could not be killed
2021-01-17T02:00:11: PM2 error: app=testbotserver id=3 pid=2627 could not be stopped
2021-01-17T02:00:11: PM2 error: Process with pid 2627 already exists
2021-01-17T02:00:11: PM2 error: Error: Process with pid 2627 already exists
at Object.God.logAndGenerateError (/home/user/pm2/node_modules/pm2/lib/God/Methods.js:39:12)
at Object.God.startProcessId (/home/user/pm2/node_modules/pm2/lib/God/ActionMethods.js:295:21)
at /home/user/pm2/node_modules/pm2/lib/God/ActionMethods.js:439:20
at /home/user/pm2/node_modules/pm2/lib/God/ActionMethods.js:350:16
at Timeout._onTimeout (/home/user/pm2/node_modules/pm2/lib/God/Methods.js:176:16)
at ontimeout (timers.js:482:11)
at tryOnTimeout (timers.js:317:5)
at Timer.listOnTimeout (timers.js:277:5)
【问题讨论】: