How do you daemonize a Flask application?


Question

I hav a small application written in Python using Flask. Right now I'm running it under nohup, but I'd like to daemonize it. What's the proper way of doing this?

1
25
6/13/2011 10:22:57 PM

Accepted Answer

There are several ways to deploy a Flask project. Deploying with gunicorn might be the easiest, install gunicorn and then:

gunicorn project:app --daemon

Although you probably want to use supervisor or something of that nature to monitor gunicorn (at the very least use --pid so you can reload/stop gunicorn easily).

32
6/13/2011 10:36:00 PM

If you have supervisor installed already, I think gunicorn would be a little redundant. The following is a flask.ini file that can be dropped in /etc/supervisord.d/ (then "supervisorctl reload" to reload the config and start the process).

command=/opt/flask/env0/bin/python /opt/flask/developer/FlaskWebServer.py
directory=/opt/flask
redirect_stderr=true
startsecs=5
autorestart=true
stdout_logfile=/opt/flask/flask.stdout.log

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon