[PATCH openbmc 1/2] Support multiple systemd service files

OpenBMC Patches openbmc-patches at stwcx.xyz
Tue Jun 14 02:40:32 AEST 2016


From: Brad Bishop <bradleyb at fuzziesquirrel.com>

Enhance obmc-phosphor-systemd such that an array of service/template
socket files in SYSTEMD_SERVICES_${PN} works.

Signed-off-by: Brad Bishop <bradleyb at fuzziesquirrel.com>
---
 .../classes/obmc-phosphor-systemd.bbclass          | 56 ++++++++++++++++++----
 .../host-ipmi-hw-example.service                   |  9 ----
 .../host-ipmi-hw-example/host-ipmi-hw.service      |  9 ++++
 3 files changed, 56 insertions(+), 18 deletions(-)
 delete mode 100644 meta-phosphor/common/recipes-phosphor/host-ipmid/host-ipmi-hw-example/host-ipmi-hw-example.service
 create mode 100644 meta-phosphor/common/recipes-phosphor/host-ipmid/host-ipmi-hw-example/host-ipmi-hw.service

diff --git a/meta-phosphor/classes/obmc-phosphor-systemd.bbclass b/meta-phosphor/classes/obmc-phosphor-systemd.bbclass
index 12e0bc1..b07174f 100644
--- a/meta-phosphor/classes/obmc-phosphor-systemd.bbclass
+++ b/meta-phosphor/classes/obmc-phosphor-systemd.bbclass
@@ -1,14 +1,52 @@
-# Common code for Phosphor OpenBMC systemd services.
-
+# Common code for systemd based services.
+#
+# Prior to inheriting this class, recipes can define services like this:
+#
+# SYSTEMD_SERVICE_${PN} = "foo.service bar.socket baz at .service"
+#
+# and these files will be added to the main package if they exist.
+#
+# Alternatively this class can just be inherited and
+# ${BPN}.service will be added to the main package.
 inherit systemd
 
-SYSTEMD_SERVICE_${PN} = "${BPN}.service"
-SRC_URI += " \
-        file://${BPN}.service \
-        "
+
+python() {
+    bpn = d.getVar('BPN', True)
+    searchpaths = d.getVar('FILESPATH', True)
+
+    services = d.getVar('SYSTEMD_SERVICE_' + bpn, True)
+
+    if services:
+        services = services.split()
+    else:
+        services = [bpn + '.service']
+
+    for s in services:
+        file = s
+        path = bb.utils.which(searchpaths, file)
+        if os.path.isfile(path):
+            d.appendVar('SRC_URI', ' file://' + file)
+            d.appendVar(
+                'FILES_' + bpn, ' ' +
+                d.getVar('systemd_system_unitdir', True) + file)
+            d.appendVar('OBMC_SYSTEMD_SERVICES', ' ' + file)
+            if file not in (d.getVar('SYSTEMD_SERVICE_' + bpn, True) or "").split():
+                d.appendVar('SYSTEMD_SERVICE_' + bpn, ' ' + file)
+        else:
+            bb.error("Could not find service file: %s" % file)
+}
 
 do_install_append() {
-        # install systemd unit files
-        install -d ${D}${systemd_unitdir}/system
-        install -m 0644 ${WORKDIR}/${BPN}.service ${D}${systemd_unitdir}/system
+        # install systemd service/socket/template files
+        if [ "${OBMC_SYSTEMD_SERVICES}" ]; then
+                install -d ${D}${systemd_system_unitdir}
+        fi
+        for s in ${OBMC_SYSTEMD_SERVICES}; do
+                install -m 0644 ${WORKDIR}/$s ${D}${systemd_system_unitdir}
+                sed -i -e 's, at BASE_BINDIR@,${base_bindir},g' \
+                        -e 's, at BINDIR@,${bindir},g' \
+                        -e 's, at SBINDIR@,${sbindir},g' \
+                        ${D}${systemd_system_unitdir}/$s
+        done
 }
diff --git a/meta-phosphor/common/recipes-phosphor/host-ipmid/host-ipmi-hw-example/host-ipmi-hw-example.service b/meta-phosphor/common/recipes-phosphor/host-ipmid/host-ipmi-hw-example/host-ipmi-hw-example.service
deleted file mode 100644
index e15d8d7..0000000
--- a/meta-phosphor/common/recipes-phosphor/host-ipmid/host-ipmi-hw-example/host-ipmi-hw-example.service
+++ /dev/null
@@ -1,9 +0,0 @@
-[Unit]
-Description=Phosphor OpenBMC host IPMI to DBUS example implementation
-
-[Service]
-Restart=always
-ExecStart=/usr/sbin/host-ipmi-hw
-
-[Install]
-WantedBy=multi-user.target
diff --git a/meta-phosphor/common/recipes-phosphor/host-ipmid/host-ipmi-hw-example/host-ipmi-hw.service b/meta-phosphor/common/recipes-phosphor/host-ipmid/host-ipmi-hw-example/host-ipmi-hw.service
new file mode 100644
index 0000000..e15d8d7
--- /dev/null
+++ b/meta-phosphor/common/recipes-phosphor/host-ipmid/host-ipmi-hw-example/host-ipmi-hw.service
@@ -0,0 +1,9 @@
+[Unit]
+Description=Phosphor OpenBMC host IPMI to DBUS example implementation
+
+[Service]
+Restart=always
+ExecStart=/usr/sbin/host-ipmi-hw
+
+[Install]
+WantedBy=multi-user.target
-- 
2.8.4




More information about the openbmc mailing list