快速重启tomcat的shell脚本

今天写了一个定时重启tomcat的脚本

 

定时任务:

30 * * * * /bin/bash /root/scripts/auto_restart_tomcat5.sh >> /root/scripts/auto_restart_tomcat5.log 2>&1 &

 

首先进行判断进程是否存在,存在则进行kill,不存在则启动;

如此循环;

启动后break跳出循环;

#!/bin/sh#date 2019-12-11#dan si#auto restart tomcat5

time=`date "+%Y-%m-%d %H:%M:%S"`
echo -e "\n\n==============================="
echo "======$time======"
echo "==============================="
serviceName=tomcat5/conf
pid=`ps -ef | grep $serviceName | grep -v "grep" | awk '{print $2}'`
#kill -9 $pid

for((i=1;i<100;i++));
do
if [ 0 == `ps -ef |grep $serviceName |grep -v "grep" |wc -l` ];then
        echo "$serviceName process is no running!"
        cd /usr/local/tomcat5/
        ./bin/catalina.sh start
        echo "$serviceName process is restart!"
        break
else
        kill -9 $pid
        echo "$serviceName process is running! It was killed again"
        sleep 1
fi
done
posted @ 2019-12-11 17:18  JimmyTang  阅读(866)  评论(0编辑  收藏  举报