mchristi 63a314
#!/bin/sh
mchristi 63a314
#
a4c8b3
# iscsid iSCSI daemon
a4c8b3
#
d3d856
# chkconfig: 345 7 89
mchristi 63a314
# description: Starts and stops the iSCSI daemon.
mchristi 63a314
#
mchristi 63a314
# processname: iscsid
mchristi 63a314
# pidfile: /var/run/iscsid.pid
mchristi 63a314
# config:  /etc/iscsi/iscsid.conf
a4c8b3
5a3872
### BEGIN INIT INFO
5a3872
# Provides:          iscsid
a4c8b3
# Default-Start: 3 4 5
a4c8b3
# Default-Stop: 0 1 2 6
5a3872
# Short-Description: Starts and stops login iSCSI daemon.
5a3872
# Description: iscsid provides the iSCSI session and connection state machine
5a3872
#              for software iscsi/iser (iscsi_tcp/ib_iser) and partialy
5a3872
#              offloaded hardware (bnx2i).
5a3872
### END INIT INFO
a4c8b3
mchristi 63a314
# Source function library.
a4c8b3
. /etc/rc.d/init.d/functions
mchristi 63a314
a4c8b3
exec=/sbin/iscsid
a4c8b3
prog=iscsid
a4c8b3
config=/etc/iscsi/iscsid.conf
a4c8b3
lockfile=/var/lock/subsys/$prog
mchristi 63a314
a4c8b3
# FIXME this has a false positive for root on nfs
a4c8b3
root_is_iscsi() {
a4c8b3
    rootopts=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $4; }}' /etc/mtab)
a4c8b3
    [[ "$rootopts" =~ "_netdev" ]]
a4c8b3
}
mchristi 63a314
a8ea6d
force_start() {
a8ea6d
    echo -n $"Starting $prog: "
a8ea6d
    modprobe -q iscsi_tcp
a8ea6d
    modprobe -q ib_iser
8f36c1
    modprobe -q cxgb3i
1c8eda
    modprobe -q bnx2i
8f36c1
    modprobe -q be2iscsi
a8ea6d
    daemon $prog
a8ea6d
    retval=$?
a8ea6d
    echo
a8ea6d
    [ $retval -eq 0 ] && touch $lockfile
a8ea6d
    return $retval
a8ea6d
}
a8ea6d
1c8eda
use_discoveryd() {
1c8eda
    grep -qrs "discovery.sendtargets.use_discoveryd = Yes" /var/lib/iscsi/send_targets
1c8eda
    if [ $? -eq 0 ] ; then
1c8eda
 	return 0
1c8eda
    fi
1c8eda
1c8eda
    grep -qrs "discovery.isns.use_discoveryd = Yes" /var/lib/iscsi/isns
1c8eda
    if [ $? -eq 0 ] ; then
1c8eda
 	return 0
1c8eda
    fi
1c8eda
1c8eda
    return 1
1c8eda
}
1c8eda
a4c8b3
start() {
a4c8b3
    [ -x $exec ] || exit 5
a4c8b3
    [ -f $config ] || exit 6
5a3872
1c8eda
    # only start if nodes are setup to startup automatically, root is iscsi,
1c8eda
    # or if iscsid is managing the sessions.
a4c8b3
    grep -qrs "node.startup = automatic" /var/lib/iscsi/nodes
1c8eda
    if [ $? -eq 0 ] || root_is_iscsi || use_discoveryd ; then
a8ea6d
        force_start
a8ea6d
        return $?
a4c8b3
    fi
a4c8b3
a4c8b3
    return 0
a4c8b3
}
mchristi 63a314
a4c8b3
stop() {
1c8eda
    if use_discoveryd ; then
1c8eda
	iscsiadm -k 0 2>/dev/null
1c8eda
    fi
1c8eda
8f36c1
    declare -a iparams=( $(iscsiadm -m session 2>/dev/null | egrep "tcp|iser|bnx2i|cxgb3i|be2iscsi") )
a4c8b3
    if [[ -n "${iparams[*]}" ]]; then
a4c8b3
        # We have active sessions, so don't stop iscsid!!
a4c8b3
        echo -n $"Not stopping $prog: iscsi sessions still active"
a4c8b3
        warning $"Not stopping $prog: iscsi sessions still active"
a4c8b3
        echo
a4c8b3
        return 0
a4c8b3
    fi
a4c8b3
a4c8b3
    echo -n $"Stopping $prog: "
1c8eda
 
1c8eda
    iscsiadm -k 0 2>/dev/null
a4c8b3
8f36c1
    # only remove the iscsi drivers when offload is used
1c8eda
    rmmod bnx2i 2>/dev/null
1c8eda
    rmmod cnic 2>/dev/null
1c8eda
8f36c1
    rmmod cxgb3i 2>/dev/null
8f36c1
8f36c1
    modprobe -r be2iscsi 2>/dev/null
8f36c1
a4c8b3
    modprobe -r ib_iser 2>/dev/null
a4c8b3
    modprobe -r iscsi_tcp 2>/dev/null
a4c8b3
2d4a52
    success $"Stopping $prog"
1c8eda
    rm -f $lockfile
2d4a52
    echo
1c8eda
    return 0
1c8eda
}
1c8eda
1c8eda
rh_status_q() {
1c8eda
    rh_status >/dev/null 2>&1
a4c8b3
}
mchristi 63a314
a4c8b3
restart() {
1c8eda
    rh_status_q
1c8eda
    use_force_start=$?
1c8eda
a4c8b3
    stop
1c8eda
    # if iscsid was running then make sure it starts up
1c8eda
    if [ "$use_force_start" -eq 0 ] ; then
1c8eda
	force_start
1c8eda
    else
1c8eda
	start
1c8eda
    fi
mchristi 63a314
}
mchristi 63a314
a4c8b3
reload() {
a4c8b3
    return 3
a4c8b3
}
500302
a4c8b3
force_reload() {
a4c8b3
    restart
500302
}
500302
a4c8b3
rh_status() {
a4c8b3
    status $prog
mchristi 63a314
}
mchristi 63a314
mchristi 63a314
case "$1" in
a4c8b3
    start)
a4c8b3
        rh_status_q && exit 0
a4c8b3
        $1
a4c8b3
        ;;
a8ea6d
    force-start)
a8ea6d
        force_start
a8ea6d
        ;;
a4c8b3
    stop)
a4c8b3
        rh_status_q || exit 0
a4c8b3
        $1
a4c8b3
        ;;
a4c8b3
    restart)
a4c8b3
        $1
a4c8b3
        ;;
a4c8b3
    reload)
a4c8b3
        rh_status_q || exit 7
a4c8b3
        $1
a4c8b3
        ;;
a4c8b3
    force-reload)
a4c8b3
        force_reload
a4c8b3
        ;;
a4c8b3
    status)
a4c8b3
        rh_status
a4c8b3
        ;;
a4c8b3
    condrestart|try-restart)
a4c8b3
        rh_status_q || exit 0
a4c8b3
        restart
a4c8b3
        ;;
a4c8b3
    *)
a4c8b3
        echo $"Usage: $0
a4c8b3
{start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
a4c8b3
        exit 2
mchristi 63a314
esac
a4c8b3
exit $?