線上有個網站業務部署在tomcat上,由於頻繁上線修改,需要經常啟動tomcat。
tomcat服務自帶的bin下沒有重啟指令碼,下面分享一例指令碼發版和tomcat重啟指令碼:
1)現將業務程式碼從svn裡下載到本地,首次下載後,後續就使用svn update更新程式碼即可。
發版指令碼:
[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
[root@web1 ~]# cd /Data/app/tomcat-7-banshanbandao/webapps/ [root@web1 webapps]# ls ROOT ROOT.war
tomcat重啟指令碼(指令碼中將dbconfig.properties配置檔案事先準備好,以後每次上線後,配置檔案保持不變!因為svn裡上線程式碼中的配置都是開發基於本機的配置)
[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
[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