自动部署war包脚本
war 包所在路径为:/home/wars/ROOT.war
tomcat 所在路径为:
①:/home/search-3
②:/home/search-4
部署单个war到一个tomcat中
#!/bin/sh TOMCAT='/home/search-3' echo "deploy ROOT.war" #ps 显示进程,grep筛选进程,awk是一个强大的文本分析工具筛选出tomcat8的pid pidList=`ps -ef|grep search-3|grep -v 'grep'|awk '{print $2'}` echo "${pidList}" if [ "$pidList" = "" ]; then echo "no tomcat pid alive" else #kill掉tomcat的进程 echo "tomcat id list :$pidList" kill -9 $pidList echo "kill $pidList" fi echo "begin del old ROOT.war" #移除原来的war包 rm -rf $TOMCAT/webapps/ROOT.war && rm -rf $TOMCAT/webapps/ROOT echo "copy to tomcat webApps " #拷贝war包到tomcat启动目录下 cp /home/wars/ROOT.war $TOMCAT/webapps/ #启动tomat echo "start tomcat ! Go Go Go!!!" cd $TOMCAT"/bin" ./startup.sh
部署同一个war到一两个不同的tomcat中,两个以上,直接修改数组即可
#!/bin/sh tomcats=('/search-3' '/search-4') echo "deploy ROOT.war" for tomcat in ${tomcats[@]} do pidList=`ps -ef|grep $tomcat|grep -v 'grep'|awk '{print $2'}` echo "${pidList}" if [ "$pidList" = "" ]; then echo "no tomcat pid alive" else echo "tomcat id list :$pidList" kill -9 $pidList echo "kill $pidList" fi echo "begin del old ROOT.war" rm -rf '/home'$tomcat/webapps/ROOT.war && rm -rf '/home'$tomcat/webapps/ROOT echo "copy to tomcat webApps " cp /home/wars/ROOT.war '/home'$tomcat/webapps/ echo "start tomcat ! Go Go Go!!!" cd '/home'$tomcat"/bin" ./startup.sh done