问题描述
我正在使用fcgi(通过使用manage.py runfcgi命令)连接的nginx后面的django实例。由于代码被加载到内存中,我无法重新加载新的代码而不会杀死并重新启动django fcgi进程,从而中断了实时网站。重新启动本身非常快。但是,通过杀死fcgi进程,一些用户的操作将被中断,这是不好的。
我想知道如何重新加载新的代码,而不会造成任何中断。我们将非常感谢您的建议!
I'm running a django instance behind nginx connected using fcgi (by using the manage.py runfcgi command). Since the code is loaded into memory I can't reload new code without killing and restarting the django fcgi processes, thus interrupting the live website. The restarting itself is very fast. But by killing the fcgi processes first some users' actions will get interrupted which is not good.I'm wondering how can I reload new code without ever causing any interruption. Advices will be highly appreciated!
推荐答案
我将在新端口上启动一个新的fcgi进程,将nginx配置更改为使用新端口,具有nginx重新加载配置(本身是优雅的),然后最终停止旧进程(可以使用netstat来查找最后一次连接到旧端口是否关闭)。
I would start a new fcgi process on a new port, change the nginx configuration to use the new port, have nginx reload configuration (which in itself is graceful), then eventually stop the old process (you can use netstat to find out when the last connection to the old port is closed).
或者,您可以将fcgi实现更改为fork一个新进程,关闭fcgi服务器套接字中的所有套接字,关闭父节点中的fcgi服务器套接字,执行一个新的django进程使其使用fcgi服务器套接字),并在所有fcgi连接关闭后终止父进程。 IOW,为runfcgi实现优雅的重启。
Alternatively, you can change the fcgi implementation to fork a new process, close all sockets in the child except for the fcgi server socket, close the fcgi server socket in parent, exec a new django process in the child (making it use the fcgi server socket), and terminate the parent process once all fcgi connections are closed. IOW, implement graceful restart for runfcgi.
这篇关于如何优雅地重新启动django在nginx之后运行fcgi?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!