-
Notifications
You must be signed in to change notification settings - Fork 4
/
docker-entrypoint.sh
118 lines (96 loc) · 3.38 KB
/
docker-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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/bin/bash
#
# Auth query entrypoint script, Switch redis mode by $1
err() {
echo -e "[$(date +'%Y-%m-%dT%H:%M:%S%z')]: $*" >&2
}
info() {
echo -e "[$(date +'%Y-%m-%dT%H:%M:%S%z')]: $*"
}
function check_single_env() {
info 'redis will start with single mode...'
info "redis on port 6379"
}
# 和单点没有区别
function check_master_env() {
if [[ -z "${REDIS_PORT}" ]]; then
REDIS_PORT=6379
fi
sed -i 's/^\(port .*\)$/# \1/' /etc/redis/redis.conf
echo -e "\nport $REDIS_PORT" >> /etc/redis/redis.conf
info "redis will start with master mode..."
info "redis on port $REDIS_PORT"
}
function check_slave_env() {
if [[ -z "${REDIS_PORT}" ]]; then
REDIS_PORT=6379
fi
sed -i 's/^\(port .*\)$/# \1/' /etc/redis/redis.conf
echo -e "\nport $REDIS_PORT" >> /etc/redis/redis.conf
if [[ -z "${MASTER_IP}" ]]; then
err "you must provide mater ip"
exit 1
fi
if [[ -z "${MASTER_PORT}" ]]; then
err "master port set 6379"
MASTER_PORT=6379
fi
sed -i 's/^\(slaveof .*\)$/# \1/' /etc/redis/redis.conf
echo -e "\nslaveof $MASTER_IP $MASTER_PORT" >> /etc/redis/redis.conf
if [[ -n "${MASTER_USER}" ]]; then
sed -i 's/^\(masteruser .*\)$/# \1/' /etc/redis/redis.conf
echo -e "\nmasteruser $MASTER_USER" >> /etc/redis/redis.conf
fi
if [[ -n "${MASTER_PASS}" ]]; then
sed -i 's/^\(masterauth .*\)$/# \1/' /etc/redis/redis.conf
echo -e "\nmasterauth $MASTER_PASS" >> /etc/redis/redis.conf
fi
info "redis will start with slave mode, master is $MASTER_IP:$MASTER_PORT"
info "redis on port $REDIS_PORT"
}
function check_sentinel_env() {
if [[ -z "${REDIS_PORT}" ]]; then
REDIS_PORT=26379
fi
sed -i 's/^\(port .*\)$/# \1/' /etc/redis/sentinel.conf
echo -e "\nport $REDIS_PORT" >> /etc/redis/sentinel.conf
if [[ -z "${MASTER_IP}" ]]; then
err "you must provide mater ip"
exit 1
fi
if [[ -z "${MASTER_PORT}" ]]; then
err "master port set 6379"
MASTER_PORT=6379
fi
sed -i 's/^\(sentinel monitor mymaster.*\)$/# \1/' /etc/redis/sentinel.conf
echo -e "\nsentinel monitor mymaster $MASTER_IP $MASTER_PORT 2" >> /etc/redis/sentinel.conf
if [[ -n "${MASTER_USER}" ]]; then
sed -i 's/^\(sentinel auth-user mymaster .*\)$/# \1/' /etc/redis/sentinel.conf
echo -e "\nsentinel auth-user mymaster $MASTER_USER" >> /etc/redis/sentinel.conf
fi
if [[ -n "${MASTER_PASS}" ]]; then
sed -i 's/^\(sentinel auth-pass mymaster .*\)$/# \1/' /etc/redis/sentinel.conf
echo -e "\nsentinel auth-pass mymaster $MASTER_PASS" >> /etc/redis/sentinel.conf
fi
info "redis will start with sentinel mode, master is $MASTER_IP:$MASTER_PORT"
info "redis on port $REDIS_PORT"
}
# shellcheck disable=SC1009
if [[ $1 == 'single' ]]; then
check_single_env
redis-server /etc/redis/redis.conf --loadmodule /usr/lib/redis/modules/retree.so /usr/lib/redis/modules/fdauth.so
exit 1
elif [[ $1 == 'master' ]]; then
check_master_env
redis-server /etc/redis/redis.conf --loadmodule /usr/lib/redis/modules/retree.so /usr/lib/redis/modules/fdauth.so
exit 1
elif [[ $1 == 'slave' ]]; then
check_slave_env
redis-server /etc/redis/redis.conf --loadmodule /usr/lib/redis/modules/retree.so /usr/lib/redis/modules/fdauth.so
exit 1
elif [[ $1 == 'sentinel' ]]; then
check_sentinel_env
redis-server /etc/redis/sentinel.conf --loadmodule /usr/lib/redis/modules/retree.so /usr/lib/redis/modules/fdauth.so --sentinel
exit 1
fi
exec "$@"