Blob Blame Raw
#!/bin/sh
#
# chkconfig: 345 13 89
# description: Starts and stops the iSCSI initiator
#
# processname: iscsid
# pidfile: /etc/iscsi/iscsid.pid
# config:  /etc/iscsi/iscsid.conf

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

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

RETVAL=0

start()
{
	echo -n $"Starting iSCSI initiator service: "
	modprobe -q iscsi_tcp
	daemon iscsid
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] || return

	touch /var/lock/subsys/iscsi

	echo -n $"Setting up iSCSI targets: "
	TARGETS=`iscsiadm -m node 2>/dev/null | sed 's/ /@/g'`
	for node in $TARGETS; do
		target=`echo $node | cut -d@ -f2`
		port=`echo $node | cut -d@ -f1`
		STARTUP=`iscsiadm -m node -T $target -p $port | grep "node.conn\[0\].startup" | cut -d' ' -f3`
		if [ "$STARTUP" = "automatic" ]; then
			iscsiadm -m node -T $target -p $port -l
		fi
	done
	success
	echo

}

stop()
{
	echo -n $"Stopping iSCSI initiator service: "
	sync
#	TARGETS=`iscsiadm -m session | grep "\[*\]" | sed 's@\[\(.*\)\] .*@\1@g'`
#	for rec in $TARGETS; do
#	    iscsiadm -m node -r $rec -u
#	done

	killproc iscsid
	echo
	[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/iscsi

	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/iscsi ] && restart
		;;
	*)
		echo $"Usage: $0 {start|stop|restart|status|condrestart}"
		exit 1
esac

exit $RETVAL