#!/bin/sh
#
# 3dm2:     	Starts the 3ware daemon
#
# Author:       Michael Benz <linuxraid@lsi.com>
#
# chkconfig: 345 40 60
# description: Start the 3dm2 application which logs the current state
#              of the 3ware DiskSwitch controller card, and then polls
#              for state changes.
#
# processname: 3dm2
# config: /etc/3dm2/3dm2.conf

# Source function library.
. /etc/rc.d/init.d/functions

DAEMON=/usr/sbin/3dm2
RETVAL=0
LOCKFILE=/var/lock/subsys/3dm2

test -x $DAEMON || exit 1

# See how we were called.
case "$1" in
  start)
        if [ ! -f $LOCKFILE ]; then
		echo -n "Starting 3ware DiskSwitch daemon: "
		daemon $DAEMON && touch $LOCKFILE || RETVAL=1
		echo
	else
		echo "3dm2 must already be running, Found lock file $LOCKFILE"
		echo "Try manually running /etc/init.d/tdm2 restart"
	fi
	;;
  stop)
	echo -n "Stopping 3ware DiskSwitch daemon: "
	killproc $DAEMON && rm -f $LOCKFILE || RETVAL=1
        echo
	sleep 2
	;;
  status)
	status 3dm2 || RETVAL=1
	;;
  restart)
	$0 stop
	$0 start
	;;
  *)
	echo "Usage: $0 {start|stop|status|restart}"
	exit 1
esac

exit $RETVAL
