13

I'm working on developing a web app using Django, hosted on Gunicorn and Nginx. It's getting a bit inconvenient to run "sudo service nginx restart; sudo service gunicorn restart" every time I make a change to the code. Is there a way I can make them restart automatically whenever I make a change, or make it so the changes show up without having to restart?

sbl
  • 231
  • 1
  • 2
  • 3
  • 2
    You don't need to restart nginx, only gunicorn. Usually you would test your changes locally using the `runserver` command (which does restart automatically), and then commit them into a repository. You would only update the code on the server after a bunch of changes, so you don't have to restart the server that often. – knbk Jun 24 '15 at 17:02
  • 1
    Possible duplicate of [gunicorn autoreload on source change](https://stackoverflow.com/questions/12773763/gunicorn-autoreload-on-source-change) – mattm Nov 09 '17 at 17:49

1 Answers1

14

You could add the '--reload' argument, as mentioned in the gunicorn documentation.

Restart workers when code changes.

This setting is intended for development. It will cause workers to be restarted whenever application code changes.

Source: http://docs.gunicorn.org/en/latest/settings.html

Andrew Zick
  • 582
  • 7
  • 23
  • Could you please post a full command which contains this '--reload' argument? – Sirojiddin Komolov Jan 31 '22 at 13:45
  • 1
    @SirojiddinKomolov it might depend on your project? It's been years since I touched gunicorn. Here is one article that walks through serving a flask application. https://www.digitalocean.com/community/tutorials/how-to-serve-flask-applications-with-gunicorn-and-nginx-on-ubuntu-18-04#step-4-configuring-gunicorn Adding the reload arg to the article's example would look like this: `gunicorn --reload --bind 0.0.0.0:5000 wsgi:app` – Andrew Zick Jan 31 '22 at 19:53
  • thanks, I will look at it – Sirojiddin Komolov Feb 01 '22 at 19:29