#!/bin/bash

# try to load module in case that hasn't been done yet
modprobe dm-mod >/dev/null 2>&1

set -e

. /lib/lsb/init-functions
. /etc/default/rcS

[ -x /sbin/dmraid ] || exit 0

case "$1" in
	start|"")
		log_begin_msg "Setting up DMRAID devices..."
		if [ "$VERBOSE" != no ]; then
	                /sbin/dmraid --activate yes --ignorelocking --verbose
		else
	                /sbin/dmraid --activate yes --ignorelocking >/dev/null 2>&1
		fi
		log_end_msg $?
		;;

	stop)
		log_begin_msg "Shutting down DMRAID devices... "
		if [ "$VERBOSE" != no ]; then
			/sbin/dmraid --activate no --ignorelocking --verbose
		else
			/sbin/dmraid --activate no --ignorelocking >/dev/null 2>&1
		fi
		log_end_msg $?
		;;

	restart|force-reload)
		$0 stop
		sleep 1
		$0 start
		;;
	
	*)
		log_success_msg "Usage: dmraid {start|stop|restart|force-reload}"
		exit 1
		;;
esac
