2007-03-20 19:39:20 +00:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
2007-10-05 07:40:40 +00:00
|
|
|
# chkconfig: 345 13 89
|
2007-03-20 19:39:20 +00:00
|
|
|
# description: Logs into iSCSI targets needed at system startup
|
|
|
|
#
|
2008-02-06 21:02:29 +00:00
|
|
|
### BEGIN INIT INFO
|
|
|
|
# Provides: iscsi
|
|
|
|
# Required-Start: $network $iscsid
|
|
|
|
# Required-Stop: $network $iscsid
|
|
|
|
# Short-Description: Starts and stops login and scanning of iSCSI devices.
|
|
|
|
# Description: iscsi provides the iSCSI state machine for software iscsi/iser
|
|
|
|
# and partial offloaded hardware. iscsi logs into and scans
|
|
|
|
# for iSCSI devices, and shuts them down when stopped.
|
|
|
|
### END INIT INFO
|
|
|
|
#
|
2007-03-20 19:39:20 +00:00
|
|
|
# Source function library.
|
|
|
|
. /etc/init.d/functions
|
|
|
|
|
|
|
|
PATH=/sbin:/bin:/usr/sbin:/usr/bin
|
|
|
|
|
|
|
|
RETVAL=0
|
|
|
|
|
|
|
|
start()
|
|
|
|
{
|
2008-02-06 21:02:29 +00:00
|
|
|
if [ -f /var/lock/subsys/iscsi ] ; then
|
|
|
|
echo
|
|
|
|
success
|
|
|
|
return
|
|
|
|
fi
|
2007-03-20 19:39:20 +00:00
|
|
|
|
2008-02-06 21:02:29 +00:00
|
|
|
# Not sure if this is ok.
|
|
|
|
# It was done for compatiblity where users were used to
|
|
|
|
# just starting the iscsi service, but for root boot we
|
|
|
|
# need need iscsid start earlier than the devices we
|
|
|
|
# log into below.
|
2007-03-20 19:39:20 +00:00
|
|
|
status iscsid
|
|
|
|
RETVAL=$?
|
|
|
|
|
|
|
|
if [ $RETVAL -ne 0 ]; then
|
|
|
|
/etc/init.d/iscsid start
|
|
|
|
fi
|
|
|
|
|
|
|
|
# this script is normally called from startup so log into
|
|
|
|
# nodes marked node.startup=automatic
|
|
|
|
iscsiadm -m node --loginall=automatic
|
|
|
|
touch /var/lock/subsys/iscsi
|
|
|
|
success
|
|
|
|
echo
|
|
|
|
}
|
|
|
|
|
2008-04-06 06:44:04 +00:00
|
|
|
cleanup_iscsi()
|
|
|
|
{
|
|
|
|
/etc/init.d/iscsid stop
|
|
|
|
rm -f /var/lock/subsys/iscsi
|
|
|
|
success
|
|
|
|
}
|
|
|
|
|
2007-03-20 19:39:20 +00:00
|
|
|
stop()
|
|
|
|
{
|
2008-02-06 21:02:29 +00:00
|
|
|
if [ ! -f /var/lock/subsys/iscsi ]; then
|
|
|
|
echo
|
|
|
|
success
|
|
|
|
return
|
|
|
|
fi
|
2007-03-20 19:39:20 +00:00
|
|
|
|
2008-04-06 06:44:04 +00:00
|
|
|
declare -a iparams=( $(iscsiadm -m session 2>/dev/null | egrep "tcp|iser") )
|
|
|
|
if [[ -z "${iparams[*]}" ]]; then
|
|
|
|
# no sessions so we can just quit
|
|
|
|
cleanup_iscsi
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2007-03-20 19:39:20 +00:00
|
|
|
# If this is a final shutdown/halt, do nothing since
|
2008-02-06 21:02:29 +00:00
|
|
|
# lvm/dm, md, power path, etc do not always handle this nicely.
|
|
|
|
# The kernel will do the right thing and shutdown devices (send
|
|
|
|
# cache syncs, start_stops, etc) that need it.
|
2007-03-20 19:39:20 +00:00
|
|
|
if [ "$RUNLEVEL" = "6" -o "$RUNLEVEL" = "0" -o "$RUNLEVEL" = "1" ]; then
|
2008-02-06 21:02:29 +00:00
|
|
|
rm -f /var/lock/subsys/iscsi
|
2007-03-20 19:39:20 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
iscsiadm -m node --logoutall=all
|
2008-04-06 06:44:04 +00:00
|
|
|
cleanup_iscsi
|
2007-03-20 19:39:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|