nginxspawn-fcgi

How to gracefully reload a spawn-fcgi script for nginx


My stack is nginx that runs python web.py fast-cgi scripts using spawn-fcgi. I am using runit to keep the process alive as a Daemon. I am using unix sockets fior the spawed-fcgi.

The below is my runit script called myserver in /etc/sv/myserver with the run file in /etc/sv/myserver/run.

exec spawn-fcgi -n -d /home/ubuntu/Servers/rtbTest/ -s /tmp/nginx9002.socket -u www-data -f /home/ubuntu/Servers/rtbTest/index.py >> /var/log/mylog.sys.log 2>&1

I need to push changes to the sripts to the production servers. I use paramiko to ssh into the box and update the index.py script.

My question is this, how do I gracefully reload the index.py using best practice to update to the new code.

Do I use:

sudo /etc/init.d/nginx reload

Do I restart the the runit script: sudo sv start myserver

Or do I use both:

sudo /etc/init.d/nginx reload
sudo sv start myserver

Or none of the above?


Solution

  • Basically you have to re-start the process that's loaded your Python script. This is spawn-cgi and not nginx itself. nginx only communicates with spawn-cgi via the Unix socket and will happily re-connect if the connection is lost due to a restart of the spawn-cgi process.

    Therefore I'd suggest a simple sudo sv restart myserver. No need to re-start/re-load nginx itself.