What happens to a Django website when you restart

2019-07-31 04:36发布

问题:

In the near future, I'll be deploying a Django/Gunicorn/Nginx website to paying customers. This is my first public website. There will be times when I'll need to bring the site down temporarily for maintenance. I've learned how to configure Nginx to serve up a "503 Site Temporarily Unavailable" page while I'm doing my maintenance and I'm set to inform my customers in advance via an email.

However, if I have a critical problem and need to change a setting or view or something and I need to restart the site without any advance warning by restarting Gunicorn, what will happen from the customer's point of view? Will the site just slow down for a couple of seconds? Will their sessions remain intact or will all sessions be lost? Clearly there will be database problems if any writes are occuring. What things are going to happen and are there any precautions I can take to limit the damage?

回答1:

As long as you don't restart gunicorn by physically cutting the power to the server, the OS will give it the chance to shut down normally. That means that all current views will complete and all open transactions will finish.

Assuming you are using a reverse proxy like nginx in front, and you start gunicorn again immediately, users will be unlikely to notice: the request might take a fraction of a second longer, that's all.

Sessions are stored in files or the database so will be unaffected.