nawawa001 发表于 2018-12-3 09:14:34

tomcat 自动上线脚本

  tomcat 自动上线脚本,看懂了你就会用
  #!/bin/bash
  #
  #This is a live, deployment automation script
  #1.backup,
  #2.download package,
  #3.issue
  #Creation time:2018/7/13
  #Admin: Rui Xu
  #
  #online time
  shi=`date +%H:%M:%S:%N | awk -F':' '{print $1}'`
  fen=`date +%H:%M:%S:%N | awk -F':' '{print $2}'`
  miao=`date +%H:%M:%S:%N | awk -F':' '{print $3}'`
  haomiao=`date +%H:%M:%S:%N | awk -F':' '{print $4}'`
  ####backup last time application package
  artemis_bak="/app/tmp/backup-package/artemis_$(date +%Y-%m-%d)"
  if [ ! -d $artemis_bak ]
  then
  mkdir -p $artemis_bak
  fi
  echo -e "\033   \033[0m"
  /bin/mv/app/tmp/artemis.war $artemis_bak/"artemis-"$(date +%H:%M:%S)".bak.war"
  echo 'Current backup package name :'
  /bin/ls -l "$artemis_bak"/artemis*| tail -n1|awk -F'/' '{print "/"$2"/"$3"/"$4"/"$5"/"$6}'
  ####download this time artemis package
  /bin/scp root@10.89.242.15:/data/ftp/xiaojushanbao/jenkins/artemis/artemis* /app/
  flag=`echo $?`
  if [ $flag != "0" ]; then
  echo "ERROR:download package artemis failed"
  break
  exit
  else
  /bin/mv/app/artemis* /app/tmp/artemis.war
  ####Use this package;server artemis stop,start
  #service artemis stop
  ps -aux | grep tomcat | grep bootstrap | grep -v grep | awk '{print $2}' | while read pid
  do
  echo "tomcat is running, to kill bootstrap pid=$pid"
  kill -9 $pid
  echo "kill result:[ $? ]   0=ok"
  done
  sleep 1
  rm -rf /app/apps/artemis/tomcat/webapps/*
  rm -rf /app/apps/artemis/tomcat/work
  rm -rf /app/apps/artemis/tomcat/temp/*
  mkdir /app/apps/artemis/tomcat/webapps/artemis
  cp /app/tmp/artemis.war /app/apps/artemis/tomcat/webapps/artemis
  cd /app/apps/artemis/tomcat/webapps/artemis
  unzip artemis.war&> /dev/null
  cd /
  rm -rf /app/apps/artemis/tomcat/webapps/artemis/artemis.war
  rm -rf /app/apps/artemis/tomcat/webapps/artemis/WEB-INF/lib/mysql-connector-java-5.1.37.jar
  yes | cp -f /app/tmp/logback-spring.xml /app/apps/artemis/tomcat/webapps/artemis/WEB-INF/classes/
  yes | cp -f /app/tmp/logback-spring.xml /app/apps/artemis/tomcat/webapps/artemis/WEB-INF/classes/config/log/logback-didiprod.xml
  yes | cp -f /app/tmp/font/simsun.ttc /app/apps/artemis/tomcat/webapps/artemis/WEB-INF/classes/font
  sleep 1
  echo 'Deployment is complete Is starting Artemis ...'
  service artemis start&> /dev/null
  sleep 8
  ID=`ps -aux | grep tomcat | grep bootstrap | grep -v grep | awk '{print $2}'|tail -n1`
  if [ ! "$ID" = "" ]
  then
  echo -e "\033   \033[0m"
  else
  echo -e "\033\033[0m"
  fi
  #online end time
  shi1=`date +%H:%M:%S:%N | awk -F':' '{print $1}'`
  fen2=`date +%H:%M:%S:%N | awk -F':' '{print $2}'`
  miao3=`date +%H:%M:%S:%N | awk -F':' '{print $3}'`
  haomiao4=`date +%H:%M:%S:%N | awk -F':' '{print $4}'`
  H=`expr $shi1 - $shi`
  F=`expr $fen2 - $fen`
  M=`expr $miao3 - $miao`
  HM=`expr $haomiao4 - $haomiao`
  echo "Elapsed time :"$H" h "$F" m "$M" s "$HM" ms"
  sleep 2
  echo '======================================================================='
  echo "+Real-time logging is coming /home/mnt/app/logs/artemis/artemis.log +"
  echo '======================================================================='
  sleep 5
  timeout 50 tail -f /home/mnt/app/logs/artemis/artemis.log
  fi
  #END



页: [1]
查看完整版本: tomcat 自动上线脚本