Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

etcd: systemd unit support for clustering #691

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions meta-oe/recipes-extended/etcd/etcd/etcd-existing.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# This is the configuration file to start the etcd server with
# existing cluster configuration in the data directory.

# Initial cluster state ('new' or 'existing').
ETCD_INITIAL_CLUSTER_STATE='existing'

# Path to the data directory.
ETCD_DATA_DIR='/var/lib/etcd'

# Time (in milliseconds) of a heartbeat interval.
ETCD_HEARTBEAT_INTERVAL=100

# Time (in milliseconds) for an election to timeout.
ETCD_ELECTION_TIMEOUT=1000

# List of comma separated URLs to listen on for peer traffic.
ETCD_LISTEN_PEER_URLS=http://localhost:2380

# List of comma separated URLs to listen on for client traffic.
ETCD_LISTEN_CLIENT_URLS=http://localhost:2379

# List of this member's peer URLs to advertise to the rest of the cluster.
# The URLs needed to be a comma-separated list.
ETCD_INITIAL_ADVERTISE_PEER_URLS=http://localhost:2380

# List of this member's client URLs to advertise to the public.
# The URLs needed to be a comma-separated list.
ETCD_ADVERTISE_CLIENT_URLS=http://localhost:2379

# Enable info-level logging for etcd.
ETCD_LOG_LEVEL='info'

# Specify 'stdout' or 'stderr' to skip journald logging even when running under systemd.
ETCD_LOG_OUTPUTS='default'

# etcd is not officially supported on arm64
ETCD_UNSUPPORTED_ARCH='arm'
9 changes: 9 additions & 0 deletions meta-oe/recipes-extended/etcd/etcd/etcd-new.path
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[Unit]
Description=Monitor the etcd config file changes

[Path]
PathChanged=/run/etcd-new.conf
Unit=etcd-new.service

[Install]
WantedBy=multi-user.target
15 changes: 15 additions & 0 deletions meta-oe/recipes-extended/etcd/etcd/etcd-new.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[Unit]
Description=etcd cluster member start/add service
Documentation=https://etcd.io/docs/v3.5/op-guide/clustering/
ConditionPathExists=!/var/lib/etcd/member
ConditionPathExists=/run/etcd-new.conf
OnFailure=etcd.service

[Service]
Type=notify
EnvironmentFile=/run/etcd-new.conf
ExecStart=/usr/bin/etcd
Restart=no

[Install]
WantedBy=multi-user.target
15 changes: 15 additions & 0 deletions meta-oe/recipes-extended/etcd/etcd/etcd.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[Unit]
Description=etcd key-value store
Documentation=https://github.com/etcd-io/etcd
After=network-online.target local-fs.target remote-fs.target time-sync.target
Wants=network-online.target local-fs.target remote-fs.target time-sync.target
ConditionPathExists=/var/lib/etcd/member

[Service]
Type=notify
EnvironmentFile=/etc/etcd.d/etcd-existing.conf
ExecStart=/usr/bin/etcd
Restart=always

[Install]
WantedBy=multi-user.target
17 changes: 16 additions & 1 deletion meta-oe/recipes-extended/etcd/etcd_3.5.7.bb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ SRC_URI = " \
git://github.com/etcd-io/etcd;branch=release-3.5;protocol=https \
file://0001-xxhash-bump-to-v2.1.2.patch;patchdir=src/${GO_IMPORT} \
file://0001-test_lib.sh-remove-gobin-requirement-during-build.patch;patchdir=src/${GO_IMPORT} \
file://etcd.service \
file://etcd-existing.conf \
file://etcd-new.service \
file://etcd-new.path \
"

SRCREV = "215b53cf3b48ee761f4c40908b3874b2e5e95e9f"
Expand All @@ -22,7 +26,7 @@ RDEPENDS:${PN}-dev = " \

export GO111MODULE="on"

inherit go
inherit go systemd pkgconfig

# Go based binaries do not handle being stripped
INHIBIT_PACKAGE_STRIP = "1"
Expand All @@ -49,10 +53,21 @@ go_do_compile:prepend() {
chmod u+w -R ${WORKDIR}/build/pkg/mod
}

REQUIRED_DISTRO_FEATURES = "systemd"
SYSTEMD_PACKAGES = "${PN}"
SYSTEMD_SERVICE:${PN}:append = " etcd.service etcd-new.service etcd-new.path"

do_install:append() {
install -d ${D}${bindir}/
install -m 0755 ${D}/usr/lib/go/src/go.etcd.io/etcd/v3/bin/etcd ${D}${bindir}
install -m 0755 ${D}/usr/lib/go/src/go.etcd.io/etcd/v3/bin/etcdctl ${D}${bindir}
install -m 0755 ${D}/usr/lib/go/src/go.etcd.io/etcd/v3/bin/etcdutl ${D}${bindir}
install -m 0644 ${WORKDIR}/etcd-existing.conf -D -t ${D}${sysconfdir}/etcd.d
install -d ${D}${systemd_system_unitdir}
install -m 0644 ${WORKDIR}/etcd.service ${D}${systemd_system_unitdir}/
install -m 0644 ${WORKDIR}/etcd-new.service ${D}${systemd_system_unitdir}/
install -m 0644 ${WORKDIR}/etcd-new.path ${D}${systemd_system_unitdir}/
}

FILES:${PN}:append = " ${sysconfdir}/etcd.d/etcd-existing.conf"