November 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930  

Categories

November 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930  

tomcat monitor script

#!/bin/bash
echo $(date ‘+%Y-%m-%d %H:%M:%S’)
whoami
JAVA_HOME=/opt/java/jdk1.8.0_40
PATH=$JAVA_HOME/bin:$PATH
export PATH JAVA_HOME
port=8086
sn=“tomcat-image-$port
th=“/home/dev/tomcat/$sn
url=“http://you-app-server/”
tomcat=`ps -ef | grep java | grep $sn | grep $port | wc -l`
if [ $tomcat -eq 0 ]
then
echo $sn stoped.
echo starting $sn ……
$th/bin/startup.sh
fi
if [ $tomcat -ge 1 ]
then
tpid=`ps -ef | grep java | grep $sn | grep $port | awk ‘{print $2}’`
echo $sn is running, pid = $tpid
httpStatus=`curl -I $url 2>/dev/null | grep HTTP | awk ‘{print $2}’`
echo $httpStatus
if [[ -z $httpStatus || $httpStatus -ge 500 ]]
then
echo killing $sn ……
kill -9 $tpid
echo starting $sn ……
$th/bin/startup.sh
fi
fi
crontab -e
*/5 * * * * /tomcat-inspector/image.sh >> /logs/image.log 2>&1

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>