Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 664
Cal Paterson Avatar asked Jul 07 '12 11:07

Cal Paterson


1 Answers

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

like image 133
Stefan Friesel Avatar answered Oct 04 '22 17:10

Stefan Friesel