ochinchina / supervisord

a go-lang supervisor implementation
MIT License
3.94k stars 548 forks source link

supervisord ctl stop doesn't work for inner commands #48

Open Siecje opened 6 years ago

Siecje commented 6 years ago

In my supervisord config I'm running a script which sets some environment variables and then runs a script. If I do supervisord ctl stop $program it removes the first script but re-parents the inside script to be a child of init and continues to run. After supervisord ctl stop, it still shows as running in supervisord status and is actually still running.

Here are the test files I am using.

supervisord config

[inet_http_server]
port=127.0.0.1:9001

[program:one]
command=/home/siecje/Desktop/one.sh

one.sh

#!/bin/sh

/home/siecje/.virtualenvs/edms/bin/python /home/siecje/Desktop/one.py

one.py

from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Hello, World!'

if __name__ == '__main__':
    import waitress
    waitress.serve(app, host = "localhost", port = 5000)

one.py will run forever serving a web application. In order to run it you will need to pip install Flask waitress.

Siecje commented 6 years ago

Here is htop output

supervisord -c config.conf -d

 1 root       20   0  117M  5972  3920 S  0.0  0.1  0:02.46 /sbin/init splash
  6955 siecje     20   0  135M  6364  5480 S  0.0  0.2  0:00.02 ├─ ./supervisord -c config.conf -d
  6975 siecje     20   0  135M  6364  5480 S  0.0  0.2  0:00.00 │  ├─ ./supervisord -c config.conf -d 
  6965 siecje     20   0  4508   792   716 S  0.0  0.0  0:00.00 │  ├─ /bin/sh /home/siecje/Desktop/one.sh
  6966 siecje     20   0  346M 19876  7252 S  0.0  0.5  0:00.10 │  │  └─ /home/siecje/.virtualenvs/edms/bin/python /home/siecje/Desktop/one.py
  6974 siecje     20   0  346M 19876  7252 S  0.0  0.5  0:00.00 │  │     ├─ /home/siecje/.virtualenvs/edms/bin/python /home/siecje/Desktop/one.py 
  6973 siecje     20   0  346M 19876  7252 S  0.0  0.5  0:00.00 │  │     ├─ /home/siecje/.virtualenvs/edms/bin/python /home/siecje/Desktop/one.py 
  6972 siecje     20   0  346M 19876  7252 S  0.0  0.5  0:00.00 │  │     ├─ /home/siecje/.virtualenvs/edms/bin/python /home/siecje/Desktop/one.py 

supervisord ctl stop one

     1 root       20   0  117M  5972  3920 S  0.0  0.1  0:02.46 /sbin/init splash
  6966 siecje     20   0  346M 19876  7252 S  0.0  0.5  0:00.11 ├─ /home/siecje/.virtualenvs/edms/bin/python /home/siecje/Desktop/one.py
  6974 siecje     20   0  346M 19876  7252 S  0.0  0.5  0:00.00 │  ├─ /home/siecje/.virtualenvs/edms/bin/python /home/siecje/Desktop/one.py 
  6973 siecje     20   0  346M 19876  7252 S  0.0  0.5  0:00.00 │  ├─ /home/siecje/.virtualenvs/edms/bin/python /home/siecje/Desktop/one.py 
  6972 siecje     20   0  346M 19876  7252 S  0.0  0.5  0:00.00 │  ├─ /home/siecje/.virtualenvs/edms/bin/python /home/siecje/Desktop/one.py 
  6971 siecje     20   0  346M 19876  7252 S  0.0  0.5  0:00.00 │  └─ /home/siecje/.virtualenvs/edms/bin/python /home/siecje/Desktop/one.py 
  6955 siecje     20   0  135M  7036  5992 S  0.0  0.2  0:00.03 ├─ ./supervisord -c config.conf -d
  6975 siecje     20   0  135M  7036  5992 S  0.0  0.2  0:00.00 │  ├─ ./supervisord -c config.conf -d 
  6963 siecje     20   0  135M  7036  5992 S  0.0  0.2  0:00.00 │  ├─ ./supervisord -c config.conf -d 
  6962 siecje     20   0  135M  7036  5992 S  0.0  0.2  0:00.00 │  ├─ ./supervisord -c config.conf -d
  6961 siecje     20   0  135M  7036  5992 S  0.0  0.2  0:00.00 │  ├─ ./supervisord -c config.conf -d 
  6960 siecje     20   0  135M  7036  5992 S  0.0  0.2  0:00.01 │  ├─ ./supervisord -c config.conf -d 
  6959 siecje     20   0  135M  7036  5992 S  0.0  0.2  0:00.00 │  ├─ ./supervisord -c config.conf -d 
  6958 siecje     20   0  135M  7036  5992 S  0.0  0.2  0:00.00 │  └─ ./supervisord -c config.conf -d
Siecje commented 6 years ago
$ supervisord ctl status
one                              RUNNING   pid 6965, uptime 0:09:33
$ supervisord ctl stop one
one: stopped
$ supervisord ctl status
one                              RUNNING   pid 6965, uptime 0:09:41
ochinchina commented 6 years ago

I will check this issue soon

ochinchina commented 6 years ago

I fixed this issue and please try it again

Siecje commented 6 years ago

Fixed with https://github.com/ochinchina/supervisord/commit/448b33773c80e1656e1d611b5afa4747eb45c8f9! Thank you very much!

Siecje commented 5 years ago

The example above works but it is not working with more than one child processes.

I'm running Jupyterhub with supervisord.

[program:jupyterhub]
autostart=false
command=/boot/app/jupyterhub/jupyterhub.sh
process_name=%(program_name)s
startretries=5
stdout_logfile=syslog
stderr_logfile=syslog
stopsignal=TERM
user=jupyterhub:app

jupyterhub.sh

#!/bin/sh
export PYTHONOPTIMIZE="1"  # forces python -O
JUPYTERHUB_PATH="/boot/tp/python3/bin/jupyterhub"
if [ -f /boot/DEBUG_PYTHON ]; then
  export PYTHONOPTIMIZE=""  # disables it (ie: no -O assumed)
fi
PATH=/boot/tp/bin:"${PATH}"
"${JUPYTERHUB_PATH}" -f /boot/app/jupyterhub/jupyterhub_config.py

When I do supervisord ctl stop jupyterhub, it just hangs forever and does return to the prompt.

Before supervisord ctl stop jupyterhub

    1 root       20   0  9752  1992  1880 S  0.0  0.1  0:00.46 init
  860 root       20   0 1591M 18956  6172 S  0.0  1.0  0:00.07 `- /boot/tp/bin/supervisord -c /boot/pcore/sysfiles/supervisord.conf -d
 1444 jupyterhu  20   0  9752   928   840 S  0.0  0.0  0:00.00 |  `- /bin/sh /boot/app/jupyterhub/jupyterhub.sh
 1445 jupyterhu  20   0  381M 45500  8436 S  0.0  2.3  0:00.40 |  |  `- /boot/tp/python3/bin/python3 /boot/tp/python3/bin/jupyterhub -f /boot/app/jupyterhub/jupyterhub_config.py
 1591 jupyterhu  20   0  169M 18588  6912 S  0.0  0.9  0:00.06 |  |     `- /boot/tp/bin/python /boot/app/jupyterhub/cull_idle_servers.py --timeout=3600
 1583 jupyterhu  20   0  851M 31224 20468 S  0.0  1.6  0:00.12 |  |     `- node /boot/tp/bin/configurable-http-proxy --log-level=WARN --ip  --port 8000 --api-ip 127.0.0.1 --api-port 8001 --error-target http://127.0.0.1:8081/notebooks/hu

After

1 root       20   0  9752  1992  1880 S  0.0  0.1  0:00.46 init
 1591 jupyterhu  20   0  169M 18588  6912 S  0.0  0.9  0:00.06 `- /boot/tp/bin/python /boot/app/jupyterhub/cull_idle_servers.py --timeout=3600
 1583 jupyterhu  20   0  851M 31224 20468 S  0.0  1.6  0:00.12 `- node /boot/tp/bin/configurable-http-proxy --log-level=WARN --ip  --port 8000 --api-ip 127.0.0.1 --api-port 8001 --error-target http://127.0.0.1:8081/notebooks/hub/error
  860 root       20   0 1591M 18956  6172 S  0.0  1.0  0:00.07 `- /boot/tp/bin/supervisord -c /boot/pcore/sysfiles/supervisord.conf -d