Nginxの入れ替えスクリプト
本編 http://d.hatena.ne.jp/m-hiyama/20120309/1331263930 で参照した http://webdevrefinery.com/forums/topic/8348-nginx-update-script/ にるシェルスクリプトを写しておく。
#!/bin/sh VERSION=0.0.1 echo "" echo "########################################################" echo "# nginx updater (c) NSPwn.com #" echo "########################################################" echo "# Author: GreySyntax #" echo "# Version: $VERSION #" echo "########################################################" echo "" PID=`cat /var/run/nginx.pid` echo "Ensure you have ran 'make install clean' before continuing" echo "Are you sure you wish to update nginx? [y/n] ($PID)" read update_ok if [ $update_ok == "y" ] then kill -USR2 $PID echo "Disable old workers? [y/n]" read disable_workers if [ $disable_workers == "y" ] then kill -WINCH $PID echo "Kill old master [1] or restart old workers [2]?" read master_workers if [ $master_workers == "1" ] then echo "Killing old master (this may take some time)" kill -QUIT $PID exit 0 else echo "Restarting old workers" PID_NEW=`cat /var/run/nginx.pid` kill -HUP $PID echo "Shutting down new master process ($PID_NEW)" kill -QUIT $PID_NEW kill -TERM $PID_NEW fi else echo "Restarting old workers" PID_NEW=`cat /var/run/nginx.pid` kill -HUP $PID echo "Shutting down new master process ($PID_NEW)" kill -QUIT $PID_NEW kill -TERM $PID_NEW fi else exit -1 fi
[追記]
これも本編に書いたけど、最近のMakefileで次のターゲットがある。簡単。
upgrade:
/usr/local/nginx/sbin/nginx -tkill -USR2 `cat /usr/local/nginx/logs/nginx.pid`
sleep 1
test -f /usr/local/nginx/logs/nginx.pid.oldbinkill -QUIT `cat /usr/local/nginx/logs/nginx.pid.oldbin`
[/追記]