Blob Blame Raw
#!/bin/sh
#
# chkconfig: 345 7 89
# description: Starts and stops the iSCSI daemon.
#
# processname: iscsid
# pidfile: /var/run/iscsid.pid
# config:  /etc/iscsi/iscsid.conf
#
### BEGIN INIT INFO
# Provides:          iscsid
# Required-Start:    $network
# Required-Stop:     $network
# Short-Description: Starts and stops login iSCSI daemon.
# Description: iscsid provides the iSCSI session and connection state machine
#              for software iscsi/iser (iscsi_tcp/ib_iser) and partialy
#              offloaded hardware (bnx2i).
### END INIT INFO
#
# Source function library.
. /etc/init.d/functions

PATH=/sbin:/bin:/usr/sbin:/usr/bin

RETVAL=0

start()
{
	if [ -f /var/lock/subsys/iscsid ] ; then
		echo
		success
		return
	fi

	echo -n $"Turning off network shutdown. "
	# we do not want iscsi or network to run during system shutdown
	# incase there are RAID or multipath devices using
	# iscsi disks
	chkconfig --level 06 network off
	rm /etc/rc0.d/*network
	rm /etc/rc6.d/*network

	echo -n $"Starting iSCSI daemon: "
	modprobe -q iscsi_tcp
	modprobe -q ib_iser
	daemon iscsid
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] || return

	touch /var/lock/subsys/iscsid

	success
	echo
}

stop()
{
	if [ ! -f /var/lock/subsys/iscsid ]; then
		echo
		success
		return
	fi

        # If this is a final shutdown/halt, do nothing since
        # we may need iscsid for as long as possible (halt script kills
	# us at the last second)
        if [ "$RUNLEVEL" = "6" -o "$RUNLEVEL" = "0" -o "$RUNLEVEL" = "1" ]; then
		rm -f /var/lock/subsys/iscsid
                success
                return
        fi

        # don't turn off iscsi if root is possibly on a iscsi disk
        rootopts=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $4; }}' /etc/mtab)
        if [[ "$rootopts" =~ "_netdev" ]] ; then
                echo $"Can not shutdown iSCSI. Root is on a iSCSI disk."
                exit 1
        fi

	echo -n $"Stopping iSCSI daemon: "
	killproc iscsid
	echo
        RETVAL=$?
        [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/iscsid

	modprobe -r ib_iser 2>/dev/null
	modprobe -r iscsi_tcp 2>/dev/null
}

restart()
{
	stop
	start
}

case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	restart)
	        stop
		start
		;;
	status)
		status iscsid
		RETVAL=$?
		;;
        condrestart)
	        [ -f /var/lock/subsys/iscsid ] && restart
		;;
	*)
		echo $"Usage: $0 {start|stop|restart|status|condrestart}"
		exit 1
esac

exit $RETVAL