当前位置 博文首页 > 闫玉林的博客:使用Linux定时器crontab实现tomcat服务的可用性检
*/1 * * * * /bin/bash /home/static_protect.sh >> /home/protect_run.log 2>&1
;#!/bin/sh
TOMCAT_PATH=/home/tomcat-static #tomcat位置
TOMCAT_BIN_PATH=$TOMCAT_PATH/bin #启动脚本位置
SERVER_NAME=/home/tomcat-static/bin/tomcat #服务名称,保证唯一
proc_num()
{
num=`ps -ef | grep $SERVER_NAME | grep -v grep | wc -l`
return $num
}
proc_num
number=$?
echo $number
if [ $number -eq 0 ]
then
#开始尝试启动
ps -ef|grep -v grep|grep $SERVER_NAME | grep java |awk '{print "kill -9 "$2}'|sh
sleep 1
set -m
$TOMCAT_BIN_PATH/startup.sh
sleep 50
fi
cs