]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Systemd integration for starting newly-degraded arrays.
authorNeilBrown <neilb@suse.de>
Mon, 2 Dec 2013 05:08:04 +0000 (16:08 +1100)
committerNeilBrown <neilb@suse.de>
Mon, 2 Dec 2013 05:08:04 +0000 (16:08 +1100)
Normally "mdadm -I" will not start an array if it has reason to
expect further devices.
This means that if a device is removed while the host is shut down,
"mdadm -I" will never start the device.

If  the array is know to the host, it make sense to start the array
anyway after a reasonable timeout.

This patch adds systemd/udev infrastructure so that 30 seconds after
a known array first becomes able to be assembled as a degraded array,
the array will be assembled even if more devices are still expected.

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

index c60cc2cf20f2fd92d003f3f7ed86c4ad3b5820d2..ae4a04e7a76520d66748e7689223bae4450e4dd1 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -285,6 +285,8 @@ install-udev: udev-md-raid-arrays.rules udev-md-raid-assembly.rules
 
 install-systemd: systemd/mdmon@.service
        $(INSTALL) -D -m 644 systemd/mdmon@.service $(DESTDIR)$(SYSTEMD_DIR)/mdmon@.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
 
 uninstall:
        rm -f $(DESTDIR)$(MAN8DIR)/mdadm.8 $(DESTDIR)$(MAN8DIR)/mdmon.8 $(DESTDIR)$(MAN4DIR)/md.4 $(DESTDIR)$(MAN5DIR)/mdadm.conf.5 $(DESTDIR)$(BINDIR)/mdadm
diff --git a/systemd/mdadm-last-resort@.service b/systemd/mdadm-last-resort@.service
new file mode 100644 (file)
index 0000000..45d3c2a
--- /dev/null
@@ -0,0 +1,7 @@
+[Unit]
+Description=Activate md array even though degraded
+DefaultDependencies=no
+
+[Service]
+Type=oneshot
+ExecStart=/sbin/mdadm --run /dev/%i
diff --git a/systemd/mdadm-last-resort@.timer b/systemd/mdadm-last-resort@.timer
new file mode 100644 (file)
index 0000000..6a1cd56
--- /dev/null
@@ -0,0 +1,6 @@
+[Unit]
+Description=Timer to wait for more drives before activating degraded array.
+DefaultDependencies=no
+
+[Timer]
+OnActiveSec=30
index b653265872304a7fce892f17f14ac0d37f12175c..72bbed4d599c49d80cb79b8cfa139ac46cae092c 100644 (file)
@@ -12,7 +12,8 @@ LABEL="md_inc"
 
 # remember you can limit what gets auto/incrementally assembled by
 # mdadm.conf(5)'s 'AUTO' and selectively whitelist using 'ARRAY'
-ACTION=="add", RUN+="/sbin/mdadm --incremental $devnode --offroot"
+ACTION=="add", IMPORT{program}="/sbin/mdadm --incremental --export $devnode --offroot"
+ACTION=="add", ENV{MD_STARTED}=="*unsafe*", ENV{MD_FOREIGN}=="no", ENV{SYSTEMD_WANTS}+="mdadm-last-resort@$env{MD_DEVICE}.timer"
 ACTION=="remove", ENV{ID_PATH}=="?*", RUN+="/sbin/mdadm -If $name --path $env{ID_PATH}"
 ACTION=="remove", ENV{ID_PATH}!="?*", RUN+="/sbin/mdadm -If $name"