feat(etcd-discovery): Add support to etcd-bootstrap for etcd-discovery

This commit is contained in:
Brian Waldon 2014-02-05 14:38:38 -08:00
parent 4a5eaf8f0a
commit 41b07642ae

View File

@ -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