• 快速部署tomcat项目的Shell脚本


    为了做集群测试,在每台机器上装了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。

    代码如下:

    复制代码
     1 #!/bin/sh
     2 
     3 war=$1
     4 bin=$(cd `dirname $0`; pwd)
     5 
     6 if [ ! -n "${war}" ]; then
     7     echo "***Usage: $0 [project.war]"
     8     exit 0
     9 fi
    10 if [ ! -f "${war}" ]; then
    11     echo "***Error: ${war} does not exist."
    12     exit 0
    13 fi
    14 if [ ! "${war##*.}" = "war" ]; then
    15     echo "***Error: ${war} is not a war file."
    16     exit 0
    17 fi
    18 
    19 echo "Deploy ${war##*/}..."
    20 rm -rf ${bin}/../webapps/ROOT/ && unzip -qo ${war} -d ${bin}/../webapps/ROOT/
    21 rm -rf ${bin}/../work/Catalina/localhost/ 22 echo "Restart tomcat..." 23 exec ${bin}/restart.sh
    复制代码

    如需重启tomcat则使用命令:./restart.sh 或 ./restart.sh -v (参数-v表示启动时打印tomcat启动日志)

    说明:restart.sh是用来重启tomcat的,如果tomcat没有启动则直接启动,如果已经启动就先shutdown再启动,如果shutdown之后3s没有停掉tomcat进程,则kill掉原来的进程再启动。

    代码如下:

    复制代码
     1 #!/bin/sh
     2 
     3 bin=$(cd `dirname $0`; pwd)
     4 pid=$(ps aux | grep tomcat | grep -v grep | grep -v restart | grep ${bin} | awk '{print $2}') 
    5 6 if [ -n "${pid}" ]; then 7 echo "Shutdown..." 8 sh ${bin}/shutdown.sh 9 sleep 3 10 11 pid=$(ps aux | grep tomcat | grep -v grep | grep -v restart | grep ${bin} | awk '{print $2}')
    12 if [ -n "${pid}" ]; then 13 kill -9 ${pid} 14 sleep 1 15 fi 16 fi 17 18 echo "Startup..." 19 sh ${bin}/startup.sh 20 if [ "$1" = "-v" ]; then 21 tail -f ${bin}/../logs/catalina.out 22 fi
    复制代码

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

    最后在浏览器里输入 http://localhost:8080 即可访问。

  • 相关阅读:
    REYES is working now!
    New Caching Mechanism
    Minimum Platform Requirements
    Multithreading Problem with Max SDK
    Bezier Triangles and NPatches
    elvish ray 0.5 beta History
    1.md
    Linux时间同步.md
    好久没写东西了
    从java到c# .net的转变(1)
  • 原文地址:https://www.cnblogs.com/cnblog-long/p/9047973.html
Copyright © 2020-2023  润新知