When my server (centOS 7 hosted on a vagrant VM) reboots, my Python Flask application (served up by Gunicorn using nginx as a reverse proxy) throws internal server errors (according to the stack traces I'm getting, it can't find templated html files even...) until a sudo supervisorctl reload
is issued. After this, the application runs just fine and my life is good but that won't do now will it?
I suspect a race condition (maybe between supervisor and gunicorn?). I tried adding a sleep to the command
in the specific program's .ini
file but this didn't help anything.
Has anyone else encountered something like this? If not, does anyone know of how to delay the start of the entire supervisor utility (not just one specific program)?
For reference, here's what the contents of my .ini
file look like:
[program:test]
command=/bin/gunicorn -b localhost:8000 -w 2 the_app:app
directory=/var/www/test
user=vagrant
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
Again, this works fine after supervisor is reloaded it just doesn't seem to start up correctly (presumably because of some kind of race condition).
For completeness: the addition of the sleep condition caused the .ini
file to look like:
[program:test]
command=bash -c "sleep 10 && exec /bin/gunicorn -b localhost:8000 -w 2 the_app:app"
directory=/var/www/test
user=vagrant
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
Aside from not fixing the problem (lol), this feels dirty so I strongly prefer not to do something like this.
Thanks in advance for any guidance.