linux下tomcat部署、启动、关闭的shell脚本

一、直接在tomcat的bin目录下创建脚本

1.部署war包脚本deploy.sh:

 #!/bin/sh

war=$1
bin=$(cd `dirname $0`; pwd)

if [ ! -n "${war}" ]; then
   echo "***Usage: $0 [project.war]"
   exit 0
fi
if [ ! -f "${war}" ]; then
    echo "***Error: ${war} does not exist."
    exit 0
fi
if [ ! "${war##*.}" = "war" ]; then
    echo "***Error: ${war} is not a war file."
    exit 0
fi

echo "Deploy ${war##*/}..."
rm -rf ${bin}/../webapps/ROOT/ && unzip -qo ${war} -d ${bin}/../webapps/ROOT/
rm -rf ${bin}/../work/Catalina/localhost/
echo "Restart tomcat..."
exec ${bin}/restart.sh
 

2.重启脚本 restart.sh :

#!/bin/sh

bin=$(cd `dirname $0`; pwd)
pid=$(ps aux | grep tomcat | grep -v grep | grep -v restart | grep ${bin} | awk '{print $2}')
if [ -n "${pid}" ]; then
   echo "Shutdown..."
   sh ${bin}/shutdown.sh
   sleep 3

    pid=$(ps aux | grep tomcat | grep -v grep | grep -v restart | grep ${bin} | awk '{print $2}')
    if [ -n "${pid}" ]; then
        kill -9 ${pid}
        sleep 1
    fi
fi

echo "Startup..."
sh ${bin}/startup.sh
if [ "$1" = "-v" ]; then
    tail -f ${bin}/../logs/catalina.out
fi
 

二、部署脚本单独存放

例如:把部署脚本放在 /opt/tomBin 目录下

重启脚本的bin只需固定路径即可,例如:bin="/usr/local/tomcat-8.5/bin"

猜你喜欢

转载自blog.csdn.net/RunnerSlowly/article/details/84966697