Tomcat 重启脚本 restart.sh

1.介绍

    Tomcat 本身提供了 startup.sh(启动)shutdown.sh(关闭)脚本,我们在部署中有时候会出现死进程形象。restart.sh解决该问题. 

2.脚本

   注意:将该脚本 放入到tomcat目录/bin目录下统一,给予chmod +x 权限

restart.sh

#!/bin/sh
TOMCAT_PATH=`dirname $(cd "$(dirname "$0")"; pwd)`

echo "TOMCAT_PATH is $TOMCAT_PATH"

PID=`ps aux | grep ${PWD##*/} | grep java | awk '{print $2}'`

if [ -n "$PID" ]; then
        echo "Will kill tomcat: $PID"
        sh "$TOMCAT_PATH/bin/shutdown.sh"
        sleep 6
else echo "No Tomcat Process $PID"
fi

PID=`ps aux | grep ${PWD##*/} | grep java | awk '{print $2}'`
echo $PID
#while [ -n "$PID" ]; do
     kill  $PID && sleep 1
#     echo "Try to kill $PID"
#done


sh "$TOMCAT_PATH/bin/startup.sh"
sleep 3

PID=`ps aux | grep ${PWD##*/} | grep java | awk '{print $2}'`
if [ -n "$PID" ]; then
        echo "Restart tomcat successfully!"
else
        echo "Fail to startup tomcat"
        exit 1
fi



你可能感兴趣的:(Tomcat 重启脚本 restart.sh)