what's pm2 auto restart strategy?
I tried to use pm2 to start the Next.js application, React rendering errors, Pm2 can see the Error log, but will not restart.
I tried to use Pm2 to start a simple Koa application. When processing the network request, I triggered a JS error and Pm2 can see the Error logļ¼ but Pm2 did not restart.
Restart app at a specified CRON time
Restart app when files have changed
Restart when app reach a memory threshold
Delay a start and automatic restart
Disable auto restart (app are always restarted with PM2) when crashing or exiting by default)
Restart application automatically at a specific exponential increasing time
Reference Link : https://pm2.keymetrics.io/docs/usage/restart-strategies/
i hope this link will help you
Related
Good morning!
I need my node.js server running in the background. I just saw this answer: Forever + Nodemon running together
I understand the idea, and I think that it's great, but when I use
forever -c "nodemon --exitcrash" app.js
the nodemon console stills visible. How can I hide the console?
Thank you everyone!
Try using pm2 pm2 guides
With pm2 your application runs in the background and:-
Can auto-start on server reboots
You can even set pm2 to watch for file changes and reload your application
You can monitor your application and see resource utilization
You can view logs
You can run your application in cluster and load-balance requests using pm2
user 1550 1 0 Jun19 ? 00:00:00 node /usr/bin/nodemon src/server.js
user 11051 1550 0 Jun19 ? 00:00:38 /usr/bin/node src/server.js
Can someone tell how this process running in the background? The user is not logged in.
it seems you are running your nodejs Application using nodemon
nodemon is used to do auto reload when an application crashed. because nodejs is single thread application, if you did not catch the error safely, it will crash the application. as nodejs is used for server-side application, its needed to use a tool which will do auto restart when its crashed.
you can kill the process by running the below command.
(mine ubuntu):
$ kill -9 <proceessId> //here it will nodemon process it
I was having issue with nodemon, as soon as I search for files ir VSC sidebar, or, sometimes, start server, nodemon starts to restart "due to changes" even-though there are no changes. This keeps going for several minutes, and then my PC crashes.
Try running nodemon with delay option.
nodemon YOURFILE --delay 1
This fixed it for me.
I had a node process running with pm2. It showed up in the result of pm2 list. Now I see the process isn't running anymore, and pm2 list is empty.
Are there any pm2 logs which show me when and why it stopped running my node process?
Well first of all you have the pm2 logs command that will show you logs, but pm2 is running by the user that ran the pm2 start commant. Meanning that if you were in sudo mode and ran pm2 start you will not see the application list from a regular user.
If this is not the issue, you should know that if you restart your machine, the list deletes. if you want to keep the list after restart, you need to run pm2 save after you finish starting your applications/json configuration file.
Issuing "pm2 restart all" will restart all of the processes pm2 is managing.
I am wondering: If there have been changes to any of the source files, does this actually reload the changes? Or does it just restart the existing pm2 process in memory.
Yes, pm2 restart picks up local changes. Clients may have to clear cache/refresh if you're not seeing the changes.