1

I have a small .py/Flask application that I can run from the command line as a uWSGI or Gunicorn Server.

Flask's site shows an abbreviated way to simply run a Flask app w/ these types of servers, i.e. esp. if I am using my source in a venv.

Do you know how to run a uWSGI server or Gunicorn server under a venv on boot?

I am basically running some simple source to test out servers for Flask applications and Python3.

1

Do you know how to run a uWSGI server or Gunicorn server under a venv on boot?

You have to create an virtual environment and hardcode the path to uWSGI or Gunicorn.

To start the app on boot, use systemd or supervisor.

An example of using supervisor.

# content from /etc/supervisor/conf.d/microblog.conf

[program:microblog]
command=/home/ubuntu/microblog/venv/bin/gunicorn -b localhost:8000 -w 4 microblog:app
directory=/home/ubuntu/microblog
user=ubuntu
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true

Check Miguel's tutorial about Deployment on Linux for detail.

  • Hello...how do I "hardcode the path" to Gunicorn? – Mala Dies Sep 13 at 1:20
  • @MalaDies Hardcoding means using the absolute path of the executable file. – Simba Sep 14 at 9:14
  • Hello...Thank you for clarifying. @Simba, thank you for taking time out to reply. – Mala Dies Sep 17 at 3:09
0

I found a nifty way via what Simba was describing in Supervisor but w/ systemd .service files.

...

[Unit]
Description=Gunicorn Server for a Flask/Python3 Application

[Service]
WorkingDirectory=/home/debian/virt
ExecStart=/home/debian/virt/env/bin/gunicorn -b 0.0.0.0:5000 -w 4 TheNameOfMyPythonApp:app

[Install]
WantedBy=multi-user.target

So, I just described my directory in the [Service] section and then used ExecStart= to give my Gunicorn location in my environment a start.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.