Improving cluster init script
This commit is contained in:
parent
1b0cc0ddb1
commit
d24fb913d1
|
@ -97,8 +97,13 @@ function redisAddReplica()
|
||||||
return ${?}
|
return ${?}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function redisClusterIsOK()
|
||||||
|
{
|
||||||
|
out=$(redis-cli -h ${1} -p ${2} cluster info | grep "cluster_state:ok")
|
||||||
|
return $?
|
||||||
|
}
|
||||||
|
|
||||||
CONF="/etc/redis/cluster.conf"
|
CONF="/etc/redis/cluster.conf"
|
||||||
#CONF=/tmp/cluster.conf
|
|
||||||
|
|
||||||
[[ ! -e ${CONF} ]] && exit 0
|
[[ ! -e ${CONF} ]] && exit 0
|
||||||
|
|
||||||
|
@ -127,6 +132,10 @@ do
|
||||||
MASTERS+=([${name}]=${master})
|
MASTERS+=([${name}]=${master})
|
||||||
done < ${CONF}
|
done < ${CONF}
|
||||||
|
|
||||||
|
# If the cluster is "ok" don't do anything
|
||||||
|
st=$(redisClusterIsOK ${IPADDRS["Leader"]} ${PORTS["Leader"]})
|
||||||
|
#[[ ${?} -eq 0 ]] && exit 0
|
||||||
|
|
||||||
if [[ ${1} == "forget" ]]
|
if [[ ${1} == "forget" ]]
|
||||||
then
|
then
|
||||||
redisClusterForgetAll ${IPADDRS["Leader"]} ${PORTS["Leader"]}
|
redisClusterForgetAll ${IPADDRS["Leader"]} ${PORTS["Leader"]}
|
||||||
|
@ -146,6 +155,20 @@ do
|
||||||
done
|
done
|
||||||
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})
|
nbMaster=$(grep -c ":master" ${CONF})
|
||||||
totalslots=16384
|
totalslots=16384
|
||||||
perNodeSlots=$((totalslots/nbMaster))
|
perNodeSlots=$((totalslots/nbMaster))
|
||||||
|
@ -178,11 +201,13 @@ done
|
||||||
|
|
||||||
for node in ${NAMES[@]}
|
for node in ${NAMES[@]}
|
||||||
do
|
do
|
||||||
[[ ${MASTERS[$node]} == "" ]] && continue
|
[[ ${ROLES[$node]} == "master" ]] && continue
|
||||||
echo -ne " - Replicate ${MASTERS[${node}]} to ${node}"
|
echo -ne " - Replicate ${MASTERS[${node}]} to ${node}\t\t"
|
||||||
redisAddReplica ${IPADDRS[${node}]} ${PORTS[${node}]} ${NIDS[${MASTERS[${node}]}]}
|
redisAddReplica ${IPADDRS[${node}]} ${PORTS[${node}]} ${NIDS[${MASTERS[${node}]}]}
|
||||||
done
|
done
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
|
||||||
echo
|
echo
|
||||||
echo "Cluster status :"
|
echo "Cluster status :"
|
||||||
echo
|
echo
|
||||||
|
|
Loading…
Reference in New Issue