eole-redis/postservice/91-redis-init

30 lines
530 B
Plaintext
Raw Normal View History

#!/bin/bash
#
# Cluster init !
#
redisTrib="/usr/share/doc/redis-tools/examples/redis-trib.rb"
CONF="/etc/redis/cluster.conf"
if [[ -f ${1} ]]
then
CONF=${1}
fi
if [[ -f "${CONF}" ]]
then
LEADER=$(awk -F ':' '/^leader/ {print $2 ":" $3}' ${CONF})
REPLICA=$(${redisTrib} check ${LEADER} | awk '/additional replica/ {print $1}')
if [[ ${REPLICA} -eq 0 ]]
then
# Create Cluster
yes yes | ${redisTrib} create --replicas 1 $(awk -F ':' '{printf "%s:%s ", $2, $3}' ${CONF})
fi
else
echo "${CONF} is missing"
exit 0
fi