Created
February 20, 2017 14:42
-
-
Save tarrynn/a1895363c3fc2f57da5fb467c14589f2 to your computer and use it in GitHub Desktop.
graceful nginx restart
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
#!/bin/bash | |
# script to gracefully restart nginx on the hostname | |
# will reside in /home/$DEPLOY_USER/scripts | |
# needs to run as user with sudo permissions | |
set -x | |
sudo nginx -t #test config file | |
if [ $? -ne 0 ] | |
then | |
echo "nginx configtest failed...aborting restart."; | |
exit 1; | |
else | |
sudo kill -s HUP `cat /var/run/nginx.pid` # reload nginx config | |
sudo kill -s USR2 `cat /var/run/nginx.pid` # spawn new master process | |
sleep 3 # wait for new process to take over the pid file | |
sudo kill -s QUIT `cat /var/run/nginx.pid.oldbin` # kill the old master process after it finishes serving in-flight requests | |
echo "nginx restarted gracefully" | |
exit 0; | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment