「shell 」Tomcatを自動起動するスクリプトコード
サンプルコード
#!/bin/bash
if [ ! -f /tmp/down_count ];then
echo “0" > /tmp/down_count
fi
curl -I tomcat-host -o “/tmp/status" >/dev/null 2>&1
code=`awk 'NR==1 {print $2}’ /tmp/status`
if [ “$[code]" -ge 500 ];then
down=`expr $(cat /tmp/down_count) + 1`
echo “$down" > /tmp/down_count
if [ “$down" -gt 3 ];then
if [ ! -f “/tmp/restart_count" ];then
echo “0" > /tmp/restart_count
fi
restart_count=`expr $(cat /tmp/restart_count) + 1`
echo “$restart_count" > /tmp/restart_count
if [ “$restart_count" -le 2 ];then
echo “tomcat down at `date`" >> /tmp/down_info
/etc/init.d/tomcat6 restart
fi
fi
else
echo “0" > /tmp/down_count
echo “0" > /tmp/restart_count
fi