mirror of
https://github.com/flatcar/scripts.git
synced 2025-08-15 08:56:58 +02:00
feat(dev-db): coordinate with the c10n service
this is an experiment to coordinate etcd with c10n.
This commit is contained in:
parent
3b2c247612
commit
b293cd63d6
@ -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
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
|
2
sdk_container/src/third_party/coreos-overlay/dev-db/etcd/files/coreos-c10n.sh → sdk_container/src/third_party/coreos-overlay/dev-db/etcd/files/coreos-c10n
vendored
Normal file → Executable file
2
sdk_container/src/third_party/coreos-overlay/dev-db/etcd/files/coreos-c10n.sh → sdk_container/src/third_party/coreos-overlay/dev-db/etcd/files/coreos-c10n
vendored
Normal file → Executable 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
|
43
sdk_container/src/third_party/coreos-overlay/dev-db/etcd/files/etcd-bootstrap
vendored
Executable file
43
sdk_container/src/third_party/coreos-overlay/dev-db/etcd/files/etcd-bootstrap
vendored
Executable 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
|
@ -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]
|
||||||
|
Loading…
Reference in New Issue
Block a user