#!/bin/bash
TRY_PORT=6379
LOCAL_IP=$(/sbin/ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:")
DATE=$(date +%Y%m%d%H%M)
LOGDATE=$(date +%Y%m%d)
cluster_type=$(/ane/redis/bin/redis-cli -c -p $TRY_PORT -h $LOCAL_IP cluster nodes |grep $LOCAL_IP":"$TRY_PORT |awk -F' ' '{print $2,$3}'|awk -F',' '{print $NF}')
rdb_type=$(/ane/redis/bin/redis-cli -c -p $TRY_PORT -h $LOCAL_IP config get save |grep 900 |wc -l)
if [ "$cluster_type" == "master" ]
then
if [ $rdb_type -eq 1 ]
then
/ane/redis/bin/redis-cli -c -p $TRY_PORT -h $LOCAL_IP config set save "" > /dev/null
echo "$DATE $LOCAL_IP":"$TRY_PORT is change to master" >>/ane/scripts/logs/$LOGDATE
exit 1
else
exit 1
fi
elif [ "$cluster_type" == "slave" ]
then
if [ $rdb_type -eq 0 ]
then
/ane/redis/bin/redis-cli -c -p $TRY_PORT -h $LOCAL_IP config set save "900 1 300 10 60 10000" > /dev/null
echo "$DATE $LOCAL_IP":"$TRY_PORT is change to slave" >>/ane/scripts/logs/$LOGDATE
exit 1
else
exit 1
fi
else
echo "$DATE $LOCAL_IP":"$TRY_PORT is down" >>/ane/scripts/logs/$LOGDATE
fi