Patchwork image-systemd: Support enabling/disabling units at image creation time.

login
register
mail settings
Submitter Randy Witt
Date June 27, 2013, 6:13 p.m.
Message ID <1372356791-11390-1-git-send-email-rewitt@declaratino.com>
Download mbox | patch
Permalink /patch/52475/
State New
Headers show

Comments

Randy Witt - June 27, 2013, 6:13 p.m.
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@declaratino.com>
---
 meta/classes/image-systemd.bbclass | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
 create mode 100644 meta/classes/image-systemd.bbclass

Patch

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; "