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

tomcat 自动上线脚本

时间:2018-08-03 16:20:22      阅读:194      评论:0      收藏:0      [点我收藏+]

标签:nba   app   timeout   ash   nec   done   The   running   sim   

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[33m mkdir $artemis_bak           [ ok ]   \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[33m Artemis is already running, and his pid is: [ $ID ]   \033[0m"

else

        echo -e "\033[5;33m Artemis run                             [ Failed ]  \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


tomcat 自动上线脚本

标签:nba   app   timeout   ash   nec   done   The   running   sim   

原文地址:http://blog.51cto.com/amunlinux/2154128

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