mchristi 8d52768
#!/bin/sh
mchristi 8d52768
#
d62d4b0
# chkconfig: 345 13 89
mchristi 8d52768
# description: Logs into iSCSI targets needed at system startup
mchristi 8d52768
#
48d880c
### BEGIN INIT INFO
48d880c
# Provides:          iscsi
48d880c
# Required-Start:    $network $iscsid
48d880c
# Required-Stop:     $network $iscsid
48d880c
# Short-Description: Starts and stops login and scanning of iSCSI devices.
48d880c
# Description: iscsi provides the iSCSI state machine for software iscsi/iser
48d880c
#              and partial offloaded hardware. iscsi logs into and scans
48d880c
#              for iSCSI devices, and shuts them down when stopped.
48d880c
### END INIT INFO
48d880c
#
mchristi 8d52768
# Source function library.
mchristi 8d52768
. /etc/init.d/functions
mchristi 8d52768
mchristi 8d52768
PATH=/sbin:/bin:/usr/sbin:/usr/bin
mchristi 8d52768
mchristi 8d52768
RETVAL=0
mchristi 8d52768
mchristi 8d52768
start()
mchristi 8d52768
{
48d880c
	if [ -f /var/lock/subsys/iscsi ] ; then
48d880c
		echo
48d880c
		success
48d880c
		return
48d880c
	fi
mchristi 8d52768
48d880c
	# Not sure if this is ok.
48d880c
	# It was done for compatiblity where users were used to
48d880c
	# just starting the iscsi service, but for root boot we
48d880c
	# need need iscsid start earlier than the devices we
48d880c
	# log into below.
mchristi 8d52768
	status iscsid
mchristi 8d52768
	RETVAL=$?
mchristi 8d52768
mchristi 8d52768
	if [ $RETVAL -ne 0 ]; then
mchristi 8d52768
		/etc/init.d/iscsid start
mchristi 8d52768
	fi
mchristi 8d52768
mchristi 8d52768
	# this script is normally called from startup so log into
mchristi 8d52768
	# nodes marked node.startup=automatic
mchristi 8d52768
	iscsiadm -m node --loginall=automatic
mchristi 8d52768
	touch /var/lock/subsys/iscsi
mchristi 8d52768
	success
mchristi 8d52768
	echo
mchristi 8d52768
}
mchristi 8d52768
9603323
cleanup_iscsi()
9603323
{
9603323
	/etc/init.d/iscsid stop
9603323
	rm -f /var/lock/subsys/iscsi
9603323
	success
9603323
}
9603323
mchristi 8d52768
stop()
mchristi 8d52768
{
48d880c
	if [ ! -f /var/lock/subsys/iscsi ]; then
48d880c
		echo
48d880c
		success
48d880c
		return
48d880c
	fi
mchristi 8d52768
9603323
	declare -a iparams=( $(iscsiadm -m session 2>/dev/null | egrep "tcp|iser") )
9603323
	if [[ -z "${iparams[*]}" ]]; then
9603323
		# no sessions so we can just quit
9603323
		cleanup_iscsi
9603323
		return
9603323
	fi
9603323
mchristi 8d52768
	# don't turn off iscsi if root is possibly on a iscsi disk
mchristi 8d52768
	rootopts=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $4; }}' /etc/mtab)
mchristi 8d52768
	if [[ "$rootopts" =~ "_netdev" ]] ; then
mchristi 8d52768
		echo $"Can not shutdown iSCSI. Root is on a iSCSI disk."
mchristi 8d52768
		exit 1
mchristi 8d52768
	fi
mchristi 8d52768
mchristi 8d52768
	iscsiadm -m node --logoutall=all
9603323
	cleanup_iscsi
mchristi 8d52768
}
mchristi 8d52768
mchristi 8d52768
case "$1" in
mchristi 8d52768
	start)
mchristi 8d52768
		start
mchristi 8d52768
		;;
mchristi 8d52768
	stop)
mchristi 8d52768
		stop
mchristi 8d52768
		;;
mchristi 8d52768
	restart)
mchristi 8d52768
		stop
mchristi 8d52768
		start
mchristi 8d52768
		;;
mchristi 8d52768
	status)
mchristi 8d52768
		status iscsid
mchristi 8d52768
		RETVAL=$?
mchristi 8d52768
		;;
mchristi 8d52768
	condrestart)
mchristi 8d52768
		[ -f /var/lock/subsys/iscsi ] && restart
mchristi 8d52768
		;;
mchristi 8d52768
	*)
mchristi 8d52768
		echo $"Usage: $0 {start|stop|restart|status|condrestart}"
mchristi 8d52768
		exit 1
mchristi 8d52768
esac
mchristi 8d52768
exit $RETVAL