快速部署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
本人用的是CentOS,3个tomcat分别在/opt/apache-tomcat-7.0.65/下的8080/8081/8082子目录下,监听8080/8081/8082端口。运行截图如下:
最后在浏览器里输入http://localhost:8080即可访问。
发布次数多了,操作就比较繁琐了,索性写个脚本一键发布,省时省力^_^。
把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端口。运行截图如下:
最后在浏览器里输入
相关文章推荐
- [转] 快速部署Tomcat项目的Shell脚本
- 快速部署tomcat项目的Shell脚本
- 快速部署Tomcat项目的Shell脚本
- 快速部署tomcat项目的Shell脚本
- Tomcat项目部署shell脚本
- 部署tomcat项目的Shell脚本
- shell 脚本快速部署dhcp服务器!
- Eclipse 中如何快速部署项目到Tomcat下
- 利用ant ,shell进行cvs下tomcat项目一键部署
- 大型项目linux自动化版本发布脚本(shell)之tomcat、nginx服务脚本
- jenkins部署maven项目构建后部署前执行shell脚本
- Eclipse下配置javaweb项目快速部署到tomcat
- 使用shell自动部署tomcat项目
- linux服务器批量部署应用系统shell脚本(Tomcat/jetty)
- shell脚本--部署应用到tomcat并启动tomcat
- Shell脚本,自动化发布tomcat项目【转载】
- shell的tomcat部署脚本
- linux服务器批量部署应用系统shell脚本(Tomcat/jetty)
- 在Tomcat部署项目的脚本
- 使用shell脚本自动部署(发布,重起)maven(java)项目