Matt Visco
Matt Visco

Reputation: 69

Using supervisor to run a flask app

I am deploying my Flask application on WebFaction. I am using flask-socketio which has lead me to deploying it with a Custom Websocket App (listening on port). Flask-socketio's instructs me to deploy my app by starting the serving with the call socketio.run(app, port= < port_listening_on >) in my main python script. I have installed eventlet on the server so socketio.run should run the app on the eventlet web server.

I can call python < app >.py and all works great – server runs, can view it at the domain, sockets working, etc. My problems start when I attempt to turn this into a long running process. I've been advised to use supervisor which I have installed and configured on my webapp following these instructions: https://community.webfaction.com/questions/18483/how-do-i-install-and-use-supervisord-to-control-long-running-processes

The problem is once I actually add the command for supervisor to run my app it errors with:

Exited too quickly

My log states the above error as well as:

(exit status 1; not expected)

In my supervisor config file I currently have the following program config:

[program:<prog_name>]
command=/usr/bin/python2.7 /home/<user>/webapps/<app_name>/<app>.py
autostart=true
autorestart=true

I have tried a removing and adding settings but it all leads to the same FATAL error.

Upvotes: 4

Views: 9283

Answers (1)

juzten
juzten

Reputation: 154

So this is what part of my supervisor config looks like, I'm using gunicorn to run my flask app.

Also, I'm logging errors to a file from the supervisor config, so if you do that, it might help you see why it's not starting correctly.

[program:gunicorn]
command=/juzten/venv/bin/gunicorn run:app --preload -p rocket.pid -b 0.0.0.0:5000 --access-logfile "-"
directory=/juzten/app-folder-name
user=juzten
autostart=true
autorestart=unexpected
stdout_logfile=/juzten/gunicorn.log
stderr_logfile=/juzten/gunicorn.log

Upvotes: 3

Related Questions