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.

Mala Dies
  • 13
  • 3

2 Answers2

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.

Simba
  • 1,632
  • 12
  • 14
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.

Mala Dies
  • 13
  • 3