Harald Hoyer 2265b4
From 792b189317068202aba16d1fc2371d605a6c715c Mon Sep 17 00:00:00 2001
Harald Hoyer 2265b4
From: Harald Hoyer <harald@redhat.com>
Harald Hoyer 2265b4
Date: Mon, 9 Jul 2012 20:46:20 +0200
Harald Hoyer 2265b4
Subject: [PATCH] systemd service cleanup
Harald Hoyer 2265b4
Harald Hoyer 2265b4
---
Harald Hoyer 2265b4
 modules.d/95rootfs-block/block-genrules.sh     |   28 ++++++++++++------------
Harald Hoyer 2265b4
 modules.d/98systemd/dracut-cmdline.service     |    4 +---
Harald Hoyer 2265b4
 modules.d/98systemd/dracut-initqueue.service   |    4 +---
Harald Hoyer 2265b4
 modules.d/98systemd/dracut-initqueue.sh        |    1 -
Harald Hoyer 2265b4
 modules.d/98systemd/dracut-pre-pivot.service   |    7 +++---
Harald Hoyer 2265b4
 modules.d/98systemd/dracut-pre-pivot.sh        |   11 ----------
Harald Hoyer 2265b4
 modules.d/98systemd/dracut-pre-trigger.service |    4 +---
Harald Hoyer 2265b4
 modules.d/98systemd/dracut-pre-udev.service    |    4 +---
Harald Hoyer 2265b4
 modules.d/98systemd/initrd-switch-root.service |    6 ++++-
Harald Hoyer 2265b4
 modules.d/98systemd/initrd-switch-root.target  |    2 +-
Harald Hoyer 2265b4
 modules.d/98systemd/module-setup.sh            |   10 ++++++---
Harald Hoyer 2265b4
 modules.d/98systemd/service-to-run.sh          |    6 +++++
Harald Hoyer 2265b4
 modules.d/98systemd/udevadm-cleanup-db.service |   20 +++++++++++++++++
Harald Hoyer 2265b4
 13 files changed, 60 insertions(+), 47 deletions(-)
Harald Hoyer 2265b4
 create mode 100755 modules.d/98systemd/service-to-run.sh
Harald Hoyer 2265b4
 create mode 100644 modules.d/98systemd/udevadm-cleanup-db.service
Harald Hoyer 2265b4
Harald Hoyer 2265b4
diff --git a/modules.d/95rootfs-block/block-genrules.sh b/modules.d/95rootfs-block/block-genrules.sh
Harald Hoyer 2265b4
index fe6e331..7f894ee 100755
Harald Hoyer 2265b4
--- a/modules.d/95rootfs-block/block-genrules.sh
Harald Hoyer 2265b4
+++ b/modules.d/95rootfs-block/block-genrules.sh
Harald Hoyer 2265b4
@@ -13,22 +13,22 @@ if [ "${root%%:*}" = "block" ]; then
Harald Hoyer 2265b4
     printf '[ -e "%s" ] && { ln -s "%s" /dev/root 2>/dev/null; rm "$job"; }\n' \
Harald Hoyer 2265b4
         "${root#block:}" "${root#block:}" > $hookdir/initqueue/settled/blocksymlink.sh
Harald Hoyer 2265b4
 
Harald Hoyer 2265b4
-    if [ -d /lib/systemd/system/ ]; then
Harald Hoyer 2265b4
-        echo "${root#block:} $NEWROOT ${fstype:-auto} ${rflags:-defaults} 1 1" >> /etc/fstab
Harald Hoyer 2265b4
-        {
Harald Hoyer 2265b4
-           echo '[Unit]'
Harald Hoyer 2265b4
-           echo 'Description=New Root File System'
Harald Hoyer 2265b4
-           echo 'DefaultDependencies=no'
Harald Hoyer 2265b4
-           echo 'Before=switch-root.service'
Harald Hoyer 2265b4
-           echo '[Mount]'
Harald Hoyer 2265b4
-           echo "What=${root#block:}"
Harald Hoyer 2265b4
-           echo "Where=$NEWROOT"
Harald Hoyer 2265b4
+    # if [ -d /lib/systemd/system/ ]; then
Harald Hoyer 2265b4
+    #     echo "${root#block:} $NEWROOT ${fstype:-auto} ${rflags:-defaults} 1 1" >> /etc/fstab
Harald Hoyer 2265b4
+    #     {
Harald Hoyer 2265b4
+    #        echo '[Unit]'
Harald Hoyer 2265b4
+    #        echo 'Description=New Root File System'
Harald Hoyer 2265b4
+    #        echo 'DefaultDependencies=no'
Harald Hoyer 2265b4
+    #        echo 'Before=initrd-switch-root.service'
Harald Hoyer 2265b4
+    #        echo '[Mount]'
Harald Hoyer 2265b4
+    #        echo "What=${root#block:}"
Harald Hoyer 2265b4
+    #        echo "Where=$NEWROOT"
Harald Hoyer 2265b4
 
Harald Hoyer 2265b4
-       } >/lib/systemd/system/${NEWROOT#/}.mount
Harald Hoyer 2265b4
+    #    } >/lib/systemd/system/${NEWROOT#/}.mount
Harald Hoyer 2265b4
 
Harald Hoyer 2265b4
-       mkdir -p /lib/systemd/system/switch-root.target.wants
Harald Hoyer 2265b4
-       ln -s ../${NEWROOT#/}.mount /lib/systemd/system/switch-root.target.wants/${NEWROOT#/}.mount
Harald Hoyer 2265b4
-    fi
Harald Hoyer 2265b4
+    #    mkdir -p /lib/systemd/system/initrd-switch-root.target.requires
Harald Hoyer 2265b4
+    #    ln -s ../${NEWROOT#/}.mount /lib/systemd/system/initrd-switch-root.target.requires/${NEWROOT#/}.mount
Harald Hoyer 2265b4
+    # fi
Harald Hoyer 2265b4
 
Harald Hoyer 2265b4
     wait_for_dev "${root#block:}"
Harald Hoyer 2265b4
 fi
Harald Hoyer 2265b4
diff --git a/modules.d/98systemd/dracut-cmdline.service b/modules.d/98systemd/dracut-cmdline.service
Harald Hoyer 2265b4
index 13671e4..1ed50a9 100644
Harald Hoyer 2265b4
--- a/modules.d/98systemd/dracut-cmdline.service
Harald Hoyer 2265b4
+++ b/modules.d/98systemd/dracut-cmdline.service
Harald Hoyer 2265b4
@@ -16,10 +16,8 @@ Wants=systemd-journald.socket
Harald Hoyer 2265b4
 ConditionPathExists=/etc/initrd-release
Harald Hoyer 2265b4
 
Harald Hoyer 2265b4
 [Service]
Harald Hoyer 2265b4
-Environment=HOME=/
Harald Hoyer 2265b4
-WorkingDirectory=/
Harald Hoyer 2265b4
-ExecStart=-/bin/dracut-cmdline
Harald Hoyer 2265b4
 Type=oneshot
Harald Hoyer 2265b4
+ExecStart=-/bin/dracut-cmdline
Harald Hoyer 2265b4
 StandardInput=null
Harald Hoyer 2265b4
 StandardOutput=syslog
Harald Hoyer 2265b4
 StandardError=syslog+console
Harald Hoyer 2265b4
diff --git a/modules.d/98systemd/dracut-initqueue.service b/modules.d/98systemd/dracut-initqueue.service
Harald Hoyer 2265b4
index 5168677..e611e93 100644
Harald Hoyer 2265b4
--- a/modules.d/98systemd/dracut-initqueue.service
Harald Hoyer 2265b4
+++ b/modules.d/98systemd/dracut-initqueue.service
Harald Hoyer 2265b4
@@ -15,10 +15,8 @@ Wants=systemd-udev-trigger.service
Harald Hoyer 2265b4
 ConditionPathExists=/etc/initrd-release
Harald Hoyer 2265b4
 
Harald Hoyer 2265b4
 [Service]
Harald Hoyer 2265b4
-Environment=HOME=/
Harald Hoyer 2265b4
-WorkingDirectory=/
Harald Hoyer 2265b4
+Type=oneshot
Harald Hoyer 2265b4
 ExecStart=-/bin/dracut-initqueue
Harald Hoyer 2265b4
-Type=simple
Harald Hoyer 2265b4
 StandardInput=null
Harald Hoyer 2265b4
 StandardOutput=syslog
Harald Hoyer 2265b4
 StandardError=syslog+console
Harald Hoyer 2265b4
diff --git a/modules.d/98systemd/dracut-initqueue.sh b/modules.d/98systemd/dracut-initqueue.sh
Harald Hoyer 2265b4
index bc63582..cfdb12d 100755
Harald Hoyer 2265b4
--- a/modules.d/98systemd/dracut-initqueue.sh
Harald Hoyer 2265b4
+++ b/modules.d/98systemd/dracut-initqueue.sh
Harald Hoyer 2265b4
@@ -106,5 +106,4 @@ done
Harald Hoyer 2265b4
 
Harald Hoyer 2265b4
 export -p > /dracut-state.sh
Harald Hoyer 2265b4
 
Harald Hoyer 2265b4
-systemctl isolate initrd-switch-root.target
Harald Hoyer 2265b4
 exit 0
Harald Hoyer 2265b4
diff --git a/modules.d/98systemd/dracut-pre-pivot.service b/modules.d/98systemd/dracut-pre-pivot.service
Harald Hoyer 2265b4
index 27cb7de..61257cf 100644
Harald Hoyer 2265b4
--- a/modules.d/98systemd/dracut-pre-pivot.service
Harald Hoyer 2265b4
+++ b/modules.d/98systemd/dracut-pre-pivot.service
Harald Hoyer 2265b4
@@ -10,14 +10,13 @@
Harald Hoyer 2265b4
 [Unit]
Harald Hoyer 2265b4
 Description=Dracut pre-pivot and cleanup hook
Harald Hoyer 2265b4
 DefaultDependencies=no
Harald Hoyer 2265b4
-Before=initrd-switch-root.service
Harald Hoyer 2265b4
+After=dracut-initqueue.service
Harald Hoyer 2265b4
 ConditionPathExists=/etc/initrd-release
Harald Hoyer 2265b4
 
Harald Hoyer 2265b4
 [Service]
Harald Hoyer 2265b4
-Environment=HOME=/
Harald Hoyer 2265b4
-WorkingDirectory=/
Harald Hoyer 2265b4
-ExecStart=-/bin/dracut-pre-pivot
Harald Hoyer 2265b4
 Type=oneshot
Harald Hoyer 2265b4
+ExecStart=-/bin/dracut-pre-pivot
Harald Hoyer 2265b4
+ExecStopPost=-/usr/bin/systemctl isolate initrd-switch-root.target
Harald Hoyer 2265b4
 StandardInput=null
Harald Hoyer 2265b4
 StandardOutput=syslog
Harald Hoyer 2265b4
 StandardError=syslog+console
Harald Hoyer 2265b4
diff --git a/modules.d/98systemd/dracut-pre-pivot.sh b/modules.d/98systemd/dracut-pre-pivot.sh
Harald Hoyer 2265b4
index 06642d0..31dded5 100755
Harald Hoyer 2265b4
--- a/modules.d/98systemd/dracut-pre-pivot.sh
Harald Hoyer 2265b4
+++ b/modules.d/98systemd/dracut-pre-pivot.sh
Harald Hoyer 2265b4
@@ -34,20 +34,9 @@ done
Harald Hoyer 2265b4
 
Harald Hoyer 2265b4
 echo "NEWROOT=\"$NEWROOT\"" >> /run/initramfs/switch-root.conf
Harald Hoyer 2265b4
 
Harald Hoyer 2265b4
-udevadm control --stop-exec-queue
Harald Hoyer 2265b4
-
Harald Hoyer 2265b4
-for i in systemd-udevd.service; do
Harald Hoyer 2265b4
-    systemctl is-active $i >/dev/null 2>&1 && systemctl stop $i
Harald Hoyer 2265b4
-done
Harald Hoyer 2265b4
-
Harald Hoyer 2265b4
-udevadm info --cleanup-db
Harald Hoyer 2265b4
-
Harald Hoyer 2265b4
 # remove helper symlink
Harald Hoyer 2265b4
 [ -h /dev/root ] && rm -f /dev/root
Harald Hoyer 2265b4
 
Harald Hoyer 2265b4
 getarg rd.break rdbreak && emergency_shell -n switch_root "Break before switch_root"
Harald Hoyer 2265b4
 
Harald Hoyer 2265b4
-cp -avr /lib/systemd/system/dracut*.service /run/systemd/system/
Harald Hoyer 2265b4
-
Harald Hoyer 2265b4
-export -p > /dracut-state.sh
Harald Hoyer 2265b4
 exit 0
Harald Hoyer 2265b4
diff --git a/modules.d/98systemd/dracut-pre-trigger.service b/modules.d/98systemd/dracut-pre-trigger.service
Harald Hoyer 2265b4
index 86c7c5e..b2dcf68 100644
Harald Hoyer 2265b4
--- a/modules.d/98systemd/dracut-pre-trigger.service
Harald Hoyer 2265b4
+++ b/modules.d/98systemd/dracut-pre-trigger.service
Harald Hoyer 2265b4
@@ -16,10 +16,8 @@ Wants=dracut-pre-udev.service systemd-udevd.service
Harald Hoyer 2265b4
 ConditionPathExists=/etc/initrd-release
Harald Hoyer 2265b4
 
Harald Hoyer 2265b4
 [Service]
Harald Hoyer 2265b4
-Environment=HOME=/
Harald Hoyer 2265b4
-WorkingDirectory=/
Harald Hoyer 2265b4
-ExecStart=-/bin/dracut-pre-trigger
Harald Hoyer 2265b4
 Type=oneshot
Harald Hoyer 2265b4
+ExecStart=-/bin/dracut-pre-trigger
Harald Hoyer 2265b4
 StandardInput=null
Harald Hoyer 2265b4
 StandardOutput=syslog
Harald Hoyer 2265b4
 StandardError=syslog+console
Harald Hoyer 2265b4
diff --git a/modules.d/98systemd/dracut-pre-udev.service b/modules.d/98systemd/dracut-pre-udev.service
Harald Hoyer 2265b4
index a320498..cc14f88 100644
Harald Hoyer 2265b4
--- a/modules.d/98systemd/dracut-pre-udev.service
Harald Hoyer 2265b4
+++ b/modules.d/98systemd/dracut-pre-udev.service
Harald Hoyer 2265b4
@@ -16,10 +16,8 @@ Wants=dracut-cmdline.service
Harald Hoyer 2265b4
 ConditionPathExists=/etc/initrd-release
Harald Hoyer 2265b4
 
Harald Hoyer 2265b4
 [Service]
Harald Hoyer 2265b4
-Environment=HOME=/
Harald Hoyer 2265b4
-WorkingDirectory=/
Harald Hoyer 2265b4
-ExecStart=-/bin/dracut-pre-udev
Harald Hoyer 2265b4
 Type=oneshot
Harald Hoyer 2265b4
+ExecStart=-/bin/dracut-pre-udev
Harald Hoyer 2265b4
 StandardInput=null
Harald Hoyer 2265b4
 StandardOutput=syslog
Harald Hoyer 2265b4
 StandardError=syslog+console
Harald Hoyer 2265b4
diff --git a/modules.d/98systemd/initrd-switch-root.service b/modules.d/98systemd/initrd-switch-root.service
Harald Hoyer 2265b4
index b00292f..84fc11e 100644
Harald Hoyer 2265b4
--- a/modules.d/98systemd/initrd-switch-root.service
Harald Hoyer 2265b4
+++ b/modules.d/98systemd/initrd-switch-root.service
Harald Hoyer 2265b4
@@ -9,9 +9,13 @@
Harald Hoyer 2265b4
 Description=Switch Root
Harald Hoyer 2265b4
 DefaultDependencies=no
Harald Hoyer 2265b4
 ConditionPathExists=/etc/initrd-release
Harald Hoyer 2265b4
+OnFailure=emergency.service
Harald Hoyer 2265b4
 
Harald Hoyer 2265b4
 [Service]
Harald Hoyer 2265b4
 Type=oneshot
Harald Hoyer 2265b4
 EnvironmentFile=/run/initramfs/switch-root.conf
Harald Hoyer 2265b4
 ExecStart=/usr/bin/systemctl --force switch-root ${NEWROOT} ${NEWINIT}
Harald Hoyer 2265b4
-ExecStopPost=-/usr/bin/systemctl isolate default.target
Harald Hoyer 2265b4
+ExecStopPost=-/usr/bin/systemctl restart systemd-journald.service
Harald Hoyer 2265b4
+StandardInput=null
Harald Hoyer 2265b4
+StandardOutput=null
Harald Hoyer 2265b4
+StandardError=null
Harald Hoyer 2265b4
diff --git a/modules.d/98systemd/initrd-switch-root.target b/modules.d/98systemd/initrd-switch-root.target
Harald Hoyer 2265b4
index 5f39711..feb7162 100644
Harald Hoyer 2265b4
--- a/modules.d/98systemd/initrd-switch-root.target
Harald Hoyer 2265b4
+++ b/modules.d/98systemd/initrd-switch-root.target
Harald Hoyer 2265b4
@@ -13,4 +13,4 @@ DefaultDependencies=no
Harald Hoyer 2265b4
 Requires=initrd-switch-root.service
Harald Hoyer 2265b4
 Before=initrd-switch-root.service
Harald Hoyer 2265b4
 AllowIsolate=yes
Harald Hoyer 2265b4
-
Harald Hoyer 2265b4
+Wants=systemd-journald.service
Harald Hoyer 2265b4
diff --git a/modules.d/98systemd/module-setup.sh b/modules.d/98systemd/module-setup.sh
Harald Hoyer 2265b4
index 0387ec4..f9bb799 100755
Harald Hoyer 2265b4
--- a/modules.d/98systemd/module-setup.sh
Harald Hoyer 2265b4
+++ b/modules.d/98systemd/module-setup.sh
Harald Hoyer 2265b4
@@ -63,7 +63,7 @@ install() {
Harald Hoyer 2265b4
         $systemdsystemunitdir/systemd-ask-password-console.service \
Harald Hoyer 2265b4
         $systemdsystemunitdir/halt.service \
Harald Hoyer 2265b4
         $systemdsystemunitdir/poweroff.service \
Harald Hoyer 2265b4
-        $systemdsystemunitdir/reboot.service \
Harald Hoyer 2265b4
+        $systemdsystemunitdir/systemd-reboot.service \
Harald Hoyer 2265b4
         $systemdsystemunitdir/kexec.service \
Harald Hoyer 2265b4
         $systemdsystemunitdir/fsck@.service \
Harald Hoyer 2265b4
         $systemdsystemunitdir/systemd-udevd.service \
Harald Hoyer 2265b4
@@ -142,8 +142,12 @@ install() {
Harald Hoyer 2265b4
 
Harald Hoyer 2265b4
     inst_script "$moddir/dracut-pre-pivot.sh" /bin/dracut-pre-pivot
Harald Hoyer 2265b4
     inst_simple "$moddir/dracut-pre-pivot.service" ${systemdsystemunitdir}/dracut-pre-pivot.service
Harald Hoyer 2265b4
-    mkdir -p "${initdir}${systemdsystemunitdir}/initrd-switch-root.target.wants"
Harald Hoyer 2265b4
-    ln -fs ../dracut-pre-pivot.service "${initdir}${systemdsystemunitdir}/initrd-switch-root.target.wants/dracut-pre-pivot.service"
Harald Hoyer 2265b4
+    ln -fs ../dracut-pre-pivot.service "${initdir}${systemdsystemunitdir}/basic.target.wants/dracut-pre-pivot.service"
Harald Hoyer 2265b4
 
Harald Hoyer 2265b4
+    inst_simple "$moddir/udevadm-cleanup-db.service" ${systemdsystemunitdir}/udevadm-cleanup-db.service
Harald Hoyer 2265b4
+    mkdir -p "${initdir}${systemdsystemunitdir}/initrd-switch-root.target.requires"
Harald Hoyer 2265b4
+    ln -fs ../udevadm-cleanup-db.service "${initdir}${systemdsystemunitdir}/initrd-switch-root.target.requires/udevadm-cleanup-db.service"
Harald Hoyer 2265b4
+
Harald Hoyer 2265b4
+    inst_script "$moddir/service-to-run.sh" $systemdutildir/system-generators/service-to-run
Harald Hoyer 2265b4
 }
Harald Hoyer 2265b4
 
Harald Hoyer 2265b4
diff --git a/modules.d/98systemd/service-to-run.sh b/modules.d/98systemd/service-to-run.sh
Harald Hoyer 2265b4
new file mode 100755
Harald Hoyer 2265b4
index 0000000..3e46ba4
Harald Hoyer 2265b4
--- /dev/null
Harald Hoyer 2265b4
+++ b/modules.d/98systemd/service-to-run.sh
Harald Hoyer 2265b4
@@ -0,0 +1,6 @@
Harald Hoyer 2265b4
+#!/bin/sh
Harald Hoyer 2265b4
+
Harald Hoyer 2265b4
+cp -a /lib/systemd/system/dracut*.service /run/systemd/system/
Harald Hoyer 2265b4
+cp -a /lib/systemd/system/initrd-* /run/systemd/system/
Harald Hoyer 2265b4
+cp -a /lib/systemd/system/udevadm*.service /run/systemd/system/
Harald Hoyer 2265b4
+
Harald Hoyer 2265b4
diff --git a/modules.d/98systemd/udevadm-cleanup-db.service b/modules.d/98systemd/udevadm-cleanup-db.service
Harald Hoyer 2265b4
new file mode 100644
Harald Hoyer 2265b4
index 0000000..368a0dd
Harald Hoyer 2265b4
--- /dev/null
Harald Hoyer 2265b4
+++ b/modules.d/98systemd/udevadm-cleanup-db.service
Harald Hoyer 2265b4
@@ -0,0 +1,20 @@
Harald Hoyer 2265b4
+#  This file is part of systemd.
Harald Hoyer 2265b4
+#
Harald Hoyer 2265b4
+#  systemd is free software; you can redistribute it and/or modify it
Harald Hoyer 2265b4
+#  under the terms of the GNU Lesser General Public License as published by
Harald Hoyer 2265b4
+#  the Free Software Foundation; either version 2.1 of the License, or
Harald Hoyer 2265b4
+#  (at your option) any later version.
Harald Hoyer 2265b4
+
Harald Hoyer 2265b4
+[Unit]
Harald Hoyer 2265b4
+Description=Cleanup udevd DB
Harald Hoyer 2265b4
+DefaultDependencies=no
Harald Hoyer 2265b4
+ConditionPathExists=/etc/initrd-release
Harald Hoyer 2265b4
+Conflicts=systemd-udevd.service systemd-udevd-control.socket systemd-udevd-kernel.socket
Harald Hoyer 2265b4
+Before=initrd-switch-root.service
Harald Hoyer 2265b4
+
Harald Hoyer 2265b4
+[Service]
Harald Hoyer 2265b4
+Type=oneshot
Harald Hoyer 2265b4
+ExecStart=-/usr/bin/udevadm info --cleanup-db
Harald Hoyer 2265b4
+StandardInput=null
Harald Hoyer 2265b4
+StandardOutput=null
Harald Hoyer 2265b4
+StandardError=null