Patchwork [meta-oe,1/3] systemd-systemctl-native: add a systemctl wrapper

login
register
mail settings
Submitter Otavio Salvador
Date Nov. 4, 2011, 5:25 p.m.
Message ID <4e8bc6392a67fb5bb6a600d3972ee892cb357c89.1320427498.git.otavio@ossystems.com.br>
Download mbox | patch
Permalink /patch/14273/
State Accepted
Commit 79f35231a351a7df30db8b2037f274a41e8d9e58
Headers show

Comments

Otavio Salvador - Nov. 4, 2011, 5:25 p.m.
The wrapper allows for enabling services at rootfs generation thus
allowing systemd to be used in ready-only filesystems.

Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
---
 .../systemd/systemd-systemctl-native.bb            |   13 +++++
 .../systemd/systemd-systemctl-native/systemctl     |   51 ++++++++++++++++++++
 2 files changed, 64 insertions(+), 0 deletions(-)
 create mode 100644 meta-oe/recipes-core/systemd/systemd-systemctl-native.bb
 create mode 100755 meta-oe/recipes-core/systemd/systemd-systemctl-native/systemctl

Patch

diff --git a/meta-oe/recipes-core/systemd/systemd-systemctl-native.bb b/meta-oe/recipes-core/systemd/systemd-systemctl-native.bb
new file mode 100644
index 0000000..3ee757e
--- /dev/null
+++ b/meta-oe/recipes-core/systemd/systemd-systemctl-native.bb
@@ -0,0 +1,13 @@ 
+DESCRIPTION = "Wrapper to enable of systemd services"
+
+LICENSE = "MIT"
+LIC_FILES_CHKSUM = "file://${COREBASE}/LICENSE;md5=3f40d7994397109285ec7b81fdeb3b58"
+
+inherit native
+
+SRC_URI = "file://systemctl"
+
+do_install() {
+	install -d ${D}${bindir}
+	install -m 0755 ${WORKDIR}/systemctl ${D}${bindir}
+}
diff --git a/meta-oe/recipes-core/systemd/systemd-systemctl-native/systemctl b/meta-oe/recipes-core/systemd/systemd-systemctl-native/systemctl
new file mode 100755
index 0000000..1fc77fd
--- /dev/null
+++ b/meta-oe/recipes-core/systemd/systemd-systemctl-native/systemctl
@@ -0,0 +1,51 @@ 
+#!/bin/sh
+
+ROOT=
+
+# parse command line params
+while [ $# != 0 ]; do
+	opt="$1"
+
+	case "$opt" in
+		enable)
+			shift
+
+			service="$1"
+			shift
+			;;
+		--root=*)
+			ROOT=${opt##--root=}
+			shift
+			;;
+		*)
+			echo "'$opt' is an unkown option; exiting with error"
+			exit 1
+			;;
+	esac
+done
+
+# find service file
+for p in $ROOT/etc/systemd/system \
+         $ROOT/lib/systemd/system \
+         $ROOT/usr/lib/systemd/system; do
+	if [ -e $p/$service ]; then
+		service_file=$p/$service
+		service_file=${service_file##$ROOT}
+	fi
+done
+if [ -z "$service_file" ]; then
+	echo "'$service' couldn't be found; exiting with error"
+	exit 1
+fi
+
+# create the required symbolic links
+wanted_by=$(grep WantedBy $ROOT/$service_file \
+                | sed 's,WantedBy=,,g' \
+                | tr ',' '\n' \
+                | grep '\.target$')
+
+for r in $wanted_by; do
+	mkdir -p $ROOT/etc/systemd/system/$r.wants
+	ln -s $service_file $ROOT/etc/systemd/system/$r.wants
+	echo "Enabled $service for $wanted_by."
+done