码迷,mamicode.com
首页 > 其他好文 > 详细

无感知的热部署切换

时间:2018-12-14 14:58:16      阅读:225      评论:0      收藏:0      [点我收藏+]

标签:ted   publish   gre   settings   The   files   port   host   新版本   

cd distribution-service-sdk
mvn -s /root/maven/settings-dev.xml -gs /root/maven/settings-dev.xml deploy

#echo "kill 99jar包"
ID=`ps -ef | grep java | grep distribution-service-99 |awk {print $2}`
CURPROT=0
DEFULTPORT=99
for id in $ID 
do 
    CURPROT=99
    #echo "killed pid=$id" 
done

if [ $CURPROT == $DEFULTPORT ];then
   ID88=`ps -ef | grep java | grep distribution-service-88 |awk {print $2}`
  for id in $ID88
  do 
      echo "88与99同时运行中,杀掉88,更新88为最新版本"
     echo "killed pid=$id"
     kill -9 $id      
  done

  echo "删除88jar包 "
  rm -rf /root/newProject/services/distribution-service-88.jar
  rm -rf /root/newProject/services/distribution-service-88.log
  sleep 2
  echo "复制88jar包"
  cp -r /var/lib/jenkins/workspace/distribution-service/distribution-service-publish/target/distribution-service-publish-1.0.0-SNAPSHOT.jar /root/newProject/services
  mv /root/newProject/services/distribution-service-publish-1.0.0-SNAPSHOT.jar /root/newProject/services/distribution-service-88.jar
  echo "执行后台启动88jar包"
  export BUILD_ID=dontKillMe
  nohup java -jar /root/newProject/services/distribution-service-88.jar --spring.profiles.active=test --server.port=88 >> /root/newProject/services/distribution-service-88.log&
  tail -f /root/newProject/services/distribution-service-88.log | sed /Tomcat started on port/ q
  echo "处理nginx,负载到88"
  mv /usr/local/nginx/conf/host_config/distribution-service-99.conf /usr/local/nginx/conf/host_config/distribution-service-99.conf.bak
  mv /usr/local/nginx/conf/host_config/distribution-service-88.conf.bak /usr/local/nginx/conf/host_config/distribution-service-88.conf
  /usr/local/nginx/sbin/nginx -s reload
  for id in $ID 
  do 
      echo "killed pid=$id" 
    kill -9 $id
  done
  exit 0
else
  echo "删除99jar包 "
  rm -rf /root/newProject/services/distribution-service-99.jar
  rm -rf /root/newProject/services/distribution-service-99.log
  sleep 2
  echo "复制99jar包"
  cp -r /var/lib/jenkins/workspace/distribution-service/distribution-service-publish/target/distribution-service-publish-1.0.0-SNAPSHOT.jar /root/newProject/services
  mv /root/newProject/services/distribution-service-publish-1.0.0-SNAPSHOT.jar /root/newProject/services/distribution-service-99.jar
  echo "执行后台启动99jar包"
  export BUILD_ID=dontKillMe
  nohup java -jar /root/newProject/services/distribution-service-99.jar --spring.profiles.active=test --server.port=99 >> /root/newProject/services/distribution-service-99.log&
  tail -f /root/newProject/services/distribution-service-99.log | sed /Tomcat started on port/ q
  echo "处理nginx,负载到99"
  mv /usr/local/nginx/conf/host_config/distribution-service-88.conf /usr/local/nginx/conf/host_config/distribution-service-88.conf.bak
  mv /usr/local/nginx/conf/host_config/distribution-service-99.conf.bak /usr/local/nginx/conf/host_config/distribution-service-99.conf
  /usr/local/nginx/sbin/nginx -s reload
  ID=`ps -ef | grep java | grep distribution-service-88 |awk {print $2}`
  CURPROT=0
  for id in $ID 
  do 
      #CURPROT=88
      echo "killed pid=$id" 
      kill -9 $id
     
  done
sleep 5
exit 0


fi 

 

无感知的热部署切换

标签:ted   publish   gre   settings   The   files   port   host   新版本   

原文地址:https://www.cnblogs.com/zhiji6/p/10119147.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!