forked from rqlite/rqlite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocker-entrypoint.sh
executable file
·92 lines (80 loc) · 2.12 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
#!/bin/sh
contains() {
key=$1
shift
for i in "$@"
do
if [[ $i == $key* ]]; then
return 1
fi
done
return 0
}
DEFAULT_NODE_ID=`hostname`
DEFAULT_ADV_ADDRESS=`hostname -f`
contains "-http-addr" "$@"
if [ $? -eq 0 ]; then
if [ -z "$HTTP_ADDR" ]; then
HTTP_ADDR="0.0.0.0:4001"
fi
http_addr="-http-addr $HTTP_ADDR"
fi
contains "-http-adv-addr" "$@"
if [ $? -eq 0 ]; then
if [ -z "$HTTP_ADV_ADDR" ]; then
HTTP_ADV_ADDR=$DEFAULT_ADV_ADDRESS:4001
fi
http_adv_addr="-http-adv-addr $HTTP_ADV_ADDR"
fi
contains "-raft-adv" "$@"
if [ $? -eq 0 ]; then
if [ -z "$RAFT_ADDR" ]; then
RAFT_ADDR="0.0.0.0:4002"
fi
raft_addr="-raft-addr $RAFT_ADDR"
fi
contains "-raft-adv-addr" "$@"
if [ $? -eq 0 ]; then
if [ -z "$RAFT_ADV_ADDR" ]; then
RAFT_ADV_ADDR=$DEFAULT_ADV_ADDRESS:4002
fi
raft_adv_addr="-raft-adv-addr $RAFT_ADV_ADDR"
fi
contains "-node-id" "$@"
if [ $? -eq 0 ]; then
if [ -z "$NODE_ID" ]; then
NODE_ID="$DEFAULT_NODE_ID"
fi
node_id="-node-id $NODE_ID"
fi
if [ -z "$DATA_DIR" ]; then
DATA_DIR="/rqlite/file/data"
fi
# When running on Kubernetes, delay a small time so DNS records
# are configured across the cluster when this rqlited comes up. Because
# rqlite does node-discovery using a headless service, it must have
# accurate DNS records. If the Pods addresses are not in the records,
# the DNS lookup will result in an error, and the Kubernetes system will
# cache this failure for (by default) 30 seconds. So this delay
# actually means getting to "ready" is quicker.
#
# This is kind of a hack. If anyone knows a better way file
# a GitHub issue at https://github.com/rqlite/rqlite-docker.
if [ -n "$KUBERNETES_SERVICE_HOST" ]; then
if [ -z "$START_DELAY" ]; then
START_DELAY=5
fi
fi
if [ -n "$START_DELAY" ]; then
sleep "$START_DELAY"
fi
RQLITED=/bin/rqlited
rqlited_commands="$RQLITED $node_id $http_addr $http_adv_addr $raft_addr $raft_adv_addr"
data_dir="$DATA_DIR"
if [ "$1" = "rqlite" ]; then
set -- $rqlited_commands $data_dir
elif [ "${1:0:1}" = '-' ]; then
# User is passing some options, so merge them.
set -- $rqlited_commands $@ $data_dir
fi
exec "$@"