How to gracefully restart django running fcgi behind nginx?

后端 未结 5 458
陌清茗
陌清茗 2020-12-04 14:45

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 with

5条回答
  •  北海茫月
    2020-12-04 15:17

    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).

    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.

提交回复
热议问题