I have a script(bash) which monitors pm2 memory usage and restarts the process if pm2 process takes memory more than 2 GB. But when i run the command (pm2 restart all) from the script, all processes in pm2 keep restarting again and again.
I am running this script via a crontab.
I want to be able to successfully restart all apps without continous restart.
pm2 already has an option for max memory which is max_memory_restart: "3G" which will restart the process if it's taking more than 3G for example.
Source: http://pm2.keymetrics.io/docs/usage/process-management/#max-memory-restart
We have supervisord running in production and I'd like to know if after running $ supervisorctl restart group-name:* if running processes are killed immediately or if supervisor lets running processes finish.
Tried my best to find that out in the docs and the source code.
As far as I know, supervisorctl will kill process, because usually under supervisor work worker script which never stops, hence it is no way to supervisorctl understand when script is ready to be stopped.
I'm using pm2 as the process manager of Node.js.
In many cases, I think I will run it as a daemon process, but if you use it locally as debugging, I think that there are times when you use the --no-daemon option.
How do I end the process when moving pm2 with this --no-daemon option?
You can try:
pm2 kill
or find the running PM2 process with:
ps aux | grep PM2
then kill with:
kill -9 [pid]
The -9 switch sends the KILL signal to the process as opposed to the default interrupt (INT or SIGINT) signal and is equivalent to -KILL or -SIGKILL. Interrupt is a less invasive way and you could try that first to let the process gracefully exit, however, if it doesn't respond to that, the kill signal should result in an immediate termination (unless the process is zombie).
You can view all processes which are registered with pm2 using
pm2 list
Assume the process you want to stop is named as processA using the below command will stop the processA:
pm2 stop processA
In case you want to delete the process than use the below command:
pm2 delete processA
In case you don't want to kill a particular process but pm2 itself using the command below:
pm2 kill
The right answer is pm2 kill
$pm2 kill
[PM2] [v] Modules Stopped
[PM2] Applying action deleteProcessId on app [all](ids: 0)
[PM2] hello ✓
[PM2] [v] All Applications Stopped
[PM2] [v] PM2 Daemon Stopped
Other solution will be to run pm2 delete all or pm2 stop all. Which will not kill pm2 process itself, but will cleanup internal pm2's process list.
First of all list all processes:
pm2 list
let suppose if your process is dev
pm2 stop dev
Now, delete the process
pm2 delete dev
after that process state became daemon.
If you want to kill that daemon process then run command
pm2 kill
sudo pkill -f pm2
This should kill all processes of pm2 in linux
One thing to add to the accepted answers. These commands only work for the current user. I had the same problem with a digitalocean droplet. I had logged in using "ubuntu" username, but I saw that the God Daemon is pointing to /home/nodejs/.pm2.
If this is the case, you need to switch to that user:
sudo su nodejs
And then run the pm2 kill commands from there.
If it's running in the foreground you should be able to kill it with ctl + c, same as you would kill node server.js.
Twice now all apps I have been running through pm2 has been stopped for no apparent reason to me. All apps where started with pm2 start app.js -n prettyname which works fine for a few days until this.
No I idea why it stops. But doing any pm2 command like the above in the screenshot, starting, restarting or stopping results in the same. [PM2] Spawning PM2 daemon
Is there a way to restart the apps without restarting the server?
node 0.10.32
pm2 0.15.10
Try below command to restart all pm2 apps,
pm2 restart all
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.