[OE-core] [PATCH] image-systemd: Support enabling/disabling units at image creation time.

Randy Witt rewitt at declaratino.com
Thu Jun 27 18:13:11 UTC 2013


Sometimes it is useful to have a set of units that get enabled or
disabled for an image, but that aren't enabled by default during package
installation.

The image-systemd.bbclass allows for adding a list of whitespace
separated units to the SYSTEMD_UNITS_ENABLE, SYSTEMD_UNITS_DISABLE, or
SYSTEMD_UNITS_MASK variables, in order to run the corresponding systemctl
command only as a rootfs postprocess.

Signed-off-by: Randy Witt <rewitt at declaratino.com>
---
 meta/classes/image-systemd.bbclass | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
 create mode 100644 meta/classes/image-systemd.bbclass

diff --git a/meta/classes/image-systemd.bbclass b/meta/classes/image-systemd.bbclass
new file mode 100644
index 0000000..f268a5c
--- /dev/null
+++ b/meta/classes/image-systemd.bbclass
@@ -0,0 +1,26 @@
+# Runs systemctl commands on the units in the SYSTEMD_UNITS_ENABLE,
+# SYSTEMD_UNITS_DISABLE, and SYSTEMD_UNITS_MASK variables. This bbclass
+# is intended to be inherited by image generation recipes.
+
+SYSTEMD_UNITS_ENABLE ??= ""
+SYSTEMD_UNITS_DISABLE ??= ""
+SYSTEMD_UNITS_MASK ??= ""
+
+run_systemctl_commands() {
+if type systemctl > /dev/null 2>&1; then
+	for unit in ${SYSTEMD_UNITS_ENABLE}; do
+		systemctl --root=${IMAGE_ROOTFS} enable ${unit} && continue
+		echo "WARNING: Could not enable unit ${unit}"
+	done
+	for unit in ${SYSTEMD_UNITS_DISABLE}; do
+		systemctl --root=${IMAGE_ROOTFS} disable ${unit} && continue
+		echo "WARNING: Could not disable unit ${unit}"
+	done
+	for unit in ${SYSTEMD_UNITS_MASK}; do
+		systemctl --root=${IMAGE_ROOTFS} mask ${unit} && continue
+		echo "WARNING: Could not mask unit ${unit}"
+	done
+fi
+}
+
+ROOTFS_POSTPROCESS_COMMAND += "run_systemctl_commands; "
-- 
1.8.1.4




More information about the Openembedded-core mailing list