Tornado doesn't restart cleanly in supervisor

怎甘沉沦 提交于 2020-01-31 05:25:11

问题


I'm using tornado to run a flask app, and I have a shell script which does a little work and then runs the app.

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

I use supervisor to manage this little script. Starting up works fine (sudo supervisorctl start theapp.sh), but when I want to restart, the python subprocess doesn't exit and hangs around, occupying the port and preventing startup again. I've tried adding traps to ensure that the python code really is stopped when the script is stopped by supervisor, but this hasn't worked. I've tried switching out tornado for gevent's wsgi server and have had the same problem. How should I be doing this small script?


回答1:


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

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




回答2:


Alternatively, if your shell script only does preperation stuff and nothing after the "real" command, you can replace the last line with

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

Which will replace the shell process with the python process, so the latter gets the signal directly and with the added benefit that you don't have an idle shell process running all the time.




回答3:


I've had similar problems with supervisord and uwsgi, but it might be valid for Tornado too. The problem is with the signal the Tornado service expects to restart. The default signal that supervisord sends is SIG_TERM (look at stopsignal in docs). I'm not sure what Tornado expects, but you can try some more options in the supervisord config, like:

# /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


来源:https://stackoverflow.com/questions/11374543/tornado-doesnt-restart-cleanly-in-supervisor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!