]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
systemd: various fixes for boot with container-arrays.
authorNeilBrown <neilb@suse.de>
Tue, 8 Apr 2014 07:22:18 +0000 (17:22 +1000)
committerNeilBrown <neilb@suse.de>
Tue, 8 Apr 2014 07:37:08 +0000 (17:37 +1000)
1/ Add systemd shutdown script to ensure DDF and IMSM are
   clean before we actually shutdown

2/ Get udev to tell systemd to run the mdmon@mdXXX.service
   units when a member array appears.

   If we boot off a member array (with dracut at least),
   the mdmon started in the initramfs will lose track of
   /sys etc, so we need to restart it.
   systemd will try to forget about it too (but not actually
   kill it because we said not to do this).
   Having udev tell it to start it will allow a new mdmon to
   run which can see /sys, and systemd will know about it.

3/ Always use --offroot and --takeover when starting mdmon with
   systemd
   --offroot is needed else shutdown will hang.
   --takeover is needed incase an mdmon was started earlier
   (e.g. in initramfs).
   Neither hurt if they aren't actually needed.

Signed-off-by: NeilBrown <neilb@suse.de>
Makefile
systemd/mdadm.shutdown [new file with mode: 0644]
systemd/mdmon@.service
udev-md-raid-arrays.rules

index ff4efba42ef2e4463eb7eac07f6404ca4c66c420..b823d85f89e313c6095f9e4d312fb3817aa58e74 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -288,6 +288,7 @@ install-systemd: systemd/mdmon@.service
        $(INSTALL) -D -m 644 systemd/mdmonitor.service $(DESTDIR)$(SYSTEMD_DIR)/mdmonitor.service
        $(INSTALL) -D -m 644 systemd/mdadm-last-resort@.timer $(DESTDIR)$(SYSTEMD_DIR)/mdadm-last-resort@.timer
        $(INSTALL) -D -m 644 systemd/mdadm-last-resort@.service $(DESTDIR)$(SYSTEMD_DIR)/mdadm-last-resort@.service
+       $(INSTALL) -D -m 755 systemd/mdadm.shutdown $(DESTDIR)$(SYSTEMD_DIR)-shutdown/mdadm.shutdown
        if [ -f /etc/SuSE-release -o -n "$(SUSE)" ] ;then $(INSTALL) -D -m 755 systemd/SUSE-mdadm_env.sh $(DESTDIR)$(SYSTEMD_DIR)/../scripts/mdadm_env.sh ;fi
 
 uninstall:
diff --git a/systemd/mdadm.shutdown b/systemd/mdadm.shutdown
new file mode 100644 (file)
index 0000000..1bbbb6f
--- /dev/null
@@ -0,0 +1,4 @@
+#!/bin/sh
+# We need to ensure all md arrays with external metadata
+# (e.g. IMSM, DDF) are clean before completing the shutdown.
+/sbin/mdadm --wait-clean --scan
index 304b26e890c704a211cab889438ded98b0564ff9..af0a2a33c80a0b00ddcd91c0918757d7697d4e6a 100644 (file)
@@ -14,7 +14,15 @@ Before=initrd-switch-root.target
 # mdmon should never complain due to lack of a platform,
 # that is mdadm's job if at all.
 Environment=IMSM_NO_PLATFORM=1
-ExecStart=/sbin/mdmon %I
+# The mdmon starting in the initramfs (with dracut at least)
+# cannot see sysfs after root is mounted, so we will have to
+# 'takeover'.  As the '--offroot --takeover' don't hurt when
+# not necessary, are are useful with root-on-md in dracut,
+# have them always present.
+ExecStart=/sbin/mdmon --offroot --takeover %I
 Type=forking
-PIDFile=/run/mdadm/%I.pid
+# Don't set the PIDFile.  It isn't necessary (systemd can work
+# it out) and systemd will remove it when transitioning from
+# initramfs to rootfs.
+#PIDFile=/run/mdadm/%I.pid
 KillMode=none
index 4abbe354393cdd19737ada11dffa28a003217442..92aec36e69d4b67789e74dab049882937230da3e 100644 (file)
@@ -34,4 +34,8 @@ ENV{ID_FS_USAGE}=="filesystem|other", ENV{ID_FS_LABEL_ENC}=="?*", SYMLINK+="disk
 
 ENV{MD_LEVEL}=="raid[1-9]*", ENV{SYSTEMD_WANTS}+="mdmonitor.service"
 
+# Tell systemd to run mdmon for our container, if we need it.
+ENV{MD_LEVEL}=="raid[1-9]*", ENV{MD_CONTAINER}=="?*", PROGRAM="/usr/bin/readlink $env{MD_CONTAINER}", ENV{MD_MON_THIS}="%c"
+ENV{MD_MON_THIS}=="?*", PROGRAM="/usr/bin/basename $env{MD_MON_THIS}", ENV{SYSTEMD_WANTS}+="mdmon@%c.service"
+
 LABEL="md_end"