summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Olbrich <m.olbrich@pengutronix.de>2011-04-10 20:32:07 +0200
committerMichael Olbrich <m.olbrich@pengutronix.de>2011-05-09 15:52:57 +0200
commit015683c407330bf189b77f8e15bb687aa5c3ac5a (patch)
tree5ac5cf50e7d66c27b98f17715672dc32065b7c19
parent12aae3b692266aba0dec58c590ae08a499be47bb (diff)
downloadptxdist-015683c407330bf189b77f8e15bb687aa5c3ac5a.tar.gz
ptxdist-015683c407330bf189b77f8e15bb687aa5c3ac5a.tar.xz
rc-once: add config files for systemd initmethod
Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
-rw-r--r--generic/etc/init.d/rc-once34
-rw-r--r--generic/lib/init/rc-once.sh25
-rw-r--r--generic/lib/systemd/system/rc-once.service12
-rw-r--r--generic/lib/systemd/system/rc-once.target8
-rw-r--r--generic/lib/systemd/systemd-rc-once43
-rw-r--r--rules/rc-once.make14
-rw-r--r--rules/rc-once.postinst6
7 files changed, 115 insertions, 27 deletions
diff --git a/generic/etc/init.d/rc-once b/generic/etc/init.d/rc-once
index 78dfb6020..2387c3157 100644
--- a/generic/etc/init.d/rc-once
+++ b/generic/etc/init.d/rc-once
@@ -2,50 +2,30 @@
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
-RC_ONCE_DIR=/etc/rc.once.d
-DONE_DIR="$RC_ONCE_DIR/.done"
-STAMP="$DONE_DIR/rc-once"
-
. /lib/init/initmethod-bbinit-functions.sh
+. /lib/init/rc-once.sh
-run_start() {
+do_start() {
test -e "$STAMP" && return
mount_root_rw || exit 1
- export RC_ONCE_FAILED=no
- 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."
- RC_ONCE_FAILED=yes
- else
- : > "$DONE_DIR/$script"
- fi
- done
- if [ "$RC_ONCE_FAILED" != "yes" ]; then
- : > "$STAMP"
- fi
- mount_root_restore || (
+ run_rc_once && : > "$STAMP"
+
+ if ! mount_root_restore; then
# remounting rw/ro during the second boot will flush anything
# left in the filesystem journal
rm "$STAMP"
reboot
sleep 100
- )
+ fi
}
case "$1" in
start)
- run_start >&2
+ do_start >&2
;;
-
*)
echo "Usage: $0 {start}" >&2
exit 1
diff --git a/generic/lib/init/rc-once.sh b/generic/lib/init/rc-once.sh
new file mode 100644
index 000000000..8689a32bc
--- /dev/null
+++ b/generic/lib/init/rc-once.sh
@@ -0,0 +1,25 @@
+#!/bin/sh
+
+RC_ONCE_DIR=/etc/rc.once.d
+DONE_DIR="$RC_ONCE_DIR/.done"
+STAMP="$DONE_DIR/rc-once"
+
+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/generic/lib/systemd/system/rc-once.service b/generic/lib/systemd/system/rc-once.service
new file mode 100644
index 000000000..47e664868
--- /dev/null
+++ b/generic/lib/systemd/system/rc-once.service
@@ -0,0 +1,12 @@
+[Unit]
+Description=First boot services
+DefaultDependencies=no
+After=local-fs.target
+Requires=local-fs.target
+
+[Service]
+Type=oneshot
+RemainAfterExit=no
+ExecStart=/lib/systemd/systemd-rc-once
+StandardOutput=syslog+console
+
diff --git a/generic/lib/systemd/system/rc-once.target b/generic/lib/systemd/system/rc-once.target
new file mode 100644
index 000000000..89f18c2ee
--- /dev/null
+++ b/generic/lib/systemd/system/rc-once.target
@@ -0,0 +1,8 @@
+[Unit]
+Description=System setup
+DefaultDependencies=no
+After=rc-once.service
+Requires=rc-once.service
+
+[Install]
+Alias=default.target
diff --git a/generic/lib/systemd/systemd-rc-once b/generic/lib/systemd/systemd-rc-once
new file mode 100644
index 000000000..5ecc5e5a3
--- /dev/null
+++ b/generic/lib/systemd/systemd-rc-once
@@ -0,0 +1,43 @@
+#!/bin/sh
+
+. /lib/init/initmethod-bbinit-functions.sh
+. /lib/init/rc-once.sh
+
+start() {
+ mount_root_rw || exit 1
+ if run_rc_once; then
+ systemctl disable --quiet rc-once.target
+ fi
+ systemctl daemon-reexec
+ sleep 1
+ exec "$0" umount
+}
+
+umount() {
+ if ! mount_root_restore; then
+ # remounting rw/ro during the second boot will flush anything
+ # left in the filesystem journal
+ systemctl enable --quiet rc-once.target
+ systemctl reboot
+ else
+ systemctl default
+ fi
+}
+
+case "$1" in
+
+ start|"")
+ start
+ ;;
+ umount)
+ umount
+ ;;
+ *)
+ echo "Usage: $0 {start|umount}" >&2
+ exit 1
+ ;;
+esac
+
+exit 0
+
+
diff --git a/rules/rc-once.make b/rules/rc-once.make
index da54ae612..f01bbe9d8 100644
--- a/rules/rc-once.make
+++ b/rules/rc-once.make
@@ -31,6 +31,9 @@ $(STATEDIR)/rc-once.targetinstall:
@$(call install_fixup, rc-once, AUTHOR, "Michael Olbrich <m.olbrich@pengutronix.de>")
@$(call install_fixup, rc-once, DESCRIPTION, missing)
+ @$(call install_alternative, rc-once, 0, 0, 0644, /lib/init/rc-once.sh)
+
+ifdef PTXCONF_INITMETHOD_BBINIT
@$(call install_alternative, rc-once, 0, 0, 0755, /etc/init.d/rc-once)
ifneq ($(call remove_quotes,$(PTXCONF_RC_ONCE_BBINIT_LINK)),)
@@ -38,6 +41,17 @@ ifneq ($(call remove_quotes,$(PTXCONF_RC_ONCE_BBINIT_LINK)),)
../init.d/rc-once, \
/etc/rc.d/$(PTXCONF_RC_ONCE_BBINIT_LINK))
endif
+endif
+ifdef PTXCONF_INITMETHOD_SYSTEMD
+ @$(call install_alternative, rc-once, 0, 0, 0755, \
+ /lib/systemd/systemd-rc-once)
+
+ @$(call install_alternative, rc-once, 0, 0, 0644, \
+ /lib/systemd/system/rc-once.service)
+ @$(call install_alternative, rc-once, 0, 0, 0644, \
+ /lib/systemd/system/rc-once.target)
+ @$(call install_copy, rc-once, 0, 0, 0755, /etc/systemd/system)
+endif
@$(call install_copy, rc-once, 0, 0, 0755, /etc/rc.once.d)
@$(call install_copy, rc-once, 0, 0, 0755, /etc/rc.once.d/.done)
diff --git a/rules/rc-once.postinst b/rules/rc-once.postinst
new file mode 100644
index 000000000..f80a334cb
--- /dev/null
+++ b/rules/rc-once.postinst
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+if [ -f "$DESTDIR/lib/systemd/system/rc-once.target" ]; then
+ ln -sf /lib/systemd/system/rc-once.target $DESTDIR/etc/systemd/system/default.target
+fi
+