summaryrefslogtreecommitdiffstats
path: root/recipes-core
diff options
context:
space:
mode:
authorEnrico Jorns <ejo@pengutronix.de>2015-12-18 09:54:23 +0100
committerEnrico Jorns <ejo@pengutronix.de>2016-03-07 11:27:57 +0100
commit5beec3ccce39e10b35e571a82d3a9a867bca6b14 (patch)
tree04f8dcfd4f669e8e646764a56500638694d24569 /recipes-core
parentf33d7d01fe1658217e679be01a0eb8844410ebb4 (diff)
downloadmeta-ptx-5beec3ccce39e10b35e571a82d3a9a867bca6b14.tar.gz
meta-ptx-5beec3ccce39e10b35e571a82d3a9a867bca6b14.tar.xz
systemd: add rc-once mechanism
This allows to place skripts for initial execution after system install in ${sysconfdir}/rc.once.d/ Signed-off-by: Enrico Jorns <ejo@pengutronix.de>
Diffstat (limited to 'recipes-core')
-rw-r--r--recipes-core/systemd/systemd-rc-once.bb37
-rw-r--r--recipes-core/systemd/systemd-rc-once/rc-once.service13
-rw-r--r--recipes-core/systemd/systemd-rc-once/rc-once.sh51
-rw-r--r--recipes-core/systemd/systemd-rc-once/systemd-rc-once47
4 files changed, 148 insertions, 0 deletions
diff --git a/recipes-core/systemd/systemd-rc-once.bb b/recipes-core/systemd/systemd-rc-once.bb
new file mode 100644
index 0000000..6c7055b
--- /dev/null
+++ b/recipes-core/systemd/systemd-rc-once.bb
@@ -0,0 +1,37 @@
+SUMMARY = "Execute initial services once with rw mount"
+SECTION = "examples"
+LICENSE = "MIT"
+LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
+
+SRC_URI = "\
+ file://rc-once.service \
+ file://rc-once.sh \
+ file://systemd-rc-once \
+ "
+
+S = "${WORKDIR}"
+
+inherit allarch systemd
+
+do_install() {
+ install -d ${D}${base_libdir}/init
+ install -m 0755 ${WORKDIR}/rc-once.sh ${D}${base_libdir}/init/
+ install -d ${D}${systemd_unitdir}/system
+ install -m 0755 ${WORKDIR}/systemd-rc-once ${D}${systemd_unitdir}/
+ install -m 0644 ${WORKDIR}/rc-once.service ${D}${systemd_unitdir}/system/
+ install -d ${D}${systemd_unitdir}/system/system-update.target.wants
+ ln -sf ../rc-once.service ${D}${systemd_unitdir}/system/system-update.target.wants/rc-once.service
+ install -d ${D}${sysconfdir}/rc.once.d
+}
+
+FILES_${PN} += "\
+ /lib/init/rc-once.sh \
+ /lib/systemd/systemd-rc-once \
+ /lib/systemd/system/system-update.target.wants/rc-once.service \
+"
+
+SYSTEMD_SERVICE_${PN} = "rc-once.service"
+
+pkg_postinst_${PN}() {
+ ln -sf etc/rc.once.d $D/system-update
+}
diff --git a/recipes-core/systemd/systemd-rc-once/rc-once.service b/recipes-core/systemd/systemd-rc-once/rc-once.service
new file mode 100644
index 0000000..d3377b3
--- /dev/null
+++ b/recipes-core/systemd/systemd-rc-once/rc-once.service
@@ -0,0 +1,13 @@
+[Unit]
+Description=First boot services
+DefaultDependencies=no
+After=local-fs.target
+Requires=local-fs.target
+After=system-update.target
+
+[Service]
+Type=oneshot
+RemainAfterExit=no
+ExecStart=/lib/systemd/systemd-rc-once
+StandardOutput=syslog+console
+
diff --git a/recipes-core/systemd/systemd-rc-once/rc-once.sh b/recipes-core/systemd/systemd-rc-once/rc-once.sh
new file mode 100644
index 0000000..c7aad00
--- /dev/null
+++ b/recipes-core/systemd/systemd-rc-once/rc-once.sh
@@ -0,0 +1,51 @@
+#!/bin/sh
+
+RC_ONCE_DIR=/etc/rc.once.d
+DONE_DIR="$RC_ONCE_DIR/.done"
+STAMP="$DONE_DIR/rc-once"
+
+mount_root_rw() {
+
+ touch "/.root_is_rw" > /dev/null 2>&1 && return
+
+ echo -n "remounting root rw..."
+ mount /dev/root / -n -o remount,rw > /dev/null 2>&1
+ if [ "$?" -ne "0" ]; then
+ echo "failed, aborting"
+ return 1
+ fi
+ echo "done"
+}
+
+mount_root_restore() {
+
+ rm "/.root_is_rw" > /dev/null 2>&1 && return
+
+ echo -n "remounting root ro..."
+ mount /dev/root / -n -o remount,ro > /dev/null 2>&1
+ if [ "$?" -ne "0" ]; then
+ echo "failed, aborting"
+ return 1
+ fi
+ echo "done"
+}
+
+run_rc_once() {
+ failed=0
+ echo "running rc.once.d services..."
+ cd "$RC_ONCE_DIR" || exit 1
+ mkdir -p "$DONE_DIR"
+ for script in *; do
+ test -x "$script" || continue
+ test -e "$DONE_DIR/$script" && continue
+ "$RC_ONCE_DIR/$script"
+ if [ $? -ne 0 ]; then
+ echo "running $script failed."
+ failed=1
+ else
+ : > "$DONE_DIR/$script"
+ fi
+ done
+ return $failed
+}
+
diff --git a/recipes-core/systemd/systemd-rc-once/systemd-rc-once b/recipes-core/systemd/systemd-rc-once/systemd-rc-once
new file mode 100644
index 0000000..fdb198c
--- /dev/null
+++ b/recipes-core/systemd/systemd-rc-once/systemd-rc-once
@@ -0,0 +1,47 @@
+#!/bin/sh
+
+. /lib/init/rc-once.sh
+
+start() {
+ mount_root_rw || exit 1
+ if run_rc_once; then
+ rm -f /system-update
+ fi
+ systemctl daemon-reexec
+ sleep 1
+ touch /var/lib/systemd/clock
+ exec "$0" umount
+}
+
+umount() {
+ if ! mount_root_restore; then
+ # remounting rw/ro during the second boot will flush anything
+ # left in the filesystem journal
+ ln -sf /etc/rc.once.d /system-update
+ systemctl reboot
+ else
+ if [ -e /system-update ]; then
+ systemctl rescue
+ else
+ systemctl default
+ fi
+ fi
+}
+
+case "$1" in
+
+ start|"")
+ start
+ ;;
+ umount)
+ umount
+ ;;
+ *)
+ echo "Usage: $0 {start|umount}" >&2
+ exit 1
+ ;;
+esac
+
+exit 0
+
+