summaryrefslogtreecommitdiff
path: root/docker/base/create_cluster.sh
blob: 82a79c80da1933dbd92acca2f7fcca5ffcaffc01 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#! /bin/bash
mkdir -p /nodes
touch /nodes/nodemap
for PORT in $(seq 16379 16384); do
  mkdir -p /nodes/$PORT
  if [[ -e /redis.conf ]]; then
    cp /redis.conf /nodes/$PORT/redis.conf
  else
    touch /nodes/$PORT/redis.conf
  fi
  cat << EOF >> /nodes/$PORT/redis.conf
port ${PORT}
cluster-enabled yes
daemonize yes
logfile /redis.log
dir /nodes/$PORT
EOF
  redis-server /nodes/$PORT/redis.conf
  if [ $? -ne 0 ]; then
    echo "Redis failed to start, exiting."
    exit 3
  fi
  echo 127.0.0.1:$PORT >> /nodes/nodemap
done
echo yes | redis-cli --cluster create $(seq -f 127.0.0.1:%g 16379 16384) --cluster-replicas 1
tail -f /redis.log