简体   繁体   中英

pm2 app restarts randomly without reason

I have a staging and production server both running a Sails.js app (www.sailsjs.org). I have experienced pm2 restarting my app randomly without at correlation or pattern. 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

This happens in both staging and production servers in cluster mode or 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

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. I also have a keymetrics.io account that monitors the server which shows me the restarts of pm2 (the pm2.log correlates these restarts): 在此处输入图片说明

If you look at the PM2 help, pm2 --help , you will see an option --no-autorestart which says 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. You can increase the max memory until restart with the --max-memory-restart option.


Example with max-memory-restart set to 5000mb:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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