赞
踩
#通知负载均衡haproxy器将我下线,负载均衡有3个管理端口,分别管理3个内核进程。
curl -u admin:123456 -d "s=app_198_1&action=drain&b=#12" -o /dev/null "http://10.0.0.1:19100/admin_status"
curl -u admin:123456 -d "s=app_198_1&action=drain&b=#12" -o /dev/null "http://10.0.0.1:19101/admin_status"
curl -u admin:123456 -d "s=app_198_1&action=drain&b=#12" -o /dev/null "http://10.0.0.1:19102/admin_status"
#等待前端接口超时时间过去
echo "等待负载均衡排干请求 ......"
sleep 15s
#给JVM发送shutdown指令,触发优雅停机
SERVERPID1=`netstat -ntlp | grep 15000 | awk -F [/] '{print $1}'|awk -F ' ' '{print $NF}'`
if [ "$SERVERPID1" != "" ]
then kill $SERVERPID1
fi
#等待优雅停机结束,发现端口占用消失。
waitShutDownTimes=0
shutDownTimeOut=10
while true
do
SERVERPID1=`netstat -ntlp | grep 15000 | awk -F [/] '{print $1}'|awk -F ' ' '{print $NF}'`
if [ "$SERVERPID1" = "" ]
then
echo "端口占用进程消失....."
break
else
if [ $waitShutDownTimes -gt $shutDownTimeOut ]
then
kill -9 $SERVERPID1
break
fi
fi
echo "端口依然占用,等待ing......"
sleep 1s
waitShutDownTimes=$(($waitShutDownTimes+1))
if [ $waitShutDownTimes -gt $shutDownTimeOut ]
then
echo "等待端口占用超时,未能正常结束进程,5s后将强制关闭进程,如不需要强制关闭,请Crtl+C中断脚本执行"
sleep 5s
fi
done
#运行同步程序命令
echo "开始进行程序同步。。。"
rsync -avzhP --delete ccsync@10.0.0.2::app1 /apps/app1/app-service/
echo "同步程序完毕...."
sleep 1s
#启动应用
nohup /usr/lib/jvm/java-1.8.0/bin/java -server -Xms4g -Xmx4g -Xmn3g -XX:SurvivorRatio=8 -Xss256K -Djava.awt.headless=true -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=256m -XX:CompressedClassSpaceSize=128m -XX:ReservedCodeCacheSize=128m -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:+UseAdaptiveSizePolicy -XX:+CMSClassUnloadingEnabled -XX:+UseCMSCompactAtFullCollection -XX:CMSFullGCsBeforeCompaction=10 -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=75 -XX:CMSMaxAbortablePrecleanTime=5 -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/apps/dumpfiles/app1 -jar /apps/app1/app-service/app1-0.0.1-SNAPSHOT.jar > /apps/logs/app1.catalog 2>&1 &
#检测应用日志,是否启动完毕。
startUpCheckTimes=0
startUpCheckTimeOut=30
while true
do
startUpFinished=`grep 'SpringBootApplication1:::main::::::started succ...::::' /apps/logs/app1.catalog`
if [ "$startUpFinished" != "" ]
then
echo "检测到应用已经重启完毕....$startUpFinished"
break
else
echo "未检测到启动成功标志,等待ing"
sleep 2s
startUpCheckTimes=$(($startUpCheckTimes+1))
if [ $startUpCheckTimes -gt $startUpCheckTimeOut ]
then
echo "检测应用启动超时.....检测停止,接下来将检测应用的接口是否正常。。。"
break
fi
fi
done
sleep 2s
#检测应用本身状态
#check app
appStatus=`curl -o /dev/null -s -m 10 --connect-timeout 10 -w %{http_code} http://10.0.0.3:15000/service/check`
if [ "$appStatus" = "200" ]
then
echo "应用状态正常..."
#check db
dbStatus=`curl -o /dev/null -s -m 10 --connect-timeout 10 -w %{http_code} http://10.0.0.3:15000/service/check?db=db1`
if [ "$dbStatus" = "200" ]
then
echo "DB状态正常..."
#通知上线
sleep 1s
curl -u admin:123456 -d "s=app_198_1&action=ready&b=#12" -o /dev/null "http://10.0.0.1:19100/admin_status"
curl -u admin:123456 -d "s=app_198_1&action=ready&b=#12" -o /dev/null "http://10.0.0.1:19101/admin_status"
curl -u admin:123456 -d "s=app_198_1&action=ready&b=#12" -o /dev/null "http://10.0.0.1:19102/admin_status"
echo "通知负载均衡上线成功....."
else
echo "DB状态异常..."
fi
else
echo "应用状态异常..."
fi
tail -f /apps/logs/app1.catalog
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。