#!/bin/bash
#/usr/local/bin/mycat_status.sh
# This script checks if a mycat server is healthy running on localhost. It will
# return:
#
# "HTTP/1.x 200 OK\r" (if mycat is running smoothly)
#
# "HTTP/1.x 503 Internal Server Error\r" (else)
#存储状态结果数据库
loghost='10.1.1.1'
loguser='root'
logpwd='123456'
host='192.168.1.1' //mycat部署的机器
checktime=`date +%Y%m%d%H%M%S`
logpath='/home/soft/'
echo "--${checktime}----start check-----" >> ${logpath}/mycatinfo.log
mycat=`/home/soft/mycat/bin/mycat status | grep 'not running' | wc -l`
if [ "$mycat" = "0" ];
then
#/bin/echo -e "HTTP/1.1 200 OK\r\n"
echo "200" >> ${logpath}/mycatinfo.log
mysql -h${loghost} -P3306 -u${loguser} -p${logpwd} slaveinfo -e "INSERT INTO mycatinfo(mark,host) VALUES ('200','${host}')"
#写入数据库
else
#/bin/echo -e "HTTP/1.1 503 Service Unavailable\r\n"
echo "500" >> ${logpath}/mycatinfo.log
#写入数据库
mysql -h${loghost} -P3306 -u${loguser} -p${logpwd} slaveinfo -e "INSERT INTO mycatinfo(mark,host) VALUES ('500','${host}')"
/home/soft/mycat/bin/mycat start
if [ $? -eq 0 ]; then
echo "restart success" >> ${logpath}/mycatinfo.log
mysql -h${loghost} -P3306 -u${loguser} -p${logpwd} slaveinfo -e "INSERT INTO mycatinfo(mark,host) VALUES ('restart success','${host}')"
else
echo "restart fail" >> ${logpath}/mycatinfo.log
mysql -h${loghost} -P3306 -u${loguser} -p${logpwd} slaveinfo -e "INSERT INTO mycatinfo(mark,host) VALUES ('restart fail','${host}')"
fi
#写入数据库
fi
mycat健康状态监测脚本
最新推荐文章于 2022-06-15 10:11:33 发布