PM2:许多进程的交错进程重新启动 [英] PM2: Stagger process restart for many processes

查看:135
本文介绍了PM2:许多进程的交错进程重新启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用PM2来管理我的流程.当前,我有一系列的机器人,每个机器人都有以下基本配置:

I'm using PM2 to manage my processes. Currently, I have a series of bots on it, each of which has the following basic configuration:

{
  "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
  ]
}

每个bot都有大约三个支持过程,并且都具有相同的cron重新启动.因此,10个程序意味着30个进程,所有进程同时重新启动.因此,重新启动时,将使用大量资源,这似乎导致了此间歇性错误:

Each bot has about three supporting processes, and all have the same cron restart. So, 10 programs means 30 processes, all restarting at the same time. As such, when the restart rolls around, alot of resources are used, which seems to have lead to this intermittent error:

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]

这会导致机器人退出,而不会重新启动;它只会有一个错误"的提示.地位.要解决此问题,我想设置两件事:

This causes the bot to exit, and not come back up; it will simply have an "errored" status. To resolve this, I'd like to setup two things:

  1. 在pm2中滚动重启,它将重启一个进程,等待它完成,然后继续进行下一个进程.
  2. 一种使pm2重新启动状态为错误"的进程的方法.

到目前为止,我仍在研究滚动重启,而我发现的最接近的是集群模式,这似乎并不是我想要的.有人对此有任何建议吗?

So far, I'm still looking into the rolling restart, and the closest I've found is clustered mode, which does not seem to be quite what I'm looking for. Does anyone have any advise on this?

有人可以帮忙吗?目前,PM2不会自动重新启动它,所以我必须解决的唯一方法是在出现错误后手动重新启动每个进程.如果我可以让它在出现错误"时重新启动;状态,或者错开重新启动的时间,这样每个进程都不会立即全部重新启动,那就太好了.

Can anyone help with this? Right now, PM2 is not restarting it automatically, so the only way I have to resolve this is by manually restarting each process after it has an error. If I can get it to restart on an 'error; status, or to stagger the restarts so each process does not restart all at once, that would be great.

在pm2日志中出现这样的错误:

I'm getting errors like this in the pm2 log:

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)

推荐答案

pm2.reload(process,errback)就是这样做的!引用自其文档:

pm2.reload(process, errback) does exactly that! Quoted from their documentation:

零停机滚动重启.随着每个实例分别重新启动,至少有一个进程将始终保持运行状态.仅适用于以群集模式启动的脚本.

Zero-downtime rolling restart. At least one process will be kept running at all times as each instance is restarted individually. Only works for scripts started in cluster mode.

请注意,您需要使用群集模式使用 pm2.reload().您可以使用重新启动策略,例如,当发生错误时,重新启动整个应用程序或以集群模式实现它.

Please note that you need to use cluster mode in order to use pm2.reload(). You can use restart strategies, i.e. when an error happens, to restart the whole application or implementing it with the cluster mode.

有一点点题外话:您还可以使用

On a slight off-topic note: You could also use the watch and restart logic in case you change any files in the running process (which would need the instances to reload).

这篇关于PM2:许多进程的交错进程重新启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆