feat(dev-db): coordinate with the c10n service

this is an experiment to coordinate etcd with c10n.
This commit is contained in:
Brandon Philips 2013-07-10 17:39:22 -07:00
parent 3b2c247612
commit b293cd63d6
5 changed files with 53 additions and 2 deletions

View File

@ -31,6 +31,9 @@ src_compile() {
src_install() { src_install() {
dobin ${S}/${PN} dobin ${S}/${PN}
dobin ${FILESDIR}/coreos-c10n
dobin ${FILESDIR}/etcd-bootstrap
systemd_dounit "${FILESDIR}"/${PN}.service systemd_dounit "${FILESDIR}"/${PN}.service
systemd_enable_service multi-user.target ${PN}.service systemd_enable_service multi-user.target ${PN}.service
} }

View File

@ -29,7 +29,10 @@ src_compile() {
} }
src_install() { src_install() {
dosbin ${S}/${PN} dobin ${S}/${PN}
dobin ${FILESDIR}/coreos-c10n
dobin ${FILESDIR}/etcd-bootstrap
systemd_dounit "${FILESDIR}"/${PN}.service systemd_dounit "${FILESDIR}"/${PN}.service
systemd_enable_service multi-user.target ${PN}.service systemd_enable_service multi-user.target ${PN}.service
} }

View File

@ -32,4 +32,4 @@ for IP4 in `curl -s $META_URL/meta-data/ | grep ipv4`; do
fi fi
done done
curl $C10N_ENDPOINT -d "c10n_url=$URL" -d"ip_list=$IP_LIST" curl $C10N_ENDPOINT -d "c10n_url=$URL" -d"ip_list=$IP_LIST" > /var/run/etcd/bootstrap.config

View File

@ -0,0 +1,43 @@
#!/bin/bash
# Test an IP address for validity:
# Usage:
# valid_ip IP_ADDRESS
# if [[ $? -eq 0 ]]; then echo good; else echo bad; fi
# OR
# if valid_ip IP_ADDRESS; then echo good; else echo bad; fi
# http://www.linuxjournal.com/content/validating-ip-address-bash-script
function valid_ip()
{
local ip=$1
local stat=1
if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
OIFS=$IFS
IFS='.'
ip=($ip)
IFS=$OIFS
[[ ${ip[0]} -le 255 && ${ip[1]} -le 255 \
&& ${ip[2]} -le 255 && ${ip[3]} -le 255 ]]
stat=$?
fi
return $stat
}
BOOTSTRAP="/var/run/etcd/bootstrap.config"
for HOSTS in `[ -e $BOOTSTRAP ] && cat $BOOTSTRAP`; do
for IP in `echo $HOSTS | sed 's/,/\'$'\n/g' `; do
echo $IP
LEADER=`curl --connect-timeout 1 -s $IP:7001/leader`
if [ $? -eq 0 ]; then
LEADER_IP=`echo $LEADER | cut -d':' -f1`
LEADER_PORT=`echo $LEADER | cut -d':' -f2`
if valid_ip $LEADER_IP; then
echo GOT LEADER $LEADER
exec /usr/bin/etcd -i -C $LEADER
fi
fi
done
done
echo "Not able to connect to a leader, just starting..."
exec /usr/bin/etcd -i

View File

@ -1,4 +1,6 @@
[Service] [Service]
ExecStartPre=-/bin/mkdir -p /var/run/etcd
ExecStartPre=/usr/bin/coreos-c10n
ExecStart=/usr/bin/etcd-bootstrap ExecStart=/usr/bin/etcd-bootstrap
[Install] [Install]