Tomcat 自动化部署脚本
使用方法: ./autodeploy.sh test
其中autodeploy.sh 为脚本的文件名, test为war的文件名。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
#!/bin/sh
now=`date +%Y%m%d%H%M%S`
echo $now
tomcat_path=
"/home/larry/tomcat8.0.45"
backup_path=
"/home/larry/tomcat8.0.45/backup"
war=$
1
if
[ -e $
1
.war ]; then
echo -e
"\033[34m war achive : '$1.war' exists \033[0m"
else
echo -e
"\033[31m war achive : $1.war not exists \033[0m"
exit
fi
#change color
echo -e
"\033[34m"
#create backup dir
if
[ ! -d
"$backup_path"
]; then
mkdir
"$backup_path"
fi
echo
"tomcat home: $tomcat_path"
echo
"backup path: $backup_path"
echo
'try to stop tomcat...'
pid=`ps aux|grep
"java"
| grep
"$tomcat_path"
| awk
'{printf $2}'
`
if
[ -n $pid ]; then
echo
"tomcat pid: $pid"
;
kill -
9
$pid;
fi
echo
'stop tomcat finished...'
echo
'back old archive...'
echo $tomcat_path/webapps/$war.war
if
[ -f
"$tomcat_path/webapps/$war.war"
]; then
mv -v
"$tomcat_path/webapps/$war.war"
"$backup_path/$1_$now.war"
;
fi
rm -rf $tomcat_path/webapps/$war*
echo
"copy $war.war archive to webapps.."
cp -v
"$war.war"
"$tomcat_path/webapps/"
echo -e
"\033[32m"
echo
'startup tomcat...'
sh $tomcat_path/bin/startup.sh
tail -10f $tomcat_path/logs/catalina.out
|
本文转自Work Hard Work Smart博客园博客,原文链接:http://www.cnblogs.com/linlf03/p/7677135.html,如需转载请自行联系原作者