How to gracefully restart django running fcgi behind nginx?

后端 未结 5 469
陌清茗
陌清茗 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:41

    I came across this page while looking for a solution for this problem. Everything else failed, so I looked in to the source code :)

    The solution seems to be much simpler. Django fcgi server uses flup, which handles the HUP signal the proper way: it shuts down, gracefully. So all you have to do is to:

    1. send the HUP signal to the fcgi server (the pidfile= argument of runserver will come in handy)

    2. wait a bit (flup allows children processes 10 seconds, so wait a couple more; 15 looks like a good number)

    3. sent the KILL signal to the fcgi server, just in case something blocked it

    4. start the server again

    That's it.

提交回复
热议问题