What is the correct way to leave gunicorn running?

45,305

Solution 1

I'd look into something like Supervisor.

Very useful tutorial can be found here https://www.codingforentrepreneurs.com/blog/hello-linux-setup-gunicorn-and-supervisor/

Solution 2

Use --daemon option while running gunicorn. Example:

gunicorn grand56.wsgi:application --name grand56 --workers 3 --user=root --group=root --bind=127.0.0.1:1001 --daemon

Solution 3

use --daemon to the binding command of gunicorn. ex:

gunicorn --bind 0.0.0.0:8001 your_project.wsgi --daemon

Solution 4

The key thing to note is that when you start the process from the command line it is a child of your terminal process (i. e. a child of bash). When you log out of the server your bash process is terminated - as are all its children.

You'll want to use whatever system you have in place to manage nginx also manage gunicorn (anything from init.d or Upstart scripts to specialized application process monitors like Monit, Supervisor, Bluepill, Foreman, etc.)

Solution 5

Try this:

nohup gunicorn app:app &
Share:
45,305
nickponline
Author by

nickponline

Updated on July 08, 2022

Comments

  • nickponline
    nickponline almost 2 years

    I want to make a Flask+Nginx+Gunicorn deployment. I have Nginx setup and running and I run gunicorn as described in the docs:

    gunicorn app:app
    

    But when I logout of the server the gunicorn process exits? What is the correct way to make sure it stay running for Nginx to connect to, and restarts if it crashes?