Skip to content

Commit

Permalink
Merge pull request hashicorp#15 from binocarlos/master
Browse files Browse the repository at this point in the history
client flag for cmd::run
  • Loading branch information
progrium committed Sep 3, 2014
2 parents 1e81d39 + 4991702 commit 84e1dec
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
12 changes: 11 additions & 1 deletion README.md
Expand Up @@ -112,7 +112,7 @@ That's it! Once this last node connects, it will bootstrap into a cluster. You n

#### Runner command

Since the `docker run` command to start in production is so long, a command is available to generate this for you. Running with `cmd:run <advertise-ip>[::<join-ip>] [docker-run-args...]` will output an opinionated, but customizable `docker run` command you can run in a subshell. For example:
Since the `docker run` command to start in production is so long, a command is available to generate this for you. Running with `cmd:run <advertise-ip>[::<join-ip>[::<client-flag>]] [docker-run-args...]` will output an opinionated, but customizable `docker run` command you can run in a subshell. For example:

$ docker run --rm progrium/consul cmd:run 10.0.1.1 -d

Expand Down Expand Up @@ -154,6 +154,16 @@ To use this convenience, you simply wrap the `cmd:run` output in a subshell. Run

$ $(docker run --rm progrium/consul cmd:run 127.0.0.1 -it)

##### Client flag

Client nodes allow you to keep growing your cluster without impacting the performance of the underlying gossip protocol (they proxy requests to one of the server nodes and so are stateless).

To boot a client node using the runner command, append the string `::client` onto the `<advertise-ip>::<join-ip>` argument. For example:

$ docker run --rm progrium/consul cmd:run 10.0.1.4::10.0.1.2::client -d

Would create the same output as above but without the `-server` consul argument.

#### Health checking with Docker

Consul lets you specify a shell script to run for health checks, similar to Nagios. As a container, those scripts run inside this container environment which is a minimal Busybox environment with bash and curl. For some, this is fairly limiting, so I've added some built-in convenience scripts to properly do health checking in a Docker system.
Expand Down
11 changes: 8 additions & 3 deletions start
Expand Up @@ -7,15 +7,20 @@ cmd-run() {
local ip_def="$1"; shift
local args="$@"

declare external_ip join_ip bridge_ip run_mode
declare external_ip join_ip bridge_ip run_mode client_flag server_flag

IFS=':' read external_ip join_ip client_flag <<< "${ip_def//::/:}"

IFS=':' read external_ip join_ip <<< "${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 \
Expand All @@ -28,7 +33,7 @@ eval docker run --name consul -h \$HOSTNAME \
-p $external_ip:8500:8500 \
-p $bridge_ip:53:53/udp \
$args \
$IMAGE -server -advertise $external_ip $run_mode
$IMAGE $server_flag -advertise $external_ip $run_mode
EOF
}

Expand Down

0 comments on commit 84e1dec

Please sign in to comment.