平滑部署war包到tomcat-deploy.sh

 1 #!/bin/sh
 2 #check war exists
 3 echo "check war exists"
 4 war_file_path=/data/tomcat8/webapps
 5 war_file_name=ROOT.war
 6 
 7 
 8 if [ ! -f "$war_file_path/$war_file_name" ]; then
 9 echo " ------------war not exists----------"
10 exit
11 else
12 echo "-----------exists-------------"
13 fi
14 
15 
16 #check tomcat is running
17 echo "check tomcat is running if stop"
18 app_start_path=/data/tomcat8/bin
19 app_start_name=startup.sh
20 
21 
22 #start tomcat
23 #sh $app_start_path/$app_start_name
24 
25 
26 pid_keyword=tomcat
27 pid=`ps -ef|grep $pid_keyword|grep -v grep|awk '{print $2}'`
28 echo "tomcat pid is:" $pid
29 
30 
31 if [ -n "$pid" ]; then
32 echo "the pid:'$pid' is stopping......"
33 kill -9 $pid
34 fi
35 
36 
37 #backup file
38 echo "backup war file start..."
39 echo "1.delete old backup file"
40 old_war_file_path=/data/tomcat8/webapps
41 old_war_file_name=ROOT.war.bak
42 
43 
44 if [ -f "$old_war_file_path/$old_war_file_name" ]; then
45 echo "war.bak exists so delete it"
46 rm -f $old_war_file_path/$old_war_file_name
47 else
48 echo "war.bak not exists"
49 fi
50 
51 
52 echo "2.backup war file"
53 mv $war_file_path/$war_file_name $old_war_file_path/$old_war_file_name
54 
55 
56 echo "3.copy new war here "
57 new_war_file_path=/var/lib/jenkins/workspace/maven-java-api-test/target
58 new_war_file_name=ROOT.war
59 
60 
61 if [ -f "$new_war_file_path/$new_war_file_name" ]; then
62 cp $new_war_file_path/$new_war_file_name $war_file_path
63 else
64 echo "new war file not esists"
65 exist
66 fi
67 
68 
69 #start tomcat
70 echo "tomcat start"
71 sh $app_start_path/$app_start_name

猜你喜欢

转载自www.cnblogs.com/mignet/p/deploy_war_tomcat_smoothly.html