I using pm2. After I started my app several times, the id increased. I deleted all in pm2, and started again, but the id didn't count from 0 any more. How can I reset it?
The solution is to restart pm2, by typing pm2 kill as said by ItalyPaleAle in the comments.
Per pm2's GitHub:
$ pm2 reset <process> # Reset meta data (restarted time...)
Reference: GitHub issue#1456
Looking at the help menu (pm2 --help) it seems like pm2 reset would be the way to go. But that command resets metadata (restarted time, etc) and does not reset IDs. One solution is to use pm2 kill to kill the pm2 daemon and restart it again (thanks, #Yao Zhao). But doing so will stop all current processes. A better approach would be to save the list of current processes, restart pm2, and then restore those processes using the following set of commands.
$ pm2 dump
$ pm2 kill
$ pm2 resurrect
Related
currently i'm using pm2 to manage my process, and i'm still new to this. I've search some docs but still not sure.
About autostartup, what is the propper way to update my nodeJS script? right now, i just execute pm2 restart all after i update some of my script. But since i want to use pm2 startup. Do i need to execute pm2 save also ?
Also on what occasion we need to update PM2 Startup Script? pm2 unstartup then pm2 startup ?
No you don't need to execute pm2 save if your script content change.
pm2 save is only for saving PM2 process configuration. So if the startup script change of location or name, you need to execute pm2 save.
Once executed pm2 save permit you restart all process after a crash or reboot with the command ``pm2 resurrect```
To restart a process use pm2 restart <id> <here id is the id of the process. You should avoid use pm2 restart allfor restarting only one process.
If you use pm2 startup, you need to do a pm2 save each time a process is added or process ecosystem change. pm2 startup just manage for you the automatic starting of PM2 when server reboot.
I can see all the processes using pm2 ls, but how can lo into a process and see the logs and make changes?
To make this question pass quality standards I'm adding these unnecessary lines.
Try
pm2 logs "processId here"
or
pm2 monit "processId here"
I am running 3 process in pm2. But after 2-3 month my process are getting deleted from pm2 list. Its like we just installed pm2.
I want to know why this is happening and how to rectify it.
Are you sure that the PM2 daemon is still alive when you're doing the pm2 list ? If you run out of memory, chance are that your OS kill the pm2 daemon and by the way killing your application since they are process child of pm2 daemon.
I have a node chat application that needs to keep running on my server (ubuntu with nginx). The problem is that the application stops after a few hours or days.
When I check on the server I see that my pm2 list is empty.
The code I use to start my app:
pm2 start notification_server/index.js
It somehow looks as if pm2 is reset after a while. I also tried using forever, but then I run into the same problem. Is there some way to prevent the pm2 list from getting empty?
This is most likely an indication that your server is rebooting. When your server reboots, PM2 shuts down and deletes all Node instances from its "status" list.
You can perform the following steps to make PM2 relaunch your Node programs start back up on reboot:
Run pm2 startup and follow the directions (you will have to perform a sudo command; PM will tell you exactly what to do).
Through pm2 start, get your Node processes up and running just like you like them.
Run pm2 save to register the current state of things as what you want to see on system startup.
Source: http://pm2.keymetrics.io/docs/usage/startup/
Did you try checking logs $ pm2 logs for you application?
Most likely it will tell you why your application was terminated or maybe it just exited as it supposed to. You could find something like that there:
PM2 | App [app] with id [0] and pid [11982], exited with code [1] via signal [SIGINT]
This can tell you what happened. Without more details, it's hard to give you a better answer.
I have a Node.js app ready which is workable, but has known and unknown bugs which crash the app. In such cases it would be nice if pm2 can restart the node app. Is this feature already available in pm2?
Yes, it does this by default. For more information see Restart strategies.
If the app repeatedly fails to start over a short period of time, pm2 may cease restarting. See configuration, min_uptime and max_restarts.
Also, check this new excellent option:
--exp-backoff-restart-delay=100
pm2 will restart the crashed app after 100 milliseconds (0.1 seconds), then step-by-step increase restart-delay to 15 seconds.
To make app restart when it crashes you have to use one of PM2's restart strategies.
There is something called "Exponential Backoff Restart Delay" which PM2 explains as:
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 using the CLI like this:
pm2 start app.js --exp-backoff-restart-delay=100
There are other restart methods also, which are mentioned here.
This may help:
# Generate Startup Script
$ pm2 startup
# Freeze your process list across server restart
$ pm2 save
# Remove Startup Script
$ pm2 unstartup
More details here