nginx平滑自动升级脚本

#!/bin/bash

Update_nginx()
{
	wget http://nginx.org/download/nginx-1.16.1.tar.gz
	tar -zxf nginx-1.16.1.tar.gz
	cd nginx-1.16.1
	./configure --user=nobody --group=nobody \
	--prefix=/usr/local/nginx \
    	--with-http_stub_status_module \
    	--with-http_ssl_module
	make
	mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx_bak_${CDATE}
	cp objs/nginx /usr/local/nginx/sbin/nginx
	echo "查看nginx版本"
	/usr/local/nginx/sbin/nginx -t
	#kill -USR2 `cat /usr/local/nginx/logs/nginx.pid`
	kill -USR2 `ps aux | grep "nginx: master process" | grep -v grep | awk '{print $2}'`
	sleep 3
	test -f /usr/local/nginx/logs/nginx.pid.oldbin && echo OK!
	read -p "上面是否输出旧版本的pid变成oldbin和OK信息,输入yes进行下一步:" canshu
	while [ ${canshu} != "yes" || ${canshu} != "YES" || ${canshu} != "y" || ${canshu} != "Y" ];
	do
		test -f /usr/local/nginx/logs/nginx.pid.oldbin && echo OK!
		read -p "上面是否输出旧版本的pid变成oldbin和OK信息,输入yes进行下一步:" canshu	
	done
        kill -WINCH `cat /usr/local/nginx/logs/nginx.pid.oldbin`
        kill -HUP `cat /usr/local/nginx/logs/nginx.pid.oldbin`
        kill -QUIT `cat /usr/local/nginx/logs/nginx.pid.oldbin`
        echo "查看升级后的nginx版本"
        /usr/local/nginx/sbin/nginx -V
	rm -rf nginx-1.16.1
}

Update_nginx_zhidong()
{
        wget http://nginx.org/download/nginx-1.16.1.tar.gz
        tar -zxf nginx-1.16.1.tar.gz
        cd nginx-1.16.1
        ./configure --user=nobody --group=nobody \
        --prefix=/usr/local/nginx \
        --with-http_stub_status_module \
        --with-http_ssl_module
        make
        mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx_bak_${CDATE}
        cp objs/nginx /usr/local/nginx/sbin/nginx
        echo "查看nginx版本"
        /usr/local/nginx/sbin/nginx -t
	make upgrade
	if [[ $? != 0 ]];then
		echo "升级失败,请手动升级"
	else
		/usr/local/nginx/sbin/nginx -V
		rm -rf nginx-1.16.1
	fi
}

cd `dirname $0`
action=${1}
CDATE=`date '+%Y-%m-%d'`
#Update_nginx
if [[ ${action} == "update_nginx" ]];then
	Update_nginx_zhidong
else
	echo "$0 update_nginx"
	exit
fi

 

你可能感兴趣的:(nginx,linux,shell)