通过进程号或日志文件增长进行服务的重启

#!/bin/sh
serviceStatus(){
 command=`ps aux|grep $2 |grep $3 |grep -v "grep"`
   if [  "$command" == "" ]
   then
	#echo -e "\033[31m$1 not started \033[0m" 
	sh $4
	sleep 5
	sh $5
	echo "$(date "+%Y-%m-%d %H:%M:%S") :restart $1"
   #else
        #echo "$1 is started"
   fi

}

restart10(){
	 sh /opt/canalgroup26/canal10/bin/restart.sh
        sleep 5
        sh /opt/canalclient/bin/restartdb10.sh
	echo "restart db10"
}

restart20(){
        sh /opt/canalgroup26/canal20/bin/restart.sh
        sleep 5
        sh /opt/canalclient/bin/restartdb20.sh
	echo "restart db20"
}


checkdb10(){
echo "checkdb10"
a=`stat -c %Y /opt/canalgroup26/canal10/logs/db10/meta.log`;
b=`date +%s`;
if [ $[ $b - $a ] -gt 600 ];
then restart10;
else :;
fi
}

checkdb20(){
echo "checkdb20"
a=`stat -c %Y /opt/canalgroup26/canal20/logs/db20/meta.log`;
b=`date +%s`;
if [ $[ $b - $a ] -gt 600 ];
then restart20;
else :;
fi
}


while true

do
	echo "check canal status"
	#serviceStatus canalclient-db1 SimpleCanalClientWithSub  db10 /opt/canalgroup26/canal10/bin/restart.sh /opt/canalclient/bin/restartdb10.sh
	#serviceStatus canalclient-db2 SimpleCanalClientWithSub  db20 /opt/canalgroup26/canal20/bin/restart.sh /opt/canalclient/bin/restartdb20.sh
	checkdb10
	checkdb20
	sleep 3600
done

 

阅读更多
换一批

没有更多推荐了,返回首页