From 541ef97142c2b3de3b83dad858780eca6b4226ee Mon Sep 17 00:00:00 2001
From: ale <ale@incal.net>
Date: Thu, 14 Nov 2013 10:24:36 +0000
Subject: [PATCH] use smarter logic to find etcd servers

---
 debian/services/lib.sh | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/debian/services/lib.sh b/debian/services/lib.sh
index ffd7b198..32a93e08 100644
--- a/debian/services/lib.sh
+++ b/debian/services/lib.sh
@@ -10,6 +10,20 @@ if [ -z "${DOMAIN}" ]; then
     exit 1
 fi
 
+resolveall() {
+    local name="$1"
+    local port="$2"
+    getent hosts ${name} | awk "{print \$1 \":${port}\"}"
+}
+
+commaseplist() {
+    local out=
+    for arg in "$@" ; do
+        out="${out}${out:+,}${arg}"
+    done
+    echo "${out}"
+}
+
 set_public_ip() {
     # Try to guess the public IP of this host if unset, resolving the
     # fully-qualified host name.
@@ -24,5 +38,6 @@ set_public_ip() {
 set_etcd_params() {
     local default_etcd_server="etcd.${DOMAIN}"
     ETCD_SERVER="${ETCD_SERVER:-${default_etcd_server}}"
-    ETCD_OPTIONS="${ETCD_OPTIONS} --etcd-servers=localhost:4001,${ETCD_SERVER}"
+    local server_ips=$(commaseplist localhost:4001 $(resolveall ${ETCD_SERVER} 4001))
+    ETCD_OPTIONS="${ETCD_OPTIONS} --etcd-servers=${server_ips}"
 }
-- 
GitLab