#!/bin/bash
#
# /etc/init.d/bnx2id
#
### BEGIN INIT INFO
# Provides:          bnx2id
# Required-Start:    $network
# Should-Start:
# Required-Stop:     
# Should-Stop:
# Default-Start:     3 4 5
# Default-Stop:      0 6
# Short-Description: Starts and stops the Broadcom iSCSI initiator components
#                    
### END INIT INFO

PID_FILE=/var/run/bnx2id.pid
DAEMON=/sbin/bnx2id
ARGS=""

# Source LSB init functions
. /etc/rc.status

# Reset status of this service
rc_reset

case "$1" in
    start)
	if checkproc $DAEMON ; then
	    RETVAL=0
	else
	    echo -n "Starting Broadcom iSCSI initiator software: "
	    modprobe bnx2i
	    startproc $DAEMON $ARGS
	    RETVAL=$?
	    rc_status -v
	fi
	;;
    stop)
	echo -n "Stopping Broadcom iSCSI initiator software: "
	rm -f $PID_FILE
	rmmod bnx2i
	rmmod cnic
	killproc $DAEMON
	rc_failed 0
	rc_status -v
	;;
    status)
	echo -n "Checking for Broadcom iSCSI initiator service: "
	if checkproc $DAEMON ; then
	    rc_status -v
	else
	    rc_failed 3
	    rc_status -v
	fi
	;;
    restart)
	$0 stop
	sleep 1
	$0 start
	;;
    *)
	echo "Usage: $0 {start|stop|status|restart}"
	exit 1
	;;
esac
rc_exit
