From 27c89858a329f109965f67f981b3684ff4c3ba43 Mon Sep 17 00:00:00 2001 From: ojayanth Date: Fri, 12 May 2023 05:02:37 -0500 Subject: [PATCH 1/2] etcd: systemd unit support to start existing etcd node Added etcd service and configuration file support to start etcd service with existing cluster configuration. Change-Id: Ia52bbf20fd1951aa76184da54af94231d2324888 Signed-off-by: ojayanth --- .../etcd/etcd/etcd-existing.conf | 37 +++++++++++++++++++ .../recipes-extended/etcd/etcd/etcd.service | 15 ++++++++ meta-oe/recipes-extended/etcd/etcd_3.5.7.bb | 13 ++++++- 3 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 meta-oe/recipes-extended/etcd/etcd/etcd-existing.conf create mode 100644 meta-oe/recipes-extended/etcd/etcd/etcd.service diff --git a/meta-oe/recipes-extended/etcd/etcd/etcd-existing.conf b/meta-oe/recipes-extended/etcd/etcd/etcd-existing.conf new file mode 100644 index 00000000000..fc32cc80841 --- /dev/null +++ b/meta-oe/recipes-extended/etcd/etcd/etcd-existing.conf @@ -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' diff --git a/meta-oe/recipes-extended/etcd/etcd/etcd.service b/meta-oe/recipes-extended/etcd/etcd/etcd.service new file mode 100644 index 00000000000..782ef4ef090 --- /dev/null +++ b/meta-oe/recipes-extended/etcd/etcd/etcd.service @@ -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 diff --git a/meta-oe/recipes-extended/etcd/etcd_3.5.7.bb b/meta-oe/recipes-extended/etcd/etcd_3.5.7.bb index 346b305f2c1..c01b03e4aff 100644 --- a/meta-oe/recipes-extended/etcd/etcd_3.5.7.bb +++ b/meta-oe/recipes-extended/etcd/etcd_3.5.7.bb @@ -8,6 +8,8 @@ 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 \ " SRCREV = "215b53cf3b48ee761f4c40908b3874b2e5e95e9f" @@ -22,7 +24,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" @@ -49,10 +51,19 @@ 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" + 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}/ } +FILES:${PN}:append = " ${sysconfdir}/etcd.d/etcd-existing.conf" + From b0d9f43c62a10ff05a842a4837f908f96ca26ae6 Mon Sep 17 00:00:00 2001 From: ojayanth Date: Fri, 12 May 2023 05:08:41 -0500 Subject: [PATCH 2/2] etcd: add systemd unit support for clustering Refer https://etcd.io/docs/v3.5/op-guide/clustering/ for etcd clustering design background details. etcd-new.service triggers only, when the config file available in the specified path. This generic serive helps to start etcd cluster based on the project specific use cases and config files. etcd-new.service only required to run on initial setup or new node add into the existing cluster. All other use cases use regular etcd.service to start etcd with existing cluster configuration. Signed-off-by: ojayanth --- meta-oe/recipes-extended/etcd/etcd/etcd-new.path | 9 +++++++++ .../recipes-extended/etcd/etcd/etcd-new.service | 15 +++++++++++++++ meta-oe/recipes-extended/etcd/etcd_3.5.7.bb | 6 +++++- 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 meta-oe/recipes-extended/etcd/etcd/etcd-new.path create mode 100644 meta-oe/recipes-extended/etcd/etcd/etcd-new.service diff --git a/meta-oe/recipes-extended/etcd/etcd/etcd-new.path b/meta-oe/recipes-extended/etcd/etcd/etcd-new.path new file mode 100644 index 00000000000..1a18a401601 --- /dev/null +++ b/meta-oe/recipes-extended/etcd/etcd/etcd-new.path @@ -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 diff --git a/meta-oe/recipes-extended/etcd/etcd/etcd-new.service b/meta-oe/recipes-extended/etcd/etcd/etcd-new.service new file mode 100644 index 00000000000..479678dc670 --- /dev/null +++ b/meta-oe/recipes-extended/etcd/etcd/etcd-new.service @@ -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 diff --git a/meta-oe/recipes-extended/etcd/etcd_3.5.7.bb b/meta-oe/recipes-extended/etcd/etcd_3.5.7.bb index c01b03e4aff..3e7bb0f68f5 100644 --- a/meta-oe/recipes-extended/etcd/etcd_3.5.7.bb +++ b/meta-oe/recipes-extended/etcd/etcd_3.5.7.bb @@ -10,6 +10,8 @@ SRC_URI = " \ 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" @@ -53,7 +55,7 @@ go_do_compile:prepend() { REQUIRED_DISTRO_FEATURES = "systemd" SYSTEMD_PACKAGES = "${PN}" -SYSTEMD_SERVICE:${PN}:append = " etcd.service" +SYSTEMD_SERVICE:${PN}:append = " etcd.service etcd-new.service etcd-new.path" do_install:append() { install -d ${D}${bindir}/ @@ -63,6 +65,8 @@ do_install:append() { 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"