sh 脚本重启/更新 Tomcat 项目

一、项目文件为一个 jar 包,无须解压

  • 重启 Tomcat 项目
 1 #!/bin/bash
 2 
 3 echo "kill hot-jdt"
 4 kill -9 `ps -ef|grep hot-jdt|grep -v grep|awk '{print $2}'`
 5 sleep 3s
 6 
 7 echo "startup tomcat_admin"
 8 nohup java -jar /usr/local/hot_jdt/hot-jdt.jar > /usr/local/hot_jdt/log/jdt.log 2>&1 &
 9 echo $! > tpid
10 
11 echo "Start Success!"
12 sleep 1s
  • 更新 Tomcat 项目
 1 #!/bin/sh
 2 currenttime=`date +%Y%m%d%H%M%S`
 3 echo "End process hot-jdt"
 4 kill -9 `ps -ef|grep hot-jdt|grep -v grep|awk '{print $2}'`
 5 sleep 2s
 6 
 7 rm -f tpid
 8 
 9 echo "Copy jar"
10 cp /usr/local/upload_jdt/hot-jdt.jar /usr/local/hot_jdt/hot-jdt.jar
11 sleep 2s
12 
13 echo "backgrounp jar"
14 nohup java -jar /usr/local/hot_jdt/hot-jdt.jar > /usr/local/hot_jdt/log/jdt.log 2>&1 &
15 
16 echo $! > tpid
17 
18 echo Start Success!
19 
20 echo "save hot_jdt jar"
21 mv /usr/local/upload_jdt/hot-jdt.jar /usr/local/upload_jdt/bak/hot-jdt_$currenttime.jar
22 
23 echo "update is complete!"
24 sleep 1s

 

二、Tomcat 项目文件为一个 jar 包,需要解压

  • 重启
 1 #!/bin/bash
 2 currenttime=`date +%Y%m%d%H%M%S`
 3 
 4 JAVA_HOME=$JAVA_HOME
 5 PATH=$JAVA_HOME/bin:/bin:$PATH
 6 CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/tools.jar
 7 export JAVA_HOME
 8 export PATH
 9 export CLASSPATH
10 
11 #/usr/local/tomcat/tomcat_jdt/bin/./shutdown.sh
12 #/usr/local/tomcat/tomcat_pot/bin/./shutdown.sh
13 #/usr/local/tomcat/tomcat_bay/bin/./shutdown.sh
14 #/usr/local/tomcat/tomcat_sass/bin/./shutdown.sh
15 
16 kill -9 `ps -ef|grep tomcat_jdt|grep -v grep|awk '{print $2}'`
17 sleep 1s
18 kill -9 `ps -ef|grep tomcat_pot|grep -v grep|awk '{print $2}'`
19 sleep 1s
20 kill -9 `ps -ef|grep tomcat_bay|grep -v grep|awk '{print $2}'`
21 sleep 1s
22 #kill -9 `ps -ef|grep tomcat_sass|grep -v grep|awk '{print $2}'`
23 #sleep 1s
24 
25 sleep 3s
26 
27 sleep 3s
28 
29 /usr/local/tomcat/tomcat_jdt/bin/startup.sh
30 /usr/local/tomcat/tomcat_pot/bin/startup.sh
31 /usr/local/tomcat/tomcat_bay/bin/startup.sh
32 #/usr/local/tomcat/tomcat_sass/bin/startup.sh

 

  • 更新(自动解压 jar 包,不需要通过脚本来解压)
 1 #!/bin/bash
 2 currenttime=`date +%Y%m%d%H%M%S`
 3 
 4 JAVA_HOME=$JAVA_HOME
 5 PATH=$JAVA_HOME/bin:/bin:$PATH
 6 CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/tools.jar
 7 export JAVA_HOME
 8 export PATH
 9 export CLASSPATH
10 
11 
12 #/usr/local/tomcat/tomcat_jdt/bin/./shutdown.sh
13 #/usr/local/tomcat/tomcat_pot/bin/./shutdown.sh
14 #/usr/local/tomcat/tomcat_bay/bin/./shutdown.sh
15 #/usr/local/tomcat/tomcat_sass/bin/./shutdown.sh
16 
17 kill -9 `ps -ef|grep tomcat_jdt|grep -v grep|awk '{print $2}'`
18 sleep 1s
19 kill -9 `ps -ef|grep tomcat_pot|grep -v grep|awk '{print $2}'`
20 sleep 1s
21 kill -9 `ps -ef|grep tomcat_bay|grep -v grep|awk '{print $2}'`
22 sleep 1s
23 #kill -9 `ps -ef|grep tomcat_sass|grep -v grep|awk '{print $2}'`
24 #sleep 1s
25 
26 sleep 3s
27 
28 rm -rf /usr/local/tomcat/tomcat_jdt/webapps/dt*
29 rm -rf /usr/local/tomcat/tomcat_pot/webapps/pt*
30 #rm -rf /usr/local/tomcat/tomcat_sass/webapps/his*
31 rm -rf /usr/local/tomcat/tomcat_bay/webapps/ob*
32 
33 sleep 1s
34 
35 cp /data/www/war/dt/dt.war /usr/local/tomcat/tomcat_jdt/webapps/dt.war
36 cp /data/www/war/dt/dt.war /usr/local/tomcat/tomcat_pot/webapps/pt.war
37 cp /data/www/war/dt/dt.war /usr/local/tomcat/tomcat_bay/webapps/ob.war
38 #cp /data/www/war/dt/dt.war /usr/local/tomcat/tomcat_sass/webapps/his.war
39 
40 sleep 3s
41 
42 /usr/local/tomcat/tomcat_jdt/bin/startup.sh
43 /usr/local/tomcat/tomcat_pot/bin/startup.sh
44 /usr/local/tomcat/tomcat_bay/bin/startup.sh
45 #/usr/local/tomcat/tomcat_sass/bin/startup.sh
46 
47 mv /data/www/war/dt/dt.war /data/www/war/dt/bak/dt$currenttime.war

 

  • 更新(需要通过脚本来解压 jar 包)
 1 #!/bin/bash
 2 currenttime=`date +%Y%m%d%H%M%S`
 3 
 4 echo "kill tomcat_service"
 5 kill -9 `ps -ef|grep tomcat_service|grep -v grep|awk '{print $2}'`
 6 sleep 3s
 7 
 8 echo "Delete tomcat_service files"
 9 rm -rf /usr/local/tomcat_service/webapps/ROOT/*
10 sleep 1s
11 
12 cp /usr/local/upload_war/service_core.war /usr/local/tomcat_service/webapps/ROOT/service_core.war
13 sleep 3s
14 
15 echo "change dir"
16 cd /usr/local/tomcat_service/webapps/ROOT
17 echo "cur dir"
18 $cd pwd
19 
20 jar -xvf service_core.war
21 sleep 1s
22 
23 echo "startup tomcat_service"
24 /usr/local/tomcat_service/bin/startup.sh
25 
26 echo "save tomcat_service war"
27 mv /usr/local/upload_war/service_core.war /usr/local/upload_war/bak/service_core$currenttime.war
28 sleep 1s

 

posted @ 2018-03-24 12:25  Snooper  阅读(1084)  评论(0编辑  收藏  举报