Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

supervisord stopping child processes

One of the problems, I face with supervisord is that when I have a command which in turn spawns another process, supervisord is not able to kill it.

For example I have a java process which when runs normally is like

 $ zkServer.sh start-foreground  $ ps -eaf | grep zk  user 30404 28280  0 09:21 pts/2    00:00:00 bash zkServer.sh start-foreground  user 30413 30404 76 09:21 pts/2    00:00:10 java -Dzookeeper.something..something 

The supervisord config file looks like:

[program:zookeeper] command=zkServer.sh start-foreground autorestart=true stopsignal=KILL 

These kind of processes which have multiple childs are not well handled by supervisord when it comes to stopping them from supervisorctl. So when I run this from the supervisord and try to stop it from supervisorctl, only the top level process gets killed but not the actual java process.

like image 552
FUD Avatar asked Feb 01 '12 04:02

FUD


People also ask

What is the use of supervisord?

Supervisord or Supervisor daemon is an open source process management system. In a nutshell: if a process crashes for any reason, Supervisor restarts it. From the Supervisord website: Supervisor is a client/server system that allows its users to monitor and control a number of processes on UNIX-like operating systems.

How can the supervisor process be stopped?

Finally, you can exit supervisorctl with Ctrl+C or by entering quit into the prompt: supervisor> quit.

How does Supervisorctl work?

Supervisorctl allows a very limited form of access to the machine, essentially allowing users to see process status and control supervisord-controlled subprocesses by emitting “stop”, “start”, and “restart” commands from a simple shell or web UI.

How do I restart my supervisord process?

To start a non-running service or stop a running one, use supervisorctl start my-daemon and supervisorctl stop my-daemon . To restart a service, you can also use supervisorctl restart my-daemon .


2 Answers

The same problem was encountered by Rick Hanlon II here: https://coderwall.com/p/4tcw7w

Option stopasgroup=true should be set in the program section for supervisord to stop not only the parent process but also the child processes.

The example is given as:

[program:some_django]  command=python manage.py runserver  directory=/dir/to/app  stopasgroup=true 

Also, have in mind that you may have an older package of supervisord that does not have "stopasgroup" functionality. I tried these Debian packages on Raspberry Pi:

  • supervisor_3.0a8 does not work.
  • supervisor_3.0b2-1 works as expected.
like image 75
kuzavas Avatar answered Sep 22 '22 03:09

kuzavas


Doing the following early in the main bash script called by supervisord fixed the problem for me:

trap "kill -- -$$" EXIT 

This kills the entire process group when the main script exits, such as when it is killed by supervisord.

like image 28
Fred Yankowski Avatar answered Sep 25 '22 03:09

Fred Yankowski