forked from nimblestratus/docker-consul
-
Notifications
You must be signed in to change notification settings - Fork 0
/
start
executable file
·48 lines (39 loc) · 1.03 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
#!/bin/bash
readonly IMAGE="nimblestratus/rpi-consul"
readonly EXPECT="${EXPECT:-3}"
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/udp \
$args \
$IMAGE $server_flag -advertise $external_ip $run_mode
EOF
}
main() {
set -eo pipefail
case "$1" in
cmd:run) shift; cmd-run $@;;
*) exec /gopath/bin/consul agent -config-dir=/config $@;;
esac
}
main "$@"