2023-10-24 03:23:05 -04:00
|
|
|
#!/bin/bash
|
2023-11-15 14:07:51 -05:00
|
|
|
|
2023-11-16 04:11:49 -05:00
|
|
|
# 计划任务,恢复后,可自动拉起keepalived
|
2023-11-16 05:00:53 -05:00
|
|
|
# bash {$SERVER_PATH}/keepalived/scripts/chk_mysql.sh
|
2023-11-16 04:11:49 -05:00
|
|
|
|
2023-10-24 03:23:05 -04:00
|
|
|
counter=$(netstat -na|grep "LISTEN"|grep "3306"|wc -l)
|
2023-11-16 06:30:43 -05:00
|
|
|
data_time=`date +'%Y-%m-%d %H:%M:%S'`
|
2023-11-16 04:19:35 -05:00
|
|
|
|
2023-11-16 06:30:43 -05:00
|
|
|
if [ "${counter}" -eq "0" ]; then
|
2023-11-16 06:34:32 -05:00
|
|
|
echo "${data_time}: start check mysql status, mysql is down, stop keepalive ..."
|
2023-10-24 03:23:05 -04:00
|
|
|
systemctl stop keepalived
|
2023-11-16 06:34:32 -05:00
|
|
|
echo "${data_time}: start check mysql end !!!"
|
2023-11-15 14:07:51 -05:00
|
|
|
fi
|
|
|
|
|
|
2023-11-16 04:19:35 -05:00
|
|
|
|
|
|
|
|
# 恢复后,自动拉起
|
|
|
|
|
# systemctl start keepalived
|
2023-11-16 06:30:43 -05:00
|
|
|
if [ "${counter}" -gt "0" ]; then
|
2023-11-16 06:34:32 -05:00
|
|
|
echo "${data_time}: start check mysql status, mysql is up, start keepalive"
|
2023-11-16 04:19:35 -05:00
|
|
|
|
2023-11-16 06:30:43 -05:00
|
|
|
keepalived_status=`which systemctl && systemctl status keepalived | grep Active | grep inactive`
|
2023-11-16 04:19:35 -05:00
|
|
|
if [ "$keepalived_status" != "" ];then
|
|
|
|
|
systemctl start keepalived
|
|
|
|
|
fi
|
2023-11-16 06:34:32 -05:00
|
|
|
|
|
|
|
|
echo "${data_time}: start check mysql end !!!"
|
2023-11-16 04:19:35 -05:00
|
|
|
fi
|