[Main]
Type = classic
Version = 0.1.0
Description = "mdadm daemon"
User = ( root )
Depends = ( devmanager mount-rw )
Options = ( log )

[Start]
Execute = (
	# mdadm --monitor in foreground (no --daemonise), matching debian/sv/mdadm.
	# Pause when disabled / no mdstat / no redundant arrays (no console restart storm).
	
	envfile -I /etc/default/mdadm
	importas -uD "true" START_DAEMON START_DAEMON
	importas -sCuD "" DAEMON_OPTIONS DAEMON_OPTIONS
	
	ifelse { test "${START_DAEMON}" = true } {
		ifelse { test -f /proc/mdstat } {
			ifelse { /etc/s6-rc/sv/mdadm-srv/has-redundant-md } {
				foreground { mkdir -p /run/mdadm }
				exec /sbin/mdadm ${Args} ${DAEMON_OPTIONS}
			}
			s6-pause
		}
		s6-pause
	}
	s6-pause
)

[Logger]
RunAs = s6log
Backup = 3
MaxSize = 2000000
Timestamp = tai
Destination = /var/log/mdadm-s6
