Skip to content

Instantly share code, notes, and snippets.

@huglester
Forked from perusio/upgrade_nginx.sh
Created October 13, 2012 12:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save huglester/3884369 to your computer and use it in GitHub Desktop.
Save huglester/3884369 to your computer and use it in GitHub Desktop.
Post Installation script from debian that upgrades Nginx the proper way, i.e., without downtime
#!/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