Does supervisord kill running processes on with the restart command? - linux

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.

Related

How to kill the pm2 --no-daemon process

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.

Why pm2 deleting process automatically?

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.

How to find out why daemon tools supervise is exiting

I run a node process (websocket server) on an AWS instance. I used to start it like this:
node websocket/index.js
But have recently swiched to using daemontools supervise to run this process so that it respawns if it should quit or die for any reason.
So, I now run the process like this (from within the dir): supervise . &. The following is my ./run file:
#!/bin/sh
node websocket/index.js
This generally works well. When I manually kill -9 the Node process to test out it out, Supervise respawns it correctly.
However, every morning when I check in on things, the Node process and the Supervise process are both dead and nowhere to be found in ps. I confirmed that the system is not rebooting by looking at uptime.
How can I find out why the Supervise and Node processes are dying overnight? And how can I prevent this?
Update: I switched to using the node module forever to keep my process running, and it has been great so far.
https://www.npmjs.com/package/forever

Monit check processes for multiple pidfiles

I have a Nodejs Web app with multiple node process, which I start using pm2 start app.js multiple times.
To monitor these processes usinf monit, I created a init script using pm2's : pm2 startup ubuntu command. Then, in the monit config file for my App, I use this init script as start and stop program commands for monit. Then I use something like check process pm2_1 with pidfile /path/to/node-pidfile, for both the processes in the monit config file.
I would like monit to check the pidfiles of both these processes and when either or both processes are down, restart both the processes. So, here's what my my-webapp.monitrc looks like :
check process pm2_1
with pidfile /root/.pm2/pids/proc1-0.pid
start program = "/etc/init.d/pm2-init.sh start"
stop program = "/etc/init.d/pm2-init.sh stop"
check process pm2_2
with pidfile /root/.pm2/pids/proc2-1.pid
start program = "/etc/init.d/pm2-init.sh start"
stop program = "/etc/init.d/pm2-init.sh stop"
The problem is, if either of the processes is down,it works. But if both processes are down, monit executes the start command twice.
Is there a way to have a "OR" condition for check process to monitor multiple different pidfiles and execute the same start and stop commands only once ?

How do I shutdown a node project started by Forever? ungit

I'm using the open source project called Ungit. It is based on node.js and I really enjoy it but I don't know how to shut it off other than rebooting the whole box.
Ungit is using "forever-monitor" to have a process run forever. So when I do nohup ungit > /dev/null & I can't shut it down by killing it's process as it will restart it.
I have looked up forever-monitor project and I was able to install it globally and try to shut it by running forever stop [number] but forever list shows nothing and I don't know how to shut it down.
Thanks for any advices,
with forever list you can see list of forever process
with forever stop 0 you can stop first process .
with forever stop myscript.js you can stop a process with name of script
find the process that forever-monitor is running under and kill it first then kill the ungit process.
http://www.cyberciti.biz/faq/kill-process-in-linux-or-terminate-a-process-in-unix-or-linux-systems/

Resources