mchristi 63a314
#!/bin/sh
mchristi 63a314
#
d3d856
# chkconfig: 345 13 89
mchristi 63a314
# description: Logs into iSCSI targets needed at system startup
mchristi 63a314
#
mchristi 63a314
# Source function library.
mchristi 63a314
. /etc/init.d/functions
mchristi 63a314
mchristi 63a314
PATH=/sbin:/bin:/usr/sbin:/usr/bin
mchristi 63a314
mchristi 63a314
RETVAL=0
mchristi 63a314
mchristi 63a314
start()
mchristi 63a314
{
mchristi 63a314
mchristi 63a314
	status iscsid
mchristi 63a314
	RETVAL=$?
mchristi 63a314
mchristi 63a314
	if [ $RETVAL -ne 0 ]; then
mchristi 63a314
		/etc/init.d/iscsid start
mchristi 63a314
	fi
mchristi 63a314
mchristi 63a314
	echo -n $"Setting up iSCSI targets: "
mchristi 63a314
	# this script is normally called from startup so log into
mchristi 63a314
	# nodes marked node.startup=automatic
mchristi 63a314
	iscsiadm -m node --loginall=automatic
mchristi 63a314
	touch /var/lock/subsys/iscsi
mchristi 63a314
	success
mchristi 63a314
	echo
mchristi 63a314
}
mchristi 63a314
mchristi 63a314
stop()
mchristi 63a314
{
mchristi 63a314
	rm -f /var/lock/subsys/iscsi
mchristi 63a314
mchristi 63a314
	# If this is a final shutdown/halt, do nothing since
mchristi 63a314
	# lvm/dm, md, power path, etc do not always handle this
mchristi 63a314
	if [ "$RUNLEVEL" = "6" -o "$RUNLEVEL" = "0" -o "$RUNLEVEL" = "1" ]; then
mchristi 63a314
		success
mchristi 63a314
		return
mchristi 63a314
	fi
mchristi 63a314
mchristi 63a314
	# don't turn off iscsi if root is possibly on a iscsi disk
mchristi 63a314
	rootopts=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $4; }}' /etc/mtab)
mchristi 63a314
	if [[ "$rootopts" =~ "_netdev" ]] ; then
mchristi 63a314
		echo $"Can not shutdown iSCSI. Root is on a iSCSI disk."
mchristi 63a314
		exit 1
mchristi 63a314
	fi
mchristi 63a314
mchristi 63a314
	iscsiadm -m node --logoutall=all
mchristi 63a314
	/etc/init.d/iscsid stop
mchristi 63a314
	success
mchristi 63a314
}
mchristi 63a314
mchristi 63a314
case "$1" in
mchristi 63a314
	start)
mchristi 63a314
		start
mchristi 63a314
		;;
mchristi 63a314
	stop)
mchristi 63a314
		stop
mchristi 63a314
		;;
mchristi 63a314
	restart)
mchristi 63a314
		stop
mchristi 63a314
		start
mchristi 63a314
		;;
mchristi 63a314
	status)
mchristi 63a314
		status iscsid
mchristi 63a314
		RETVAL=$?
mchristi 63a314
		;;
mchristi 63a314
	condrestart)
mchristi 63a314
		[ -f /var/lock/subsys/iscsi ] && restart
mchristi 63a314
		;;
mchristi 63a314
	*)
mchristi 63a314
		echo $"Usage: $0 {start|stop|restart|status|condrestart}"
mchristi 63a314
		exit 1
mchristi 63a314
esac
mchristi 63a314
exit $RETVAL