1

all. Got a weird problem in running gunicorn with supervisor to serve a flask application. Before I start stating my problem, just want to say that I'm aware of this SO post. Nevertheless, my problem was that I could run gunicorn directly in the foreground to server the app. The problem only occurred when I used supervisor.

Here's the structure of my flask application:

myproject/
|---webapp/
|   |---__init__.py    # create_app function is here
|   |--- ...           # other files in webapp
|---wsgi.py
|---manage.py          
|---venv               # gunicorn is in venv/bin

The wsgi.py file looks like the following

from webapp import create_app

app = create_app()

if __name__ == "__main__":
    app.run()

Sitting in myproject directory, I can launch the app by running

$ venv/bin/gunicorn -w 4 wsgi:app

Then I created a webapp.conf in /etc/supervisor/conf.d/ directory, as follows.

[program:webapp]
directory=/home/<my username>/projects/myproject
command=/home/<my username>/projects/myproject/venv/bin/gunicorn -w 4 wsgi:app
user=<my username>
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=<some path>
stderr_logfile=<some path>

When I reloaded my supervisor, the stdout log file said

usage: gunicorn [OPTIONS] [APP_MODULE] gunicorn: error: No application module specified.

My question is, why do I get an error here if I don't get an error when running gunicorn directly? What's the difference?

By the way, I then tried to use systemd to run the gunicorn following this post, and systemd can launch the gunicorn service normally.

Any idea what I did wrong with supervisor? Thanks very much.

Zheng Liu
  • 292
  • 2
  • 11

0 Answers0