From c38bfb22cca67c2c932689e5c45aba470255016f Mon Sep 17 00:00:00 2001 From: Geoff Bourne Date: Sun, 4 Sep 2016 16:10:08 -0500 Subject: [PATCH] [es] Also adding host IP discovery for http --- elasticsearch/README.md | 6 +++++- elasticsearch/start | 15 ++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/elasticsearch/README.md b/elasticsearch/README.md index ea69a5b3..ae11b165 100755 --- a/elasticsearch/README.md +++ b/elasticsearch/README.md @@ -170,7 +170,7 @@ Using the Docker Compose file above, a value of `2` is appropriate when scaling docker-compose scale master=3 -## Auto transport discovery with Swarm Mode +## Auto transport/http discovery with Swarm Mode When using Docker Swarm mode (starting with 1.12), the overlay and ingress network interfaces are assigned multiple IP addresses. As a result, it creates confusion for the transport publish logic even when using @@ -181,3 +181,7 @@ To resolve this, add -e DISCOVER_TRANSPORT_IP=eth0 replacing `eth0` with another interface within the container, if needed. + +The same can be done for publish/binding of the http module by adding: + + -e DISCOVERY_HTTP_IP=eth2 diff --git a/elasticsearch/start b/elasticsearch/start index c3ff5256..d76cb8d6 100755 --- a/elasticsearch/start +++ b/elasticsearch/start @@ -18,10 +18,19 @@ OPTS="$OPTS -Des.path.conf=/conf \ -Des.transport.tcp.port=9300 \ -Des.http.port=9200" +discoverIpFromLink() { + dev=$1 + mode=$2 + ip=`ipaddr show dev $dev scope global|awk '$1 == "inet" { if (!match($2,"/32")) { gsub("/.*","",$2) ; print $2 } }'` + echo "Discovered $mode address $ip for $dev" + OPTS="$OPTS -Des.$mode.host=$ip" +} + if [ "$DISCOVER_TRANSPORT_IP" != "" ]; then - ip=`ipaddr show dev $DISCOVER_TRANSPORT_IP scope global|awk '$1 == "inet" { if (!match($2,"/32")) { gsub("/.*","",$2) ; print $2 } }'` - echo "Discovered address $ip for $DISCOVER_TRANSPORT_IP" - OPTS="$OPTS -Des.transport.host=$ip" + discoverIpFromLink $DISCOVER_TRANSPORT_IP transport +fi +if [ "$DISCOVER_HTTP_IP" != "" ]; then + discoverIpFromLink $DISCOVER_HTTP_IP http fi if [ -n "$CLUSTER" ]; then