• while true 死循环判断端口按顺序启动应用


    需求:spring微服务应用启动较慢并且要求一个应用启完才能启第二个应用。

    思路:加了个while true 死循环判断端口启动了才启下一个应用。

    执行方式:/appupgrade/spring_cloud/pay.sh xxx

    #!/bin/bash
    export JAVA_HOME=/usr/java/jdk1.8.0_111
    export PATH=$JAVA_HOME/bin:$PATH
    export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
    BUCKUP_DIR=/fs01/backup/spring-cloud/pay/$(date +%Y%m%d%H%M)
    PAYPRE_DIR=/fs01/spring-cloud/paypre
    APPLY_DIR=/fs01/spring-cloud/pay/acc-apply
    SETTLE_DIR=/fs01/spring-cloud/pay/acc-settle
    FILE=$1
    if [ ! -f ${APPLY_DIR}/${FILE} ];then
    echo "/tmp1/${FILE} This directory does not exist.Please check it!"
    exit 0     
    fi
    echo "开始更新应用,请勿操作等待更新完毕!!"
    ps aux|grep pay-front|grep -v grep |awk '{print $2}'|xargs kill -9
    rm -fr ${PAYPRE_DIR}/app.pid
    sleep 10
    ps aux|grep acc-apply|grep -v grep |awk '{print $2}'|xargs kill -9
    rm -fr ${APPLY_DIR}/app.pid
    sleep 3
    ps aux|grep acc-settle|grep -v grep |awk '{print $2}'|xargs kill -9
    rm -fr ${SETTLE_DIR}/app.pid
    
    /bin/cp /tmp1/$1 ${APPLY_DIR}
    [ -z ${BUCKUP_DIR} ] || /bin/mkdir -p ${BUCKUP_DIR} 
    cd ${APPLY_DIR}
    tar -cf ${BUCKUP_DIR}/apply.tar BOOT-INF/ META-INF/
    cd ${SETTLE_DIR}
    tar -cf ${BUCKUP_DIR}/settle.tar BOOT-INF/ META-INF/
    #更新acc-apply
    cd ${APPLY_DIR}/BOOT-INF/classes/ 
    /bin/mv bootstrap.yml db.properties  paylink.properties ../
    cd ${APPLY_DIR}
    /usr/java/jdk1.8.0_111/bin/jar -xf ${APPLY_DIR}/${FILE}
    cd ${APPLY_DIR}/BOOT-INF/classes/ 
    /bin/mv ../bootstrap.yml ../db.properties ../paylink.properties ./ 
    /bin/chown -R tomcat8:tomcatg /fs01/spring-cloud/pay/acc-apply
    cd /fs01/spring-cloud/pay/acc-apply/ && ./start.sh
    sleep 3
    while true
    do
    	ss -lntp|grep 8761 >>/dev/null
    	if [ $? = 0 ];then
    	echo "acc-apply更新成功!!"
    	break;
    	fi
    done
    #更新acc-settle
    /bin/cp ${APPLY_DIR}/${FILE} ${SETTLE_DIR}
    cd ${SETTLE_DIR}/BOOT-INF/classes/             
    /bin/mv bootstrap.yml db.properties paylink.properties ../
    cd ${SETTLE_DIR}
    /usr/java/jdk1.8.0_111/bin/jar -xf ${SETTLE_DIR}/${FILE}
    cd ${SETTLE_DIR}/BOOT-INF/classes/             
    /bin/mv ../bootstrap.yml ../db.properties ../paylink.properties ./
    /bin/chown -R tomcat8:tomcatg /fs01/spring-cloud/pay/acc-settle
    while true
    do
    	ss -lntp|grep 8761 >>/dev/null
    	if [ $? = 0 ];then
    cd /fs01/spring-cloud/pay/acc-settle/ && ./start.sh
    	break;
    	fi
    done
    while true
    do
    	ss -lntp|grep 8762 >>/dev/null
    	if [ $? = 0 ];then
    	echo "acc-settle更新成功!!"
    cd /fs01/spring-cloud/paypre/ && ./start.sh
    	break;
    	fi
    done
    while true
    do
    	ss -lntp|grep 8763 >>/dev/null
    	if [ $? = 0 ];then
    echo "全部更新完毕,请检查应用日志是否正常!!"
    	break;
    	fi
    done
    mv /tmp1/${FILE} /tmp1/${FILE}_$(date +%Y%m%d%H%M)
    
  • 相关阅读:
    20180813 mysql 手动整理
    20180811 mysql 整理
    20180810 mysql
    20180808 第一阶段项目展示
    20180807 接近第一阶段项目完成 心里话
    20180730 轮播 (加定时器 鼠标移入停止 移除继续轮播 点击小图标换大图片)
    20180730 表格的删除 增加 编辑内容
    10.10日PHP MAC
    10.09日PHP MAC
    数据库类的封装
  • 原文地址:https://www.cnblogs.com/Dev0ps/p/9425016.html
Copyright © 2020-2023  润新知