无感知的热部署切换

Posted zhiji6

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了无感知的热部署切换相关的知识,希望对你有一定的参考价值。

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 

 

以上是关于无感知的热部署切换的主要内容,如果未能解决你的问题,请参考以下文章

spring 的热部署方式

JavaWeb项目的热部署配置

Kafka不停机,如何无感知迁移ZooKeeper集群?

JavaWeb项目的热部署配置

Kafka不停机,如何无感知迁移ZooKeeper集群?

readinessProbe+preStop使应用更新时用户无感知