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

 

定时任务:

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

 

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

如此循环;

启动后break跳出循环;

#!/bin/sh#auto restart tomcat5

`
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

相关文章:

  • 2021-10-18
  • 2021-05-08
  • 2021-06-27
  • 2021-11-21
  • 2022-12-23
  • 2021-10-07
猜你喜欢
  • 2021-10-30
  • 2021-12-01
  • 2022-12-23
  • 2021-09-16
  • 2021-07-19
  • 2021-06-10
  • 2021-12-29
相关资源
相似解决方案