summaryrefslogtreecommitdiff
path: root/user/mdadm/mdadm-raid.initd
diff options
context:
space:
mode:
authorA. Wilcox <AWilcox@Wilcox-Tech.com>2018-08-02 08:15:40 +0000
committerA. Wilcox <AWilcox@Wilcox-Tech.com>2018-08-02 08:15:40 +0000
commit2690d595a5cb78777d8c12aca212ac386cbfbe1d (patch)
tree0cf9e8510b869d2e38ab3bf2b4f165e7d535f569 /user/mdadm/mdadm-raid.initd
parenta3758819aee2547f93c1234e042b8b839dcd2be8 (diff)
downloadpackages-2690d595a5cb78777d8c12aca212ac386cbfbe1d.tar.gz
packages-2690d595a5cb78777d8c12aca212ac386cbfbe1d.tar.bz2
packages-2690d595a5cb78777d8c12aca212ac386cbfbe1d.tar.xz
packages-2690d595a5cb78777d8c12aca212ac386cbfbe1d.zip
user/mdadm: pull in from Alpine, fix up, requested by @Elizafox
Diffstat (limited to 'user/mdadm/mdadm-raid.initd')
-rw-r--r--user/mdadm/mdadm-raid.initd48
1 files changed, 48 insertions, 0 deletions
diff --git a/user/mdadm/mdadm-raid.initd b/user/mdadm/mdadm-raid.initd
new file mode 100644
index 000000000..368860ae0
--- /dev/null
+++ b/user/mdadm/mdadm-raid.initd
@@ -0,0 +1,48 @@
+#!/sbin/openrc-run
+
+# script to start raid devices described in /etc/mdadm.conf.
+depend() {
+ before checkfs fsck swap
+ after modules
+}
+
+array_devices() {
+ awk '/^ARRAY/ {print $2}' /etc/mdadm.conf
+}
+
+start() {
+ [ -f /etc/mdadm.conf ] || return 0
+ # start all devices that are not already started
+ [ -f /proc/mdstat ] || modprobe md > /dev/null 2>&1
+ local tostart=
+ for i in $(array_devices); do
+ [ -b "$i" ] && continue
+ tostart="$tostart $i"
+ done
+ [ -z "$tostart" ] && return 0
+
+ ebegin "Starting RAID devices"
+ mdadm --assemble --scan --quiet $tostart
+ eend $?
+}
+
+is_mounted_as() {
+ local mnt
+ for mnt in $(awk "\$1 == \"$1\" {print \$2}" /proc/mounts); do
+ [ "$mnt" = "$2" ] && return 0
+ done
+ return 1
+}
+
+stop() {
+ # stop all raid devices except anything mounted as /
+ [ -f /etc/mdadm.conf ] || return 0
+ ebegin "Stopping RAID devices"
+ local tostop=
+ for i in $(array_devices); do
+ is_mounted_as $i / && continue
+ tostop="$tostop $i"
+ done
+ mdadm --stop --quiet $tostop
+ eend $?
+}