From 41b07642aec81b42913ec5c10f6ce8e6de7d6c1f Mon Sep 17 00:00:00 2001 From: Brian Waldon Date: Wed, 5 Feb 2014 14:38:38 -0800 Subject: [PATCH] feat(etcd-discovery): Add support to etcd-bootstrap for etcd-discovery --- .../dev-db/etcd/files/etcd-bootstrap | 38 +++++++++++-------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/sdk_container/src/third_party/coreos-overlay/dev-db/etcd/files/etcd-bootstrap b/sdk_container/src/third_party/coreos-overlay/dev-db/etcd/files/etcd-bootstrap index 2ac1fd41a9..690834309a 100755 --- a/sdk_container/src/third_party/coreos-overlay/dev-db/etcd/files/etcd-bootstrap +++ b/sdk_container/src/third_party/coreos-overlay/dev-db/etcd/files/etcd-bootstrap @@ -1,31 +1,37 @@ #!/bin/bash +#TODO: Generating a config file rather than args so etcd-bootstrap can run as a +# completely separate unit from etcd + VIRT=$(coreos-detect-virt) STATE=/var/lib/etcd -DEFAULT_ARGS="-d $STATE -f -cl 0.0.0.0 -n ${HOSTNAME}" +ARGS="-f -data-dir $STATE -bind-addr 0.0.0.0" if [ "${VIRT}" != "ec2" ]; then echo "Detected environment \"${VIRT}\", just starting solo master..." - exec /usr/bin/etcd ${DEFAULT_ARGS} + exec /usr/bin/etcd ${ARGS} -n ${HOSTNAME} fi +BOOTSTRAP_PEERS="/var/run/etcd/bootstrap.config" +BOOTSTRAP_DISCO="/var/run/etcd/bootstrap.disco" + META_URL="http://169.254.169.254/latest" MY_IP=$(curl -s $META_URL/meta-data/local-ipv4) -BOOTSTRAP="/var/run/etcd/bootstrap.config" +ARGS="${ARGS} -name ${MY_IP} -addr ${MY_IP}:4001 -peer-addr ${MY_IP}:7001 -peer-bind-addr 0.0.0.0" -[ ! -e $BOOTSTRAP ] && echo bootstrap config missing && exit 1 +if [ -e $BOOTSTRAP_DISCO ]; then + DISCOVERY_URL="$(cat $BOOTSTRAP_DISCO)" + ARGS="${ARGS} -discovery ${DISCOVERY_URL}" -CLUSTER_ARGS="-n $MY_IP -c $MY_IP:4001 -s $MY_IP:7001 -sl 0.0.0.0" - -# strip blank lines -IPS=$(grep -v $MY_IP $BOOTSTRAP|grep -v '^\n$' |sed 's/$/:7001/'|tr '\n' ','|sed 's/^,//'|sed 's/,$//') - -if [ -z "$IPS" ]; then - echo "becoming master..." - exec /usr/bin/etcd ${DEFAULT_ARGS} ${CLUSTER_ARGS} -else - echo "trying $IPS" - set -x - exec /usr/bin/etcd ${DEFAULT_ARGS} ${CLUSTER_ARGS} -C "$IPS" +elif [ -e $BOOTSTRAP_PEERS ]; then + IPS=$(grep -v $MY_IP $BOOTSTRAP_PEERS | grep -v '^\n$' | sed 's/$/:7001/'| tr '\n' ','| sed 's/^,//' | sed 's/,$//') + if [ -z "$IPS" ]; then + ARGS="${ARGS} -C ${IPS}" + fi +else + echo "Could not find any bootstrap configuration" + exit 1 fi + +exec /usr/bin/etcd $ARGS