#!/usr/bin/env bash
vip="192.168.1.20/24"
key="5"
stop_vip="/sbin/ifconfig em2:$key down"
start_vip="/sbin/ifconfig em2:$key $vip"
pingtest=$(fping 192.168.1.20 2> /dev/null | grep -c alive)
while true
do
if [ $pingtest -ne 1 ];then
echo "redis master is down"
$start_vip
exit 1
else
conne=$(/usr/local/redis-3.0.0/src/redis-cli -h 192.168.1.20 ping 2>/dev/null | grep -c PONG)
if [ $conne -ne 1 ];then
echo "redis master is unreachable"
pingtest2=$(fping 192.168.1.20 2> /dev/null | grep -c alive)
[ $pingtest2 -eq 1 ] && ssh [email protected] $stop_vip
$start_vip
exit 2
fi
fi
sleep 2
echo "======================"
done