2015-10-15 10:23:26 +00:00
|
|
|
#!/bin/sh /etc/rc.common
|
|
|
|
|
|
|
|
START=13
|
|
|
|
STOP=98
|
|
|
|
|
|
|
|
USE_PROCD=1
|
|
|
|
PROG=/sbin/mdadm
|
|
|
|
NAME=mdadm
|
|
|
|
|
2017-02-09 12:22:47 +00:00
|
|
|
CONF="/var/etc/mdadm.conf"
|
|
|
|
|
|
|
|
append_list_item() {
|
|
|
|
append "$2" "$1" "$3"
|
|
|
|
}
|
|
|
|
|
|
|
|
append_option() {
|
|
|
|
local var="$1"
|
|
|
|
local cfg="$2"
|
|
|
|
local opt="$3"
|
|
|
|
local name="$4"
|
|
|
|
local sep="$5"
|
|
|
|
local str
|
|
|
|
|
|
|
|
if [ -n "$sep" ]; then
|
|
|
|
config_list_foreach "$cfg" "$opt" append_list_item str "$sep"
|
|
|
|
else
|
|
|
|
config_get str "$cfg" "$opt"
|
|
|
|
fi
|
|
|
|
|
|
|
|
[ -n "$str" ] && append "$var" $(printf "%s=%s" "${name:-${opt//_/-}}" "$str")
|
|
|
|
}
|
|
|
|
|
|
|
|
mdadm_common() {
|
|
|
|
local cfg="$1"
|
|
|
|
local email devices
|
|
|
|
|
|
|
|
if [ -x /sbin/sendmail ]; then
|
|
|
|
append_option email "$cfg" email "MAILADDR"
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
append_option devices "$cfg" devices DEVICE " "
|
|
|
|
|
|
|
|
printf "%s\n%s\n" "$email" "$devices" >> $CONF
|
|
|
|
}
|
|
|
|
|
|
|
|
mdadm_array() {
|
2015-10-15 10:23:26 +00:00
|
|
|
local cfg="$1"
|
2017-02-09 12:22:47 +00:00
|
|
|
local uuid device devices name array
|
|
|
|
|
|
|
|
config_get uuid "$cfg" uuid
|
|
|
|
config_get name "$cfg" name
|
|
|
|
config_get device "$cfg" device
|
|
|
|
|
|
|
|
if [ -z "$device" ] || [ -z "$uuid$name" ]; then
|
|
|
|
echo "Skipping array without device, uuid or name" >&2
|
2015-10-15 10:23:26 +00:00
|
|
|
return
|
|
|
|
fi
|
2017-02-09 12:22:47 +00:00
|
|
|
|
|
|
|
[ -n "$uuid" ] && append array "uuid=$uuid"
|
|
|
|
[ -n "$name" ] && append array "name=$name"
|
|
|
|
|
|
|
|
append_option array "$cfg" super_minor
|
|
|
|
append_option array "$cfg" spares
|
|
|
|
append_option array "$cfg" spare_group
|
|
|
|
append_option array "$cfg" bitmap
|
|
|
|
append_option array "$cfg" container
|
|
|
|
append_option array "$cfg" member
|
|
|
|
append_option array "$cfg" devices devices ","
|
|
|
|
|
|
|
|
printf "ARRAY %s %s\n" "$device" "$array" >> $CONF
|
2015-10-15 10:23:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
start_service() {
|
|
|
|
local email
|
|
|
|
|
2017-02-09 12:22:47 +00:00
|
|
|
mkdir -p "${CONF%/*}"
|
|
|
|
printf "# Autogenerated from /etc/config/mdadm, do not edit!\n" > $CONF
|
|
|
|
|
2015-10-15 10:23:26 +00:00
|
|
|
config_load mdadm
|
2017-02-09 12:22:47 +00:00
|
|
|
config_foreach mdadm_common mdadm
|
|
|
|
config_foreach mdadm_array array
|
2015-10-15 10:23:26 +00:00
|
|
|
|
2017-02-09 12:22:47 +00:00
|
|
|
$PROG --assemble --scan --config="$CONF"
|
2015-10-15 10:23:26 +00:00
|
|
|
|
|
|
|
procd_open_instance
|
2017-02-09 12:22:47 +00:00
|
|
|
procd_set_param command "$PROG" --monitor --syslog --scan --config="$CONF"
|
2015-10-15 10:23:26 +00:00
|
|
|
procd_close_instance
|
|
|
|
}
|
|
|
|
|
|
|
|
stop_service() {
|
|
|
|
$PROG --stop --scan
|
|
|
|
}
|
|
|
|
|