Search code examples
pythontornadosupervisord

Tornado doesn't restart cleanly in supervisor


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?


Solution

  • 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