线上有个网站业务部署在tomcat上,由于频繁上线修改,需要经常启动tomcat。
tomcat服务自带的bin下没有重启脚本,下面分享一例脚本发版和tomcat重启脚本:
1)现将业务代码从svn里下载到本地,首次下载后,后续就使用svn update更新代码即可。
发版脚本:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
[root@redmine ~]
# cd /Data/webroot_svncode/xqsj_app/banshanbandao/bsbd_war/
[root@redmine bsbd_war]
# ls
ROOT.war
[root@redmine xqsj_app]
# cat up_pub_online_banshanbandao.sh
#!/bin/bash
REMOTE_SERVER_IP=
"192.168.1.106 192.168.1.220"
DEST_DIR=
"/Data/app/tomcat-7-banshanbandao/webapps/"
cd
/Data/webroot_svncode/xqsj_app/banshanbandao/bsbd_war/
/usr/bin/svn
update
for
SERVER
in
${REMOTE_SERVER_IP};
do
/usr/bin/ssh
-p22 ${SERVER}
"rm -rf /Data/app/tomcat-7-banshanbandao/webapps/*"
;
/usr/bin/rsync
-av -e
"/usr/bin/ssh -p22"
--
rsync
-path=
"/usr/bin/rsync"
--progress
/Data/webroot_svncode/xqsj_app/banshanbandao/bsbd_war/ROOT
.war ${SERVER}:${DEST_DIR};
sleep
15
/usr/bin/ssh
-p22 ${SERVER}
"/bin/sh /Data/app/tomcat-7-banshanbandao/start.sh"
;
done
|
2)目标机器192.168.1.106
1
2
3
|
[root@web1 ~]
# cd /Data/app/tomcat-7-banshanbandao/webapps/
[root@web1 webapps]
# ls
ROOT ROOT.war
|
tomcat重启脚本(脚本中将dbconfig.properties配置文件事先准备好,以后每次上线后,配置文件保持不变!因为svn里上线代码中的配置都是开发基于本机的配置)
1
2
3
4
5
6
7
8
9
10
11
12
|
[root@web1 webapps]
# cat /Data/app/tomcat-7-banshanbandao/start.sh
#!/bin/bash
cd
/Data/app/tomcat-7-banshanbandao/
kill
-9 `
ps
-ef|
grep
java|
grep
-
v
grep
|
grep
banshanbandao |
awk
-F
" "
'{print $2}'
`
rm
-rf temp/*
rm
-rf work/*
\
cp
-rf dbconfig.properties webapps
/ROOT/WEB-INF/classes/
export
JAVA_HOME=
"/usr/java/jdk1.7.0_79"
/bin/sh
bin
/startup
.sh
|
---------------------------------------------------------------------------------------
上述脚本中的:
kill -9 `ps -ef|grep java|grep -v grep|grep banshanbandao |awk -F" " '{print $2}'`
可以替换为:
ps -ef|grep java|grep -v grep|grep banshanbandao |awk -F" " '{print $2}'|xargs kill -9
---------------------------------------------------------------------------------------
重启tomcat
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
|
[root@web1 ~]
# ps -ef|grep tomcat
root 5759 1 0 Oct31 ? 00:20:09
/usr/java/jdk1
.7.0_79
/bin/java
-Djava.util.logging.config.
file
=
/Data/app/tomcat-7-banshanbandao/conf/logging
.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -server -Xms1024m -Xmx2048m -XX:MaxNewSize=512m -XX:PermSize=2048M -XX:MaxPermSize=2048m -Djava.endorsed.
dirs
=
/Data/app/tomcat-7-banshanbandao/endorsed
-classpath
/Data/app/tomcat-7-banshanbandao/bin/bootstrap
.jar:
/Data/app/tomcat-7-banshanbandao/bin/tomcat-juli
.jar -Dcatalina.base=
/Data/app/tomcat-7-banshanbandao
-Dcatalina.home=
/Data/app/tomcat-7-banshanbandao
-Djava.io.tmpdir=
/Data/app/tomcat-7-banshanbandao/temp
org.apache.catalina.startup.Bootstrap start
root 19549 16881 0 18:06 pts
/0
00:00:00
grep
--color=auto tomcat
[root@web1 ~]
# ps -ef|grep java|grep -v grep|grep banshanbandao |awk -F" " '{print $2}'
5759
[root@web1 ~]
# /bin/sh -x /Data/app/tomcat-7-banshanbandao/start.sh
+
cd
/Data/app/tomcat-7-banshanbandao/
++
ps
-ef
++
grep
java
++
grep
-
v
grep
++
grep
banshanbandao
++
awk
'-F '
'{print $2}'
+
kill
-9 19707
+
rm
-rf
'temp/*'
+
rm
-rf work
/Catalina
+
cp
-rf dbconfig.properties webapps
/ROOT/WEB-INF/classes/
+
export
JAVA_HOME=
/usr/java/jdk1
.7.0_79
+ JAVA_HOME=
/usr/java/jdk1
.7.0_79
+
/bin/sh
bin
/startup
.sh
Using CATALINA_BASE:
/Data/app/tomcat-7-banshanbandao
Using CATALINA_HOME:
/Data/app/tomcat-7-banshanbandao
Using CATALINA_TMPDIR:
/Data/app/tomcat-7-banshanbandao/temp
Using JRE_HOME:
/usr/java/jdk1
.7.0_79
Using CLASSPATH:
/Data/app/tomcat-7-banshanbandao/bin/bootstrap
.jar:
/Data/app/tomcat-7-banshanbandao/bin/tomcat-juli
.jar
Tomcat started.
[root@web1 ~]
# ps -ef|grep tomcat
root 19859 1 99 18:07 pts
/0
00:00:05
/usr/java/jdk1
.7.0_79
/bin/java
-Djava.util.logging.config.
file
=
/Data/app/tomcat-7-banshanbandao/conf/logging
.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -server -Xms1024m -Xmx2048m -XX:MaxNewSize=512m -XX:PermSize=2048M -XX:MaxPermSize=2048m -Djava.endorsed.
dirs
=
/Data/app/tomcat-7-banshanbandao/endorsed
-classpath
/Data/app/tomcat-7-banshanbandao/bin/bootstrap
.jar:
/Data/app/tomcat-7-banshanbandao/bin/tomcat-juli
.jar -Dcatalina.base=
/Data/app/tomcat-7-banshanbandao
-Dcatalina.home=
/Data/app/tomcat-7-banshanbandao
-Djava.io.tmpdir=
/Data/app/tomcat-7-banshanbandao/temp
org.apache.catalina.startup.Bootstrap start
root 19883 16881 0 18:07 pts
/0
00:00:00
grep
--color=auto tomcat
|
***************当你发现自己的才华撑不起野心时,就请安静下来学习吧***************