-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentrypoint.sh
executable file
·94 lines (75 loc) · 2.24 KB
/
entrypoint.sh
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/bin/sh -e
if [ "$1" = 'redis-cluster' ]; then
# Allow passing in cluster IP by argument or environmental variable
IP="${2:-$IP}"
if [ -z "$IP" ]; then # If IP is unset then discover it
IP=$(hostname -i)
fi
if [ -z "${INITIAL_PORT}" ]; then # Default to port 7000
INITIAL_PORT=7000
fi
if [ -z "$MASTERS" ]; then # Default to 3 masters
MASTERS=3
fi
if [ -z "$SLAVES_PER_MASTER" ]; then # Default to 1 slave for each master
SLAVES_PER_MASTER=1
fi
if [ -z "$BIND_ADDRESS" ]; then # Default to any IPv4 address
BIND_ADDRESS=0.0.0.0
fi
max_port=$((INITIAL_PORT + MASTERS * (SLAVES_PER_MASTER + 1) - 1))
first_standalone=$((max_port + 1))
if [ "$STANDALONE" = "true" ]; then
STANDALONE=2
fi
if [ -n "$STANDALONE" ]; then
max_port=$((max_port + STANDALONE))
fi
for port in $(seq $INITIAL_PORT $max_port); do
mkdir -p "/redis-conf/${port}" "/redis-data/${port}" "/etc/sv/${port}"
if [ -e "/redis-data/${port}/nodes.conf" ]; then
rm "/redis-data/${port}/nodes.conf"
fi
if [ -e "/redis-data/${port}/dump.rdb" ]; then
rm "/redis-data/${port}/dump.rdb"
fi
if [ -e "/redis-data/${port}/appendonly.aof" ]; then
rm "/redis-data/${port}/appendonly.aof"
fi
if [ "$port" -lt "$first_standalone" ]; then
cat >"/redis-conf/${port}/redis.conf" <<EOF
bind ${BIND_ADDRESS}
port ${port}
daemonize no
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
appendonly yes
dir /redis-data/${port}
EOF
nodes="$nodes $IP:$port"
else
cat >"/redis-conf/${port}/redis.conf" <<EOF
bind ${BIND_ADDRESS}
port ${port}
daemonize no
appendonly yes
dir /redis-data/${port}
EOF
fi
cat >"/etc/sv/${port}/run" <<EOF
#!/bin/sh -eu
exec 2>&1
exec /usr/local/bin/redis-server /redis-conf/${port}/redis.conf
EOF
chmod +x "/etc/sv/${port}/run"
ln -sf "/etc/sv/${port}" /etc/service/
done
(
sleep 5
echo "yes" | eval redis-cli --cluster create --cluster-replicas "$SLAVES_PER_MASTER" "$nodes"
) &
exec /sbin/runsvdir -P /etc/service
else
exec "$@"
fi