#!/usr/bin/execlineb -P
# mdadm --monitor in foreground (no --daemonise), matching debian/sv/mdadm.

envfile -I /etc/default/mdadm
importas -uD "true" START_DAEMON START_DAEMON
importas -sCuD "" DAEMON_OPTIONS DAEMON_OPTIONS
envfile -I /etc/s6-rc/config/mdadm.conf
importas -sCuD "--monitor --scan" Args Args

ifelse { test "${START_DAEMON}" = true } {
	ifelse { test -f /proc/mdstat } {
		foreground { mkdir -p /run/mdadm }
		fdmove -c 2 1
		exec /sbin/mdadm ${Args} ${DAEMON_OPTIONS}
	}
	s6-pause
}
s6-pause
