2015-01-28 23:26:42 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
2015-01-30 10:41:45 +01:00
|
|
|
# Settings
|
2015-01-28 23:26:42 +01:00
|
|
|
PORT=30000
|
2015-01-30 10:41:45 +01:00
|
|
|
TIMEOUT=2000
|
|
|
|
NODES=6
|
|
|
|
REPLICAS=1
|
|
|
|
|
|
|
|
# You may want to put the above config parameters into config.sh in order to
|
|
|
|
# override the defaults without modifying this script.
|
|
|
|
|
|
|
|
if [ -a config.sh ]
|
|
|
|
then
|
|
|
|
source "config.sh"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Computed vars
|
|
|
|
ENDPORT=$((PORT+NODES))
|
2015-01-28 23:26:42 +01:00
|
|
|
|
|
|
|
if [ "$1" == "start" ]
|
|
|
|
then
|
|
|
|
while [ $((PORT < ENDPORT)) != "0" ]; do
|
|
|
|
PORT=$((PORT+1))
|
|
|
|
echo "Starting $PORT"
|
2015-01-29 13:21:42 +01:00
|
|
|
../../src/redis-server --port $PORT --cluster-enabled yes --cluster-config-file nodes-${PORT}.conf --cluster-node-timeout $TIMEOUT --appendonly yes --appendfilename appendonly-${PORT}.aof --dbfilename dump-${PORT}.rdb --logfile ${PORT}.log --daemonize yes
|
2015-01-28 23:26:42 +01:00
|
|
|
done
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$1" == "create" ]
|
|
|
|
then
|
|
|
|
HOSTS=""
|
|
|
|
while [ $((PORT < ENDPORT)) != "0" ]; do
|
|
|
|
PORT=$((PORT+1))
|
|
|
|
HOSTS="$HOSTS 127.0.0.1:$PORT"
|
|
|
|
done
|
2018-05-07 15:56:12 +02:00
|
|
|
../../src/redis-cli --cluster create $HOSTS --cluster-replicas $REPLICAS
|
2015-01-28 23:26:42 +01:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$1" == "stop" ]
|
|
|
|
then
|
|
|
|
while [ $((PORT < ENDPORT)) != "0" ]; do
|
|
|
|
PORT=$((PORT+1))
|
|
|
|
echo "Stopping $PORT"
|
2015-03-24 09:44:52 +13:00
|
|
|
../../src/redis-cli -p $PORT shutdown nosave
|
2015-01-28 23:26:42 +01:00
|
|
|
done
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2015-01-30 10:41:45 +01:00
|
|
|
if [ "$1" == "watch" ]
|
2015-01-28 23:26:42 +01:00
|
|
|
then
|
2015-01-30 10:41:45 +01:00
|
|
|
PORT=$((PORT+1))
|
|
|
|
while [ 1 ]; do
|
|
|
|
clear
|
|
|
|
date
|
2015-03-24 09:44:52 +13:00
|
|
|
../../src/redis-cli -p $PORT cluster nodes | head -30
|
2015-01-30 10:41:45 +01:00
|
|
|
sleep 1
|
2015-01-28 23:26:42 +01:00
|
|
|
done
|
2015-01-30 10:41:45 +01:00
|
|
|
exit 0
|
|
|
|
fi
|
2015-01-28 23:26:42 +01:00
|
|
|
|
2015-01-30 10:41:45 +01:00
|
|
|
if [ "$1" == "tail" ]
|
|
|
|
then
|
|
|
|
INSTANCE=$2
|
|
|
|
PORT=$((PORT+INSTANCE))
|
|
|
|
tail -f ${PORT}.log
|
|
|
|
exit 0
|
|
|
|
fi
|
2015-01-28 23:26:42 +01:00
|
|
|
|
2015-01-30 10:41:45 +01:00
|
|
|
if [ "$1" == "call" ]
|
|
|
|
then
|
2015-01-28 23:26:42 +01:00
|
|
|
while [ $((PORT < ENDPORT)) != "0" ]; do
|
|
|
|
PORT=$((PORT+1))
|
2015-01-30 10:41:45 +01:00
|
|
|
../../src/redis-cli -p $PORT $2 $3 $4 $5 $6 $7 $8 $9
|
2015-01-28 23:26:42 +01:00
|
|
|
done
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$1" == "clean" ]
|
|
|
|
then
|
|
|
|
rm -rf *.log
|
|
|
|
rm -rf appendonly*.aof
|
|
|
|
rm -rf dump*.rdb
|
|
|
|
rm -rf nodes*.conf
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2017-04-14 10:35:55 +02:00
|
|
|
if [ "$1" == "clean-logs" ]
|
|
|
|
then
|
|
|
|
rm -rf *.log
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2015-01-30 10:41:45 +01:00
|
|
|
echo "Usage: $0 [start|create|stop|watch|tail|clean]"
|
|
|
|
echo "start -- Launch Redis Cluster instances."
|
2018-05-07 15:56:12 +02:00
|
|
|
echo "create -- Create a cluster using redis-cli --cluster create."
|
2015-01-30 10:41:45 +01:00
|
|
|
echo "stop -- Stop Redis Cluster instances."
|
|
|
|
echo "watch -- Show CLUSTER NODES output (first 30 lines) of first node."
|
|
|
|
echo "tail <id> -- Run tail -f of instance at base port + ID."
|
|
|
|
echo "clean -- Remove all instances data, logs, configs."
|
2017-04-14 10:35:55 +02:00
|
|
|
echo "clean-logs -- Remove just instances logs."
|