Tornado does not restart in supervisor

I use a tornado to launch a flash application, and I have a shell script that works a bit and then launches the application.

#!/usr/bin/env bash some_work more_work python /usr/share/theapp/theapp.py 

I am using a dispatcher to manage this little script. The sudo supervisorctl start theapp.sh works fine ( sudo supervisorctl start theapp.sh ), but when I want to restart, the python subprocess does not exit and does not hang, taking up the port and preventing it from starting up again. I tried adding traps to make sure that the python code is really stopped when the script is stopped by the supervisor, but that didn't work. I tried disabling the tornado for the gevent wsgi server and had the same problem. How do I make this little script?

+7
source share
3 answers

The TERM signal is only sent to theapp.sh bash script and is never accepted by the python process. You can try the stopasgroup option in the supevisor configuration section of the program, which is more compatible with how bash (and other shells) process signals [1].

[1] http://www.vidarholen.net/contents/blog/?p=34

+8
source

I had similar problems with supervisord and uwsgi, but this could be true for Tornado as well. The problem is with the signal that the Tornado service is waiting to restart. The default signal that the supervisor sends is SIG_TERM (see stopignal in the docs ). I'm not sure what Tornado expects, but you can try a few more options in the supervisord configuration, for example:

 # /etc/supervisor.d/myprogram.ini # http://supervisord.org/configuration.html#program-x-section-values [program:myprogram] command=/path/to/script/ .... stopsignal=INT 

or

 stopsignal=HUP 
0
source

Alternatively, if your shell script only does the preliminary work and nothing after the β€œreal” command, you can replace the last line

 exec python /usr/share/theapp/theapp.py 

Which will replace the shell process with the python process, so that the latter will receive a signal directly and with the added benefit that you do not complete the inactivity process all the time.

0
source

All Articles