Nginx Zero downtime upgrade

A nice feature in Nginx is the ability to upgrade with zero downtime. The idea is to load new processes parallel with the old ones, have them start serving requests then phase out the old processes. The procedure is careful and you have the option of retracting if anything goes wrong:
  1. Install the new binaries. If you do this with dpkg, remember that the postinst script will probably try this automatically or restart nginx. Either edit the package or don't use it unless you're sure you know what the postinst script does
  2. Send the USR2 signal to the master process E.G. kill -s USR2 $(cat /var/run/nginx.pid)
  3. Check that Nginx has spawned new master process and children ps -ef|grep nginx, also, Nginx should move the old pid file to /var/run/nginx.pid.oldbin
  4. Phase out the old worker processes kill -s WINCH $(cat /var/run/nginx.pid.oldbin), the old workers will gracefully close
  5. Verify everything is ok.
  6. If you want to go back to the old binary, send the HUP signal to the old master process, then QUIT to the new master process, and finally TERM just to make sure. kill -s HUP $(cat /var/run/nginx.pid.oldbin) && kill -s QUIT $(cat /var/run/nginx.pid) && sleep 10 && kill -s TERM $(cat /var/run/nginx.pid)
  7. If you're happy with the upgrade, send the old master process to it's final rest kill -s QUIT $(cat /var/run/nginx.pid.oldbin)

Reference

-- AvishaiIshShalom - 23 Jul 2010
Topic revision: r1 - 23 Jul 2010 - 08:13:03 - AvishaiIshShalom
 

This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Foswiki? Send feedback