Created
October 13, 2012 11:41
-
-
Save perusio/3884272 to your computer and use it in GitHub Desktop.
Post Installation script from debian that upgrades Nginx the proper way, i.e., without downtime
This file contains hidden or 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/sh | |
set -e | |
case "$1" in | |
configure) | |
if [ -z $2 ] && [ ! -e /etc/nginx/sites-enabled/default ] ; | |
then | |
ln -s /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default | |
fi | |
;; | |
abort-upgrade|abort-remove|abort-deconfigure) | |
;; | |
*) | |
echo "postinst called with unknown argument \`$1'" >&2 | |
exit 1 | |
;; | |
esac | |
if [ -x /etc/init.d/nginx ] | |
then | |
if [ -f /var/run/nginx.pid ] && pidof /usr/sbin/nginx >/dev/null | |
then | |
echo "Trying a soft restart" | |
NGX_PID=`cat /var/run/nginx.pid` | |
if kill -s USR2 $NGX_PID 2>/dev/null | |
then | |
echo "PID IS RIGHT" | |
while [ ! -f /var/run/nginx.pid.oldbin ] | |
do | |
echo "WAITING" | |
cnt=`expr $cnt + 1` | |
if [ $cnt -gt 10 ] | |
then | |
echo "Nginx 'soft' update failed, doing restart" | |
kill -s KILL $NGX_PID | |
invoke-rc.d nginx start | |
exit 0 | |
fi | |
sleep 1 | |
done | |
echo "QUIT" | |
NGX_OLD_PID=`cat /var/run/nginx.pid.oldbin` | |
kill -s QUIT $NGX_OLD_PID | |
fi | |
fi | |
fi | |
#DEBHELPER# | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment