您的位置:首页 > 运维架构 > Tomcat

快速部署tomcat项目的Shell脚本

2017-08-14 16:17 417 查看
为了做集群测试,在每台机器上装了3个tomcat,每次发布项目的时候都要反复敲一些命令,重启tomcat之前先检查tomcat进程有没有停掉,没有还要手动kill该进程。
发布次数多了,操作就比较繁琐了,索性写个脚本一键发布,省时省力^_^。
把deploy.sh和restart.sh分别拷贝到3个tomcat的bin目录下,再用chmod+x给这两个脚本赋上可执行权限。
一键发布命令:./deploy.sh项目war包例如:./deploy.sh/home/test.war
说明:deploy.sh会先清空tomcat下的ROOT目录,再将指定的war包加压至ROOT目录,最后执行restart.sh重启tomcat。
代码如下:

#!/bin/sh
war=$1
bin=$(cd`dirname$0`;pwd)
if[!-n"${war}"];then
echo"***Usage:$0[project.war]"
exit0
fi
if[!-f"${war}"];then
echo"***Error:${war}doesnotexist."
exit0
fi
if[!"${war##*.}"="war"];then
echo"***Error:${war}isnotawarfile."
exit0
fi
echo"Deploy${war##*/}..."
rm-rf${bin}/../webapps/ROOT/&&unzip-qo${war}-d${bin}/../webapps/ROOT/
rm-rf${bin}/../work/Catalina/localhost/
echo"Restarttomcat..."
exec${bin}/restart.sh

#!/bin/sh
bin=$(cd`dirname$0`;pwd)
pid=$(psaux|greptomcat|grep-vgrep|grep-vrestart|grep${bin}|awk'{print$2}')
if[-n"${pid}"];then
echo"Shutdown..."
sh${bin}/shutdown.sh
sleep3
pid=$(psaux|greptomcat|grep-vgrep|grep-vrestart|grep${bin}|awk'{print$2}')
if[-n"${pid}"];then
kill-9${pid}
sleep1
fi
fi
echo"Startup..."
sh${bin}/startup.sh
if["$1"="-v"];then
tail-f${bin}/../logs/catalina.out
fi

本人用的是CentOS,3个tomcat分别在/opt/apache-tomcat-7.0.65/下的8080/8081/8082子目录下,监听8080/8081/8082端口。运行截图如下:







最后在浏览器里输入http://localhost:8080即可访问。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  linux tomcat