如何限制 pm2 上的自动重启次数? [英] How do I limit the number of auto-restarts on pm2?

查看:338
本文介绍了如何限制 pm2 上的自动重启次数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在 pm2 上运行的节点服务器,它依赖于一些外部服务.

I have a node server running on pm2 which depends on some external services.

当这些服务器出现故障时,我 pm2 开始重新启动我的应用程序,但这会一直持续,直到它堵塞服务器上的 cpu 和 ram,每分钟重新启动多达 50 次.

When those servers go down I pm2 starts restarting my app, but this will keep going until it clogs up my cpu and ram on the server, restarting as much as 50 times a minute.

有没有办法限制pm2上的重启次数?当服务器达到某个 RAM 内存级别时,有一种方法可以重新启动服务器,所以我希望我要求的这个功能存在.

Is there a way to limit the numbers of restarts on pm2? There is a way to restart the server when the server reaches a certain RAM memory level, so I would hope this feature I am asking for exists.

推荐答案

您可以结合使用 max_restartsmin_uptime 来限制应用程序连续重启.

You can use combination of max_restarts and min_uptime to restrict the app to restart consecutively.

在您的应用被视为错误并停止重新启动之前,连续不稳定重新启动的次数(小于 1 秒间隔或通过 min_uptime 自定义时间)

number of consecutive unstable restarts (less than 1sec interval or custom time via min_uptime) before your app is considered errored and stop being restarted

有关max_restartsmin_uptime 的更多信息可在这里

More information about max_restarts and min_uptime is available here

这篇关于如何限制 pm2 上的自动重启次数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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