#!/sbin/openrc-run

description="hd-idle"

pidfile="/run/$RC_SVCNAME.pid"
command="/usr/sbin/hd-idle"
command_args="-l $LOGFILE -i 0"
[ -n "$DISK_TYPE" ] && command_args="$command_args -c $DISK_TYPE"
command_background=yes

depend() {
	need localmount
	after modules
}

config_error() {
	ebegin "Starting $description"
	eend 1 "$1"
}

start_pre() {
	if [ -n "$DISK" ]; then
		case "$IDLE_TIME" in
			*[!0123456789]* )	config_error "IDLE_TIME value is invalid" ;;
			"" )	config_error "IDLE_TIME is not set" ;;
			"0" )	config_error "IDLE_TIME cannot be 0" ;;
			* )	command_args="$command_args -a $DISK -i $IDLE_TIME"
		esac
	fi
}
