Simple Linux Panel
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mdserver-web/plugins/keepalived/scripts/chk_mysql.sh

28 lines
834 B

2 years ago
#!/bin/bash
2 years ago
2 years ago
# 计划任务,恢复后,可自动拉起keepalived
2 years ago
# bash {$SERVER_PATH}/keepalived/scripts/chk_mysql.sh
2 years ago
2 years ago
counter=$(netstat -na|grep "LISTEN"|grep "3306"|wc -l)
2 years ago
data_time=`date +'%Y-%m-%d %H:%M:%S'`
2 years ago
if [ "${counter}" -eq "0" ]; then
echo "${data_time}: start check mysql status, mysql is down, stop keepalive ..."
2 years ago
systemctl stop keepalived
echo "${data_time}: start check mysql end !!!"
2 years ago
fi
# 恢复后,自动拉起
# systemctl start keepalived
2 years ago
if [ "${counter}" -gt "0" ]; then
echo "${data_time}: start check mysql status, mysql is up, start keepalive"
2 years ago
keepalived_status=`which systemctl && systemctl status keepalived | grep Active | grep inactive`
if [ "$keepalived_status" != "" ];then
systemctl start keepalived
fi
echo "${data_time}: start check mysql end !!!"
fi