node.js pm2节点模块崩溃后能否自动重启app
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26135371/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can the pm2 node module restarts the app after crash automatically
提问by Talespin_Kit
I have a node app ready which is workable, but has known and unknown bugs which crashes the node app. In such cases it would be nice if pm2 can restart the node app. Is this feature already available in pm2 ?
我有一个可用的节点应用程序,但有已知和未知的错误,这些错误会导致节点应用程序崩溃。在这种情况下,如果 pm2 可以重新启动节点应用程序,那就太好了。这个功能在 pm2 中已经可用了吗?
回答by jgillich
Yes, it does this by default and there is even a watch optionto restart on changes.
是的,它默认执行此操作,甚至还有一个监视选项可以根据更改重新启动。
回答by xoid
Also, check new excellent option
另外,检查新的优秀选项
--exp-backoff-restart-delay=100 (msec, not sec!)
pm2 will restart crashed app after 100 msec, then step-by-step increase restart-delay to 15 secunds
pm2 将在 100 毫秒后重启崩溃的应用程序,然后逐步将重启延迟增加到 15 秒
回答by illiteratewriter
To make app restart when it crash you have to use one of PM2 Restart strategies.
要在应用程序崩溃时重新启动,您必须使用 PM2 重启策略之一。
There is something called Exponential Backoff Restart Delay which PM2 explains as:
有一种叫做指数退避重启延迟的东西,PM2 解释为:
Instead of restarting your application like crazy when exceptions happens (e.g. database is down), the exponential backoff restart will increase incrementaly the time between restarts.
当异常发生(例如数据库关闭)时,不是像疯狂地重新启动您的应用程序,指数退避重新启动将增加重新启动之间的时间。
You can set it with CLI by pm2 start app.js --exp-backoff-restart-delay=100.
您可以通过 CLI 设置它pm2 start app.js --exp-backoff-restart-delay=100。
There are other restart methods also, which are mentioned here.
还有其他重启方法,这里提到。

