简体   繁体   English

pm2应用无故随机重启

[英]pm2 app restarts randomly without reason

I have a staging and production server both running a Sails.js app (www.sailsjs.org). 我有一个同时运行Sails.js应用程序(www.sailsjs.org)的暂存和生产服务器。 I have experienced pm2 restarting my app randomly without at correlation or pattern. 我经历过pm2随机重启我的应用程序而没有相关性或模式。 I've checked the following for any pattern: - Memory usage leading up to restart - sometimes it's ~320MB and others it's ~410MB - Events/Requests/Errors nothing in my Nginx, Node, PM2, or App logs show errors or any concerns 我检查了以下任何模式:-导致重新启动的内存使用-有时约为320MB,其他约为410MB-事件/请求/错误Nginx,Node,PM2或App日志中没有显示错误或任何问题

This happens in both staging and production servers in cluster mode or fork. 在群集模式或fork的登台服务器和生产服务器中都会发生这种情况。 It does NOT happen locally, at least I haven't experienced it. 它不会在本地发生,至少我还没有经历过。

Info Servers: Digitalocean droplets 2GB RAM 2 CPU/Core Ubuntu 14.04 lts Node: v4.4 PM2: 1.0.2 信息服务器:Digitalocean Droplet 2GB RAM 2 CPU / Core Ubuntu 14.04 lts节点:v4.4 PM2:1.0.2

Also, the pm2 list command shows the app running for 3h but says there have been zero restarts when I know for a fact the app has been running for several days. 另外, pm2 list命令显示应用程序运行了3h,但是说当我知道该应用程序已经运行了几天时,重启次数为零。 I also have a keymetrics.io account that monitors the server which shows me the restarts of pm2 (the pm2.log correlates these restarts): 我还有一个keymetrics.io帐户,该帐户监视服务器,该帐户向我显示pm2的重启(pm2.log与这些重启相关): 在此处输入图片说明

If you look at the PM2 help, pm2 --help , you will see an option --no-autorestart which says start an app without automatic restart . 如果您查看PM2帮助pm2 --help ,则会看到--no-autorestart选项,该选项表示start an app without automatic restart That should do it. 那应该做。

But you want PM2 to to be able to restart when it is out of memory. 但是您希望PM2在内存不足时能够重新启动。 You can increase the max memory until restart with the --max-memory-restart option. 您可以增加最大内存,直到使用--max-memory-restart选项--max-memory-restart为止。


Example with max-memory-restart set to 5000mb: max-memory-restart设置为5000mb的示例:

PM2 start --name my-process --max-memory-restart 5000M index.js

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM