分享一例腳本發版和tomcat重啓腳本

 

線上有個網站業務部署在tomcat上,因爲頻繁上線修改,須要常常啓動tomcat。
tomcat服務自帶的bin下沒有重啓腳本,下面分享一例腳本發版和tomcat重啓腳本:java

1)現將業務代碼從svn裏下載到本地,首次下載後,後續就使用svn update更新代碼便可。
     發版腳本:web

[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.106apache

[root@web1 ~]# cd /Data/app/tomcat-7-banshanbandao/webapps/
[root@web1 webapps]# ls
ROOT  ROOT.war

tomcat重啓腳本(腳本中將dbconfig.properties配置文件事先準備好,之後每次上線後,配置文件保持不變!由於svn裏上線代碼中的配置都是開發基於本機的配置bootstrap

[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

重啓tomcatbash

[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
相關文章
相關標籤/搜索