forked from sequenceiq/docker-consul
-
Notifications
You must be signed in to change notification settings - Fork 0
/
start
executable file
·64 lines (52 loc) · 1.35 KB
/
start
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
#!/bin/bash
readonly IMAGE="progrium/consul"
readonly EXPECT="${EXPECT:-3}"
get-recursors() {
grep "nameserver" /etc/resolv.conf | awk '{print $2}';
}
configure-recursors() {
for recursor in $(get-recursors); do
sed -i '/^.*disable_update_check.*$/ i\ "recursor": "'$recursor'",' /config/consul.json;
done
}
cmd-run() {
local ip_def="$1"; shift
local args="$@"
declare external_ip join_ip bridge_ip run_mode client_flag server_flag
IFS=':' read external_ip join_ip client_flag <<< "${ip_def//::/:}"
if [[ -z "$join_ip" ]]; then
run_mode="-bootstrap-expect $EXPECT"
else
run_mode="-join $join_ip"
fi
if [[ -z "$client_flag" ]]; then
server_flag="-server"
fi
bridge_ip="$(ip ro | awk '/^default/{print $3}')"
cat <<EOF
eval docker run --name consul -h \$HOSTNAME \
-p $external_ip:8300:8300 \
-p $external_ip:8301:8301 \
-p $external_ip:8301:8301/udp \
-p $external_ip:8302:8302 \
-p $external_ip:8302:8302/udp \
-p $external_ip:8400:8400 \
-p $external_ip:8500:8500 \
-p $bridge_ip:53:53 \
-p $bridge_ip:53:53/udp \
$args \
$IMAGE $server_flag -advertise $external_ip $run_mode
EOF
}
run-agent() {
configure-recursors
exec /bin/consul agent -config-dir=/config $@ | tee -a $CONSUL_LOG_FILE
}
main() {
set -eo pipefail
case "$1" in
cmd:run) shift; cmd-run $@;;
*) run-agent $@;;
esac
}
main "$@"