mchristi 63a3144
#!/bin/sh
mchristi 63a3144
#
a4c8b30
# iscsid iSCSI daemon
a4c8b30
#
d3d8564
# chkconfig: 345 7 89
mchristi 63a3144
# description: Starts and stops the iSCSI daemon.
mchristi 63a3144
#
mchristi 63a3144
# processname: iscsid
mchristi 63a3144
# pidfile: /var/run/iscsid.pid
mchristi 63a3144
# config:  /etc/iscsi/iscsid.conf
a4c8b30
5a3872e
### BEGIN INIT INFO
5a3872e
# Provides:          iscsid
a4c8b30
# Default-Start: 3 4 5
a4c8b30
# Default-Stop: 0 1 2 6
5a3872e
# Short-Description: Starts and stops login iSCSI daemon.
5a3872e
# Description: iscsid provides the iSCSI session and connection state machine
5a3872e
#              for software iscsi/iser (iscsi_tcp/ib_iser) and partialy
5a3872e
#              offloaded hardware (bnx2i).
5a3872e
### END INIT INFO
a4c8b30
mchristi 63a3144
# Source function library.
a4c8b30
. /etc/rc.d/init.d/functions
mchristi 63a3144
a4c8b30
exec=/sbin/iscsid
a4c8b30
prog=iscsid
a4c8b30
config=/etc/iscsi/iscsid.conf
a4c8b30
lockfile=/var/lock/subsys/$prog
Mike Christie 3949e15
iscsi_lockfile=/var/lock/subsys/iscsi
mchristi 63a3144
a4c8b30
# FIXME this has a false positive for root on nfs
a4c8b30
root_is_iscsi() {
a4c8b30
    rootopts=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $4; }}' /etc/mtab)
a4c8b30
    [[ "$rootopts" =~ "_netdev" ]]
a4c8b30
}
mchristi 63a3144
Mike Christie 3949e15
start_iscsid() {
a8ea6d9
    echo -n $"Starting $prog: "
a8ea6d9
    modprobe -q iscsi_tcp
a8ea6d9
    modprobe -q ib_iser
8f36c17
    modprobe -q cxgb3i
Mike Christie 3949e15
    modprobe -q cxgb4i
1c8eda8
    modprobe -q bnx2i
8f36c17
    modprobe -q be2iscsi
Mike Christie 3949e15
    daemon iscsiuio
a8ea6d9
    daemon $prog
a8ea6d9
    retval=$?
a8ea6d9
    echo
Mike Christie 3949e15
    touch $lockfile
Mike Christie 3949e15
}
Mike Christie 3949e15
Mike Christie 3949e15
force_start() {
Mike Christie 3949e15
    start_iscsid
Mike Christie 3949e15
    # a force start could imply the iscsi service is started due to how it
Mike Christie 3949e15
    # lazy starts. We need to touch the lock file so it is shutdown later
Mike Christie 3949e15
    touch $iscsi_lockfile
a8ea6d9
}
a8ea6d9
1c8eda8
use_discoveryd() {
1c8eda8
    grep -qrs "discovery.sendtargets.use_discoveryd = Yes" /var/lib/iscsi/send_targets
1c8eda8
    if [ $? -eq 0 ] ; then
1c8eda8
 	return 0
1c8eda8
    fi
1c8eda8
1c8eda8
    grep -qrs "discovery.isns.use_discoveryd = Yes" /var/lib/iscsi/isns
1c8eda8
    if [ $? -eq 0 ] ; then
1c8eda8
 	return 0
1c8eda8
    fi
1c8eda8
1c8eda8
    return 1
1c8eda8
}
1c8eda8
a4c8b30
start() {
a4c8b30
    [ -x $exec ] || exit 5
a4c8b30
    [ -f $config ] || exit 6
5a3872e
Mike Christie 658ff4f
    start_iscsid 
Mike Christie 658ff4f
    return $?
a4c8b30
}
mchristi 63a3144
a4c8b30
stop() {
1c8eda8
    if use_discoveryd ; then
1c8eda8
	iscsiadm -k 0 2>/dev/null
1c8eda8
    fi
1c8eda8
Mike Christie 3949e15
    declare -a iparams=( $(iscsiadm -m session 2>/dev/null | egrep "tcp|iser|bnx2i|cxgb3i|cxgb4i|be2iscsi") )
a4c8b30
    if [[ -n "${iparams[*]}" ]]; then
a4c8b30
        # We have active sessions, so don't stop iscsid!!
a4c8b30
        echo -n $"Not stopping $prog: iscsi sessions still active"
a4c8b30
        warning $"Not stopping $prog: iscsi sessions still active"
a4c8b30
        echo
a4c8b30
        return 0
a4c8b30
    fi
a4c8b30
a4c8b30
    echo -n $"Stopping $prog: "
1c8eda8
 
1c8eda8
    iscsiadm -k 0 2>/dev/null
Mike Christie 3949e15
    echo
Mike Christie 3949e15
Mike Christie 3949e15
    killproc iscsiuio
Mike Christie 3949e15
    rm -f /var/run/iscsiuio.pid
a4c8b30
8f36c17
    # only remove the iscsi drivers when offload is used
1c8eda8
    rmmod bnx2i 2>/dev/null
1c8eda8
    rmmod cnic 2>/dev/null
1c8eda8
8f36c17
    rmmod cxgb3i 2>/dev/null
Mike Christie 3949e15
    rmmod cxgb4i 2>/dev/null
8f36c17
Mike Christie 3949e15
    # a bug in kobject netlink code will cause this to oops
Mike Christie 3949e15
    # modprobe -r be2iscsi 2>/dev/null
8f36c17
a4c8b30
    modprobe -r ib_iser 2>/dev/null
a4c8b30
    modprobe -r iscsi_tcp 2>/dev/null
a4c8b30
1c8eda8
    rm -f $lockfile
1c8eda8
    return 0
1c8eda8
}
1c8eda8
1c8eda8
rh_status_q() {
1c8eda8
    rh_status >/dev/null 2>&1
a4c8b30
}
mchristi 63a3144
a4c8b30
restart() {
1c8eda8
    rh_status_q
1c8eda8
    use_force_start=$?
1c8eda8
a4c8b30
    stop
1c8eda8
    # if iscsid was running then make sure it starts up
1c8eda8
    if [ "$use_force_start" -eq 0 ] ; then
Mike Christie 3949e15
	start_iscsid
1c8eda8
    else
1c8eda8
	start
1c8eda8
    fi
mchristi 63a3144
}
mchristi 63a3144
a4c8b30
reload() {
a4c8b30
    return 3
a4c8b30
}
5003024
a4c8b30
force_reload() {
a4c8b30
    restart
5003024
}
5003024
a4c8b30
rh_status() {
a4c8b30
    status $prog
mchristi 63a3144
}
mchristi 63a3144
mchristi 63a3144
case "$1" in
a4c8b30
    start)
a4c8b30
        rh_status_q && exit 0
a4c8b30
        $1
a4c8b30
        ;;
a8ea6d9
    force-start)
a8ea6d9
        force_start
a8ea6d9
        ;;
a4c8b30
    stop)
a4c8b30
        rh_status_q || exit 0
a4c8b30
        $1
a4c8b30
        ;;
a4c8b30
    restart)
a4c8b30
        $1
a4c8b30
        ;;
a4c8b30
    reload)
a4c8b30
        rh_status_q || exit 7
a4c8b30
        $1
a4c8b30
        ;;
a4c8b30
    force-reload)
a4c8b30
        force_reload
a4c8b30
        ;;
a4c8b30
    status)
a4c8b30
        rh_status
a4c8b30
        ;;
a4c8b30
    condrestart|try-restart)
a4c8b30
        rh_status_q || exit 0
a4c8b30
        restart
a4c8b30
        ;;
a4c8b30
    *)
a4c8b30
        echo $"Usage: $0
a4c8b30
{start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
a4c8b30
        exit 2
mchristi 63a3144
esac
a4c8b30
exit $?