Debian Codegraph @

ccheck/create-cluster

raw
1 #!/bin/bash
2
3 # Copyright (c) 2006-2015, Salvatore Sanfilippo
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
7 #
8 # * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
9 # * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
10 # disclaimer in the documentation and/or other materials provided with the distribution.
11 # * Neither the name of Redis nor the names of its contributors may be used to endorse or promote products derived
12 # from this software without specific prior written permission.
13 #
14 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
15 # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
16 # AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
20 # IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
21 # OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
23 # Settings
24 PORT=30000
25 TIMEOUT=2000
26 NODES=6
27 REPLICAS=1
28
29 # You may want to put the above config parameters into config.sh in order to
30 # override the defaults without modifying this script.
31
32 if [ -a config.sh ]
33 then
34 source "config.sh"
35 fi
36
37 # Computed vars
38 ENDPORT=$((PORT+NODES))
39
40 if [ "$1" == "start" ]
41 then
42 while [ $((PORT < ENDPORT)) != "0" ]; do
43 PORT=$((PORT+1))
44 echo "Starting $PORT"
45 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
46 done
47 exit 0
48 fi
49
50 if [ "$1" == "create" ]
51 then
52 HOSTS=""
53 while [ $((PORT < ENDPORT)) != "0" ]; do
54 PORT=$((PORT+1))
55 HOSTS="$HOSTS 127.0.0.1:$PORT"
56 done
57 ./redis-trib.rb create --replicas $REPLICAS $HOSTS
58 exit 0
59 fi
60
61 if [ "$1" == "stop" ]
62 then
63 while [ $((PORT < ENDPORT)) != "0" ]; do
64 PORT=$((PORT+1))
65 echo "Stopping $PORT"
66 redis-cli -p $PORT shutdown nosave
67 done
68 exit 0
69 fi
70
71 if [ "$1" == "watch" ]
72 then
73 PORT=$((PORT+1))
74 while [ 1 ]; do
75 clear
76 date
77 redis-cli -p $PORT cluster nodes | head -30
78 sleep 1
79 done
80 exit 0
81 fi
82
83 if [ "$1" == "tail" ]
84 then
85 INSTANCE=$2
86 PORT=$((PORT+INSTANCE))
87 tail -f ${PORT}.log
88 exit 0
89 fi
90
91 if [ "$1" == "call" ]
92 then
93 while [ $((PORT < ENDPORT)) != "0" ]; do
94 PORT=$((PORT+1))
95 redis-cli -p $PORT $2 $3 $4 $5 $6 $7 $8 $9
96 done
97 exit 0
98 fi
99
100 if [ "$1" == "clean" ]
101 then
102 rm -rf *.log
103 rm -rf appendonly*.aof
104 rm -rf dump*.rdb
105 rm -rf nodes*.conf
106 exit 0
107 fi
108
109 echo "Usage: $0 [start|create|stop|watch|tail|clean]"
110 echo "start -- Launch Redis Cluster instances."
111 echo "create -- Create a cluster using redis-trib create."
112 echo "stop -- Stop Redis Cluster instances."
113 echo "watch -- Show CLUSTER NODES output (first 30 lines) of first node."
114 echo "tail <id> -- Run tail -f of instance at base port + ID."
115 echo "clean -- Remove all instances data, logs, configs."