feat(systemd-service-demo):Add a systemd demo

The demo includes following features:
* notifications (ready and status)
* dependencies between services (strong and week)
This commit is contained in:
Patrick Vogelaar 2023-02-08 22:23:12 +01:00
parent b0747d657d
commit 558096e264
9 changed files with 131 additions and 1 deletions

View File

@ -1,4 +1,7 @@
DESCRIPTION = "An image that come with most of the feature available in CoreOS"
inherit coreos-image
require coreos-image-all-features
require recipes-core/images/coreos-image-all-features.bb
# demos
IMAGE_INSTALL:append = " systemd-services-demo"

View File

@ -0,0 +1,15 @@
#!/bin/sh
# This is a simple example for systemd start
PIPE="/tmp/bar"
if [ ! -p "$PIPE" ]; then
mkfifo $PIPE
fi
COUNTER=0
while : ; do
COUNTER=$((COUNTER + 1))
echo "Hello Service 1: ${COUNTER}" > /tmp/bar
sleep 10
done

View File

@ -0,0 +1,18 @@
#!/bin/sh
# This is a simple example for systemd start
PIPE="/tmp/baz"
if [ ! -p "$PIPE" ]; then
mkfifo $PIPE
fi
COUNTER=0
while : ; do
COUNTER=$((COUNTER + 1))
echo "Hello Service 2: ${COUNTER}" > /tmp/baz
sleep 10
done

View File

@ -0,0 +1,28 @@
#!/bin/sh
# This is an example for systemd-notify
# You can see the status with systemctl status demoservice3.service
PIPE="/tmp/foo"
if [ ! -p "$PIPE" ]; then
mkfifo -m 666 $PIPE
fi
sleep 10 # Assume we are doing some time consuming initialization
# Notify systemd that we are ready
systemd-notify --ready --status="Waiting for data ..."
while : ; do
read a < /tmp/foo
# Tell systemd your current status
systemd-notify --status="Processing $a"
# Do something with $a …
sleep 10
systemd-notify --status="Waiting for data ..."
done

View File

@ -0,0 +1,10 @@
[Unit]
Description=systemd demo
After=demoservice3.service
Wants=demoservice3.service
[Service]
ExecStart=/usr/bin/demo_service_1.sh
[Install]
WantedBy=multi-user.target

View File

@ -0,0 +1,10 @@
[Unit]
Description=systemd demo for showing dependencies
After=demoservice3.service
Requires=demoservice3.service
[Service]
ExecStart=/usr/bin/demo_service_2.sh
[Install]
WantedBy=multi-user.target

View File

@ -0,0 +1,9 @@
[Unit]
Description=systemd demo for showing notifications
[Service]
Type=notify
ExecStart=/usr/bin/demo_service_3.sh
[Install]
WantedBy=multi-user.target

View File

@ -0,0 +1,34 @@
DESCRIPTION = "Example that shows how services can be started by using systemd unit files"
SECTION = "examples"
DEPENDS = ""
LICENSE = "CLOSED"
FILESEXTRAPATHS:prepend := "${THISDIR}/files:"
SRC_URI = " file://demo_service_1.sh \
file://demoservice1.service \
file://demo_service_2.sh \
file://demoservice2.service \
file://demo_service_3.sh \
file://demoservice3.service \
"
inherit systemd
SYSTEMD_SERVICE:${PN} += "demoservice1.service"
SYSTEMD_SERVICE:${PN} += "demoservice2.service"
SYSTEMD_SERVICE:${PN} += "demoservice3.service"
SYSTEMD_AUTO_ENABLE = "enable"
do_install(){
install -d ${D}${bindir}
install -m 0777 ${WORKDIR}/demo_service_1.sh ${D}${bindir}
install -m 0777 ${WORKDIR}/demo_service_2.sh ${D}${bindir}
install -m 0777 ${WORKDIR}/demo_service_3.sh ${D}${bindir}
install -d ${D}${systemd_unitdir}/system
install -m 0644 ${WORKDIR}/demoservice1.service ${D}${systemd_unitdir}/system
install -m 0644 ${WORKDIR}/demoservice2.service ${D}${systemd_unitdir}/system
install -m 0644 ${WORKDIR}/demoservice3.service ${D}${systemd_unitdir}/system
}
FILES:${PN} += " ${systemd_unitdir}/system/demoservice*.service ${bindir}/demo_service_*.sh"

View File

@ -7,3 +7,6 @@ IMAGE_FEATURES += "${@bb.utils.contains("MACHINE_FEATURES", "efi", "swupdate", "
IMAGE_INSTALL:append = " packagegroup-core-full-cmdline"
IMAGE_INSTALL:append = "${@bb.utils.contains("IMAGE_FEATURES", "swupdate", " swupdate-www", "", d)}"
# development tools
IMAGE_INSTALL:append = " systemd-analyze"