aboutsummaryrefslogtreecommitdiffstats
path: root/main/mdadm/mdadm-raid.initd
blob: d2479737cd4705b37800c5244ab4036b69a1aa5f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/sbin/runscript

# script to start raid devices described in /etc/mdadm.conf.
depend() {
	before checkfs fsck
	after modules
}

start() {
	[ -f /etc/mdadm.conf ] || return 0
	# start all devices that are not already started
	[ -f /proc/mdstat ] || modprobe -k md > /dev/null 2>&1
	local tostart=
	ebegin "Starting RAID devices"
	for i in $(awk '{print $2}' /etc/mdadm.conf); do
		[ -b "$i" ] && continue
		tostart="$tostart $i"
	done		
	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 $(awk '{print $2}' /etc/mdadm.conf); do
		is_mounted_as $i / && continue
		tostop="$tostop $i"
	done
	mdadm --stop --quiet $tostop
	eend $?
}