Restart nginx with zero downtime
Typically, when you upgrade, there is usually a short downtime while the application is restarted.
However, nginx has come up with an elegant way of upgrading without any downtime by using different signals to manage the master and worker processes. The process is outlined on the nginx wiki.
Essentially, the upgrade happens in the following steps:
- Send USR2 signal to the existing master process
- This starts up a new master process and renames the pid file for the old process to nginx.pid.oldbin
- Send QUIT signal to old master process to shut down master & worker processes
Since the default nginx init script does not account for this, I have added an “upgrade” option to the init file.
Note: Recent versions of the development branch now have a -s switch that can be used to pass signals.
UPDATE: Switched the init file to using kill directly instead of start-stop-daemon as it was generating errors.