forked from gliderlabs/docker-consul
-
Notifications
You must be signed in to change notification settings - Fork 1
/
start
executable file
·55 lines (46 loc) · 1.11 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
#!/bin/bash
readonly IMAGE="ficusio/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:8600 \
-p $bridge_ip:53:8600/udp \
$args \
$IMAGE $server_flag -advertise $external_ip $run_mode
EOF
}
main() {
set -eo pipefail
case "$1" in
cmd:run)
shift
cmd-run $@
;;
*)
local nproc=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || 1)
GOMAXPROCS=$nproc exec /bin/consul agent -config-dir=/config $@
;;
esac
}
main "$@"