Last active
August 20, 2024 13:04
-
-
Save andreadipersio/7804185 to your computer and use it in GitHub Desktop.
How to switch nginx binary at runtime.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# inspired by | |
# Master NGINX - Dimitri Aivaliotis | |
# http://www.amazon.com/Mastering-NGINX-Dimitri-Aivaliotis-ebook/dp/B00B90PJR4 | |
# Chapter 8 - Switching binaries at runtime | |
# We get the pid of the 'to be replaced' nginx master process | |
export nginx_old_pid=`cat /var/run/nginx.pid` | |
# we send an USR2 signal to tell 'to be replaced' process | |
# to start a new master process. | |
# Notice that NGINX will rename the pid file, example: | |
# /var/run/nginx.pid.oldbin | |
kill -USR2 $nginx_old_pid | |
# Sending the 'to be replaced' process a WINCH | |
# cause it to stop handling new requests and phase out | |
# its worker processed once they are done with their current requests. | |
kill -WINCH $nginx_old_pid | |
# Once all workers process of the 'to be replaced' nginx master process | |
# have ended, we can send it a QUIT signal. | |
kill -QUIT $nginx_old_pid | |
# ...or, if we discover problem with the new binary, | |
# we can rollback to the old one by sending a HUP signal | |
kill -HUP $nginx_old_pid |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment