eole-redis/postservice/90-redis-init

85 lines
1.5 KiB
Plaintext
Raw Normal View History

2018-05-11 17:03:42 +02:00
#!/bin/bash
#
# Cluster init !
#
function redisRun()
{
cmd="redis-cli"
host=$1
shift
port=$1
shift
pass=$1
shift
opt="-h ${host} -p ${port} -a ${pass}"
act=${@}
${cmd} ${opt} ${act}
return ${?}
}
function getNodeID()
{
searchCmd="awk '/${1}/ { print \$1 }'"
redisRun $1 $2 $3 cluster nodes | eval ${searchCmd}
return ${?}
}
#CONF="/etc/redis/cluster.conf"
CONF=/tmp/cluster.conf
[[ ! -e ${CONF} ]] && exit 0
declare -A IPADDRS
declare -A PORTS
declare -A ROLES
declare -A MASTERS
declare -A NIDS
index=0
CLPASS=$(CreoleGet redisMasterPassword)
while read line
do
line=${line//::/:none:}
li=(${line//:/ })
name=${li[0]}
ip=${li[1]}
port=${li[2]}
role=${li[3]}
master=${li[4]}
NAMES+=(${name})
IPADDRS+=([${name}]=${ip})
PORTS+=([${name}]=${port})
ROLES+=([${name}]=${role})
MASTERS+=([${name}]=${master})
done < ${CONF}
echo "Organise Cluster Meeting !"
echo ${NAMES[@]}
for node in ${NAMES[@]}
do
echo $node
[[ ${IPADDRS[$node]} == "127.0.0.1" ]] && continue
act="cluster meet ${IPADDRS[${node}]} ${PORTS[${node}]}"
echo redisRun ${act}
done
echo "Setup Master and pass"
NIDS+=()
for node in ${NAMES[@]}
do
NIDS+=([${node}]=$(getNodeID ${IPADDRS[leader]} ${PORTS[leader]} ${CLPASS} ${PORTS[${node}]}))
done
for node in ${NAMES[@]}
do
[[ ${ROLES[$node]} == "master" ]] && continue
MASTERIP=
echo "redis-cli -h ${IPADDRS[${node}]} -p ${PORTS[${node}]} cluster replicate ${NIDS[${node}]}"
done