Improving cluster init script

This commit is contained in:
Philippe Caseiro 2018-05-15 00:09:46 +02:00
parent d61a45ed24
commit 36b8982e25
1 changed files with 28 additions and 3 deletions

View File

@ -97,8 +97,13 @@ function redisAddReplica()
return ${?}
}
function redisClusterIsOK()
{
out=$(redis-cli -h ${1} -p ${2} cluster info | grep "cluster_state:ok")
return $?
}
CONF="/etc/redis/cluster.conf"
#CONF=/tmp/cluster.conf
[[ ! -e ${CONF} ]] && exit 0
@ -127,6 +132,10 @@ do
MASTERS+=([${name}]=${master})
done < ${CONF}
# If the cluster is "ok" don't do anything
st=$(redisClusterIsOK ${IPADDRS["Leader"]} ${PORTS["Leader"]})
#[[ ${?} -eq 0 ]] && exit 0
if [[ ${1} == "forget" ]]
then
redisClusterForgetAll ${IPADDRS["Leader"]} ${PORTS["Leader"]}
@ -146,6 +155,20 @@ do
done
done
echo " * Waiting for all members ."
for node in ${NAMES[@]}
do
try=3
scmd="awk '/${IPADDRS[$node]}:${PORTS[${node}]}/ {print \$8}'"
while [[ $(redisRun ${IPADDRS['Leader']} ${PORTS['Leader']} "cluster nodes" | eval ${scmd}) != "connected" ]]
do
sleep 1
try=$((try-1))
[[ ${try} -eq 0 ]]
break
done
done
nbMaster=$(grep -c ":master" ${CONF})
totalslots=16384
perNodeSlots=$((totalslots/nbMaster))
@ -178,11 +201,13 @@ done
for node in ${NAMES[@]}
do
[[ ${MASTERS[$node]} == "" ]] && continue
echo -ne " - Replicate ${MASTERS[${node}]} to ${node}"
[[ ${ROLES[$node]} == "master" ]] && continue
echo -ne " - Replicate ${MASTERS[${node}]} to ${node}\t\t"
redisAddReplica ${IPADDRS[${node}]} ${PORTS[${node}]} ${NIDS[${MASTERS[${node}]}]}
done
sleep 2
echo
echo "Cluster status :"
echo