Merge pull request #440 from polvi/etcd-refactor

fix(etcd.service): refactor to support cloudinit and easy c10n slaughtering
This commit is contained in:
Brian Waldon 2014-03-18 11:20:35 -07:00
commit f04d7f23b8
12 changed files with 70 additions and 78 deletions

View File

@ -9,7 +9,7 @@ CROS_WORKON_REPO="git://github.com"
if [[ "${PV}" == 9999 ]]; then
KEYWORDS="~amd64"
else
CROS_WORKON_COMMIT="e4965ec33d06f0c71622aad59d5f59f9aaca7c00" # v0.1.2
CROS_WORKON_COMMIT="5185fe48dafd601917660c4df41ed0c3332e5f98" # v0.1.2+git
KEYWORDS="amd64"
fi
@ -35,4 +35,8 @@ src_compile() {
src_install() {
dobin ${S}/bin/coreos-cloudinit
systemd_dounit "${FILESDIR}"/coreos-cloudinit-oem.service
systemd_dounit "${FILESDIR}"/cloud-config.target
systemd_enable_service default.target coreos-cloudinit-oem.service
systemd_enable_service default.target cloud-config.target
}

View File

@ -0,0 +1,6 @@
[Unit]
Requires=coreos-cloudinit-oem.service
After=coreos-cloudinit-oem.service
[Install]
WantedBy=multi-user.target

View File

@ -0,0 +1,18 @@
[Unit]
Description=coreos-cloudinit for /usr/share/oem/cloud-config.yml
Requires=dbus.service
After=dbus.service
Requires=coreos-setup-environment.service
After=coreos-setup-environment.service
RequiresMountsFor=/usr/share/oem
ConditionPathExists=/usr/share/oem/cloud-config.yml
[Service]
Type=oneshot
EnvironmentFile=/etc/environment
ExecStartPre=/usr/bin/coreos-cloudinit --from-file=/usr/share/oem/cloud-config.yml
ExecStart=/usr/bin/systemctl daemon-reload
[Install]
WantedBy=multi-user.target
WantedBy=cloudinit.target

View File

@ -52,7 +52,6 @@ src_install() {
systemd_enable_service basic.target coreos-startup.target
# Services!
systemd_enable_service default.target coreos-cloudinit-oem.service
systemd_enable_service default.target local-enable.service
systemd_enable_service default.target sshd-keygen.service
systemd_enable_service default.target sshd.socket

View File

@ -11,15 +11,19 @@ coreos:
[Service]
Type=oneshot
StandardOutput=journal+console
ExecStart=/usr/share/oem/usr/bin/ec2-ssh-key
ExecStart=/usr/share/oem/bin/ec2-ssh-key
- name: ec2-cloudinit.service
runtime: yes
content: |
[Service]
Requires=coreos-setup-environment.service
After=coreos-setup-environment.service
[Unit]
Description=Cloudinit from EC2 metadata
[Service]
Type=oneshot
EnvironmentFile=/etc/environment
ExecStart=/usr/bin/coreos-cloudinit -from-url=http://169.254.169.254/latest/user-data
- name: ec2-c10n.service
runtime: yes
@ -32,21 +36,11 @@ coreos:
[Service]
Type=oneshot
RemainAfterExit=no
ExecStart=/usr/share/oem/usr/bin/coreos-c10n
- name: etcd.service
runtime: yes
content: |
[Unit]
Description=etcd with ec2 auto-bootstrap
Requires=ec2-c10n.service
After=ec2-c10n.service
ExecStart=/usr/share/oem/bin/coreos-c10n
[Service]
User=etcd
PermissionsStartOnly=true
ExecStart=/usr/share/oem/usr/bin/etcd-bootstrap
Restart=always
RestartSec=10s
[Install]
WantedBy=multi-user.target
write_files:
- path: /etc/systemd/system/etcd.service.d/10-oem.conf
permissions: 0644
content: |
[Service]
Environment=ETCD_PEER_ELECTION_TIMEOUT=1200

View File

@ -9,8 +9,8 @@ depwarn() {
C10N_ENDPOINT=https://core-api.appspot.com/v1/c10n/group
META_URL="http://169.254.169.254/latest"
BOOTSTRAP_PEERS="/var/run/etcd/bootstrap.config"
BOOTSTRAP_DISCOVERY="/var/run/etcd/bootstrap.disco"
ETCD_SERVICE_D="/run/systemd/system/etcd.service.d"
mkdir -p $ETCD_SERVICE_D
/usr/bin/block-until-url $META_URL
@ -64,13 +64,10 @@ if head -n 1 $TMP | grep -q '^#!'; then
START_FLEET=1
fi
# If user-data is a cloud-config, hand it off to the new hotness
# If user-data is a cloud-config, do not do c10n
elif head -n 1 $TMP | grep -q '^#cloud-config'; then
# If an etcd discovery URL was found, we can assume the new hotness
# will handle bootstrapping, allowing us to clear the c10n token
if grep -q 'discovery_url:' $TMP; then
C10N_TOKEN=""
fi
# no c10n if this is a cloudconfig
C10N_TOKEN=""
# Validate the user-data as an SSH key, installing it if so
else
@ -87,7 +84,8 @@ fi
# After all that, if a script happened to set the discovery URL, write it to disk for etcd-bootstrap
if [ -n "${ETCD_DISCOVERY_URL}" ]; then
echo "Using '${ETCD_DISCOVERY_URL}' as etcd discovery url"
echo "${ETCD_DISCOVERY_URL}" > $BOOTSTRAP_DISCOVERY
echo "[Service]
Environment=ETCD_DISCOVERY=${ETCD_DISCOVERY}" > ${ETCD_SERVICE_D}/11-c10n.conf
# ...otherwise, we treat the provided user-data as a legacy c10n URL
elif [ -n "${C10N_TOKEN}" ]; then
depwarn "Bootstrapping etcd with the c10n service is deprecated."
@ -98,7 +96,11 @@ elif [ -n "${C10N_TOKEN}" ]; then
/usr/bin/block-until-url $C10N_ENDPOINT
IP=$(curl -s $META_URL/meta-data/local-ipv4)
curl -s $C10N_ENDPOINT -d "c10n_url=$C10N_TOKEN" -d"ip_list=$IP" > $BOOTSTRAP_PEERS
ETCD_PEERS=$(curl -s $C10N_ENDPOINT -d "c10n_url=$C10N_TOKEN" -d"ip_list=$IP")
echo "[Service]" > ${ETCD_SERVICE_D}/12-c10n.conf
for peer in $ETCD_PEERS; do
echo "Environment=ETCD_PEERS=${peer}" >> ${ETCD_SERVICE_D}/12-c10n.conf
done
fi
if [ "$START_FLEET" = "1" ]; then

View File

@ -1,4 +1,4 @@
#!/bin/bash +x
#!/bin/bash
ENV=$1
@ -17,6 +17,8 @@ sed -i -e '/^COREOS_PUBLIC_IPV4=/d' \
-e '/^COREOS_PRIVATE_IPV4=/d' \
"${ENV}"
/usr/bin/block-until-url http://169.254.169.254/latest/meta-data/public-ipv4
# get public ip from metadata
PUB_IP_URL=http://169.254.169.254/latest/meta-data/public-ipv4
IP=$(/usr/bin/curl --fail -s "$PUB_IP_URL")

View File

@ -16,7 +16,7 @@ IUSE=""
S="${WORKDIR}"
src_install() {
into "/usr"
into "/"
dobin ${FILESDIR}/ec2-ssh-key
dobin ${FILESDIR}/coreos-setup-environment
dobin ${FILESDIR}/coreos-c10n

View File

@ -0,0 +1 @@
etcd-9999.ebuild

View File

@ -9,16 +9,21 @@ EAPI=4
CROS_WORKON_PROJECT="coreos/etcd"
CROS_WORKON_LOCALNAME="etcd"
CROS_WORKON_REPO="git://github.com"
CROS_WORKON_COMMIT="040c1f591efa735e24e794d5084ad07782123e3c" # v0.3.0 + v1 API fix
inherit toolchain-funcs cros-workon systemd
if [[ "${PV}" == 9999 ]]; then
KEYWORDS="~amd64"
else
CROS_WORKON_COMMIT="040c1f591efa735e24e794d5084ad07782123e3c"
KEYWORDS="amd64"
fi
DESCRIPTION="etcd"
HOMEPAGE="https://github.com/coreos/etcd"
SRC_URI=""
LICENSE="Apache-2.0"
SLOT="0"
KEYWORDS="amd64 x86"
IUSE=""
DEPEND=">=dev-lang/go-1.2"
@ -31,6 +36,6 @@ src_install() {
dobin ${S}/bin/${PN}
systemd_dounit "${FILESDIR}"/${PN}.service
systemd_enable_service multi-user.target ${PN}.service
systemd_dotmpfilesd "${FILESDIR}"/${PN}.conf
systemd_enable_service multi-user.target ${PN}.service
}

View File

@ -1,35 +0,0 @@
#
# Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
# Copyright (c) 2013 CoreOS, Inc.. All rights reserved.
# Distributed under the terms of the GNU General Public License v2
# $Header:$
#
EAPI=4
CROS_WORKON_PROJECT="coreos/etcd"
CROS_WORKON_LOCALNAME="etcd"
CROS_WORKON_REPO="git://github.com"
inherit toolchain-funcs cros-workon systemd
DESCRIPTION="etcd"
HOMEPAGE="https://github.com/coreos/etcd"
SRC_URI=""
LICENSE="Apache-2.0"
SLOT="0"
KEYWORDS="~amd64"
IUSE=""
DEPEND=">=dev-lang/go-1.2"
src_compile() {
./build
}
src_install() {
dobin ${S}/bin/${PN}
systemd_dounit "${FILESDIR}"/${PN}.service
systemd_enable_service multi-user.target ${PN}.service
systemd_dotmpfilesd "${FILESDIR}"/${PN}.conf
}

View File

@ -1,18 +1,14 @@
[Unit]
Description=etcd
RequiresMountsFor=/usr/share/oem
# oem will setup etcd for auto bootstrapping
ConditionPathExists=!/usr/share/oem/cloud-config.yml
After=cloud-config.target
Wants=cloud-config.target
[Service]
User=etcd
PermissionsStartOnly=true
# Default, this will be overwritten with a cloud-config
ExecStart=/usr/bin/etcd -f -data-dir /var/lib/etcd -bind-addr 0.0.0.0 -n default
Environment=ETCD_DATA_DIR=/var/lib/etcd ETCD_NAME=default
ExecStart=/usr/bin/etcd
Restart=always
# Set a longish timeout in case this machine isn't behaving
# nicely and bothering the rest of the cluster
RestartSec=10s
[Install]