SHELL_NAME='yqdzcentral.sh'
SHELL_LOG='/app/rsweb/logs/yqdz/shell/logs.txt'
QZ_TOMCAT_HOME='/app/rsweb/apache-tomcat-7.0.73-yqdz-yqdzcentral'
QZ_HREF='http://localhost:8081/yqdzcentral/portal/isRun'
HZ_TOMCAT_HOME='/app/rsweb/apache-tomcat-7.0.73-yqdz-yqdzcentralds'
HZ_HREF='http://localhost:8082/yqdzCentralCore/datasource/portal/isRun'
doWork(){
TOMCAT_HOME=$1
HREF=$2
STARTTOMCAT=$TOMCAT_HOME/bin/startup.sh
proc_id=`ps -ef | grep -i ${TOMCAT_HOME} | grep -v "grep" | awk '{print $2}'`
echo ${proc_id[@]}
if [[ -z $proc_id ]];then
echo ${TOMCAT_HOME} " is not running ! "
echo ${TOMCAT_HOME} " is not running ! " >> $SHELL_LOG
sleep 3
$STARTTOMCAT
echo "Start command executed after 3s sleep ! "
echo "Start command executed after 3s sleep ! " >> $SHELL_LOG
else
echo ${TOMCAT_HOME}" pid is "${proc_id[@]}
echo "Request href is " ${HREF}
proc_result=`curl ${HREF}`
echo "proc_result is " ${proc_result[@]} " !"
if [ "OK" = "$proc_result" ];then
echo ${TOMCAT_HOME} " is normal ! "
else
echo ${TOMCAT_HOME} "is not normal ! "
echo ${TOMCAT_HOME} "is not normal ! " >> $SHELL_LOG
echo "kill the server ..."
for pid in ${proc_id[*]}
do
echo ${pid}
kill -9 ${pid}
if [ $? -eq 0 ];then
echo ${TOMCAT_HOME} "is killed ..."
echo ${TOMCAT_HOME} "is killed ..." >> $SHELL_LOG
echo "startup $TOMCAT_HOME"
echo "startup $TOMCAT_HOME" >> $SHELL_LOG
$STARTTOMCAT
echo "Start command executed !"
echo "Start command executed !" >> $SHELL_LOG
else
echo ${TOMCAT_HOME} " failed ..."
echo ${TOMCAT_HOME} " failed ..." >> $SHELL_LOG
fi
done
fi
fi
}
while true ;do
echo "--------------------------separator--------------------------"
echo "shell log path is " $SHELL_LOG
echo "current time is " $(date +"%Y-%m-%d %H:%M:%S")
echo "current time is " $(date +"%Y-%m-%d %H:%M:%S") >> $SHELL_LOG
doWork $HZ_TOMCAT_HOME $HZ_HREF
echo "*******************************"
doWork $QZ_TOMCAT_HOME $QZ_HREF
echo ""
sleep 600
done