[PATCH runin] Port to systemd

Daniel Drake dsd at laptop.org
Fri Apr 20 18:14:18 EDT 2012


Under systemd, the init-script runin launcher is running later than
before, and NetworkManager, crond and a heap of other services are also
running while runin runs.

Solve this by moving to systemd.
A runin-check service is run every boot, after olpc-configure but before
the rest of the system. runin-check is based on the old init script.
If it decides that runin is needed, it switches runlevel to the "runin"
runlevel which launches runin.service itself.

Please fix up this work as you see fit!
---
 olpc-runin-tests.spec |   14 ++++--
 runin-check           |   98 +++++++++++++++++++++++++++++++++++++++++++++++++
 runin-check.service   |   15 +++++++
 runin.service         |    8 ++++
 runin.target          |    6 +++
 5 files changed, 136 insertions(+), 5 deletions(-)
 create mode 100755 runin-check
 create mode 100644 runin-check.service
 create mode 100644 runin.service
 create mode 100644 runin.target

diff --git a/olpc-runin-tests.spec b/olpc-runin-tests.spec
index 468c391..2da6828 100644
--- a/olpc-runin-tests.spec
+++ b/olpc-runin-tests.spec
@@ -22,7 +22,9 @@ OLPC run-in manufacturing tests.
 
 %install
 rm -rf $RPM_BUILD_ROOT
-%{__install} -D -m 0755 runin.initd	$RPM_BUILD_ROOT/%{_sysconfdir}/rc.d/init.d/00-olpc-runin
+%{__install} -D -m 0644 runin.service $RPM_BUILD_ROOT/%{_unitdir}/runin.service
+%{__install} -D -m 0644 runin-check.service $RPM_BUILD_ROOT/%{_unitdir}/runin-check.service
+%{__install} -D -m 0644 runin.target $RPM_BUILD_ROOT/%{_unitdir}/runin.target
 %{__install} -D -m 0755 runin-battery	$RPM_BUILD_ROOT/runin/runin-battery
 %{__install} -D -m 0755 runin-camera	$RPM_BUILD_ROOT/runin/runin-camera
 %{__install} -D -m 0755 runin-common	$RPM_BUILD_ROOT/runin/runin-common
@@ -56,12 +58,14 @@ rm -rf $RPM_BUILD_ROOT
 %{__install} -D -m 0755 sdkit-arm/watchdog $RPM_BUILD_ROOT/runin/sdkit-arm/watchdog
 
 %post
-/sbin/chkconfig --add 00-olpc-runin
+if [ $1 -eq 1 ]; then
+	/bin/systemctl enable runin-check.service
+fi
 
 
 %preun
-if [ $1 -eq 0 ]; then
-	/sbin/chkconfig --del 00-olpc-runin
+if [ $1 = 0 ]; then
+	/bin/systemctl disable runin-check.service
 fi
 
 
@@ -71,7 +75,7 @@ rm -rf $RPM_BUILD_ROOT
 
 %files
 %defattr(-,root,root,-)
-%{_sysconfdir}/rc.d/init.d/00-olpc-runin
+%{_unitdir}/*
 /runin/runin-battery
 /runin/runin-camera
 /runin/runin-common
diff --git a/runin-check b/runin-check
new file mode 100755
index 0000000..966a0bf
--- /dev/null
+++ b/runin-check
@@ -0,0 +1,98 @@
+#!/bin/bash
+# runin-check: Check if we should run OLPC run-in manufacturing tests
+# and ask systemd to run them, if required.
+
+RUNIN_FILE=runin.tar.gz
+RUNIN_OFW=/bootpart/runin # created by olpc-os-builder, fatal if missing
+if [[ -e ${RUNIN_OFW} ]]; then
+    export RUNIN_OFW_PRESENT=true
+else
+    export RUNIN_OFW_PRESENT=false
+fi
+RUNIN_SRC=$RUNIN_OFW/$RUNIN_FILE
+RUNIN_PATH=/runin
+
+# Where is OpenFirmware today?
+OFW=/ofw
+for x in /proc/device-tree /ofw; do
+    if [[ -e $x/mfg-data ]]; then OFW=$x; break; fi
+done
+export OFW
+
+# Are we in runin mode?
+runin=false
+quick=false
+
+# We are in runin mode if the TS manufacturing tag is set to RUNIN
+if [[ -e ${OFW}/mfg-data/TS ]]; then
+    case "$(tr -d '[:space:]\000' < ${OFW}/mfg-data/TS)" in
+	RUNIN|runin|rnin)
+            runin=true
+            ;;
+    esac
+fi
+
+# We are in runin mode if the kernel command line contains runin
+for word in $(cat /proc/cmdline); do
+    case "$word" in
+        runin|RUNIN)
+            runin=true
+            ;;
+    esac
+done
+
+# We are in runin mode always if the /runin/always file is present
+# (use with care, you need to boot to single user mode or boot an
+# external build to unset it)
+if [[ -e /runin/always ]]; then
+    echo "oh, /runin/always"
+    touch /runin/always && sync && runin=true
+fi
+
+# We are in runin mode once if the /runin/force file is present
+if [[ -e /runin/force ]]; then
+    echo "oh, /runin/force"
+    rm -f /runin/force && sync && runin=true
+fi
+
+# We are in runin mode once if the /runin/quick file is present
+if [[ -e /runin/quick ]]; then
+    echo "oh, /runin/quick"
+    rm -f /runin/quick && sync && runin=true && quick=true
+fi
+
+if [[ false = "$runin" ]]; then
+    exit 0
+fi
+
+PATH=$PATH:/bin:/usr/bin
+export PATH
+
+if [[ ! -d $RUNIN_PATH ]]; then
+    mkdir -p $RUNIN_PATH
+fi
+cd $RUNIN_PATH
+
+# Look for both the long form and the 8.3 form
+if [[ -f $RUNIN_OFW/runin.tar.gz ]]; then
+    RUNIN_SRC=$RUNIN_OFW/runin.tar.gz
+fi
+
+if [[ -f $RUNIN_OFW/runin.tgz ]]; then
+    RUNIN_SRC=$RUNIN_OFW/runin.tgz
+fi
+
+if [[ -f $RUNIN_SRC ]]; then
+    echo "Overriding in-build tests"
+    (echo "Switched to dir: $(pwd)" && tar xvzf $RUNIN_SRC 2>&1) >$RUNIN_PATH/tar.log
+else
+    echo "Using in-build tests"
+fi
+
+DISPLAY=:0
+export DISPLAY
+export RUNIN_PATH
+
+# FIXME reimplement runin quick. Perhaps leave the /runin/quick marker in place
+# to be later detected and deleted by runin-main.
+systemctl isolate runin.target
diff --git a/runin-check.service b/runin-check.service
new file mode 100644
index 0000000..90973fb
--- /dev/null
+++ b/runin-check.service
@@ -0,0 +1,15 @@
+# Check if we need to start runin tests this boot.
+
+[Unit]
+Description=Check whether to run OLPC run-in tests
+DefaultDependencies=no
+Requires=olpc-configure.service
+After=olpc-configure.service
+Before=basic.target
+
+[Service]
+Type=oneshot
+ExecStart=/runin/runin-check
+
+[Install]
+WantedBy=basic.target
diff --git a/runin.service b/runin.service
new file mode 100644
index 0000000..ca8abd1
--- /dev/null
+++ b/runin.service
@@ -0,0 +1,8 @@
+[Unit]
+Description=OLPC run-in tests
+DefaultDependencies=no
+Wants=udev-settle.service
+After=udev-settle.service
+
+[Service]
+ExecStart=/runin/runin-main
diff --git a/runin.target b/runin.target
new file mode 100644
index 0000000..2a8c312
--- /dev/null
+++ b/runin.target
@@ -0,0 +1,6 @@
+[Unit]
+Description=OLPC run-in tests
+AllowIsolate=true
+DefaultDependencies=no
+Requires=olpc-configure.service runin.service
+After=olpc-configure.service
-- 
1.7.7.6




More information about the Devel mailing list