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
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
a8ea6d9
force_start() {
a8ea6d9
    echo -n $"Starting $prog: "
a8ea6d9
    modprobe -q iscsi_tcp
a8ea6d9
    modprobe -q ib_iser
a8ea6d9
    daemon $prog
a8ea6d9
    retval=$?
a8ea6d9
    echo
a8ea6d9
    [ $retval -eq 0 ] && touch $lockfile
a8ea6d9
    return $retval
a8ea6d9
}
a8ea6d9
a4c8b30
start() {
a4c8b30
    [ -x $exec ] || exit 5
a4c8b30
    [ -f $config ] || exit 6
5a3872e
a4c8b30
    # only start if nodes are setup to startup automatically or root is iscsi
a4c8b30
    grep -qrs "node.startup = automatic" /var/lib/iscsi/nodes
a4c8b30
    if [ $? -eq 0 ] || root_is_iscsi; then
a8ea6d9
        force_start
a8ea6d9
        return $?
a4c8b30
    fi
a4c8b30
a4c8b30
    return 0
a4c8b30
}
mchristi 63a3144
a4c8b30
stop() {
a4c8b30
    declare -a iparams=( $(iscsiadm -m session 2>/dev/null | egrep "tcp|iser") )
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: "
a4c8b30
    killproc $prog
a4c8b30
    retval=$?
a4c8b30
    echo
a4c8b30
a4c8b30
    modprobe -r ib_iser 2>/dev/null
a4c8b30
    modprobe -r iscsi_tcp 2>/dev/null
a4c8b30
a4c8b30
    [ $retval -eq 0 ] && rm -f $lockfile
a4c8b30
    return $retval
a4c8b30
}
mchristi 63a3144
a4c8b30
restart() {
a4c8b30
    stop
a4c8b30
    start
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
a4c8b30
rh_status_q() {
a4c8b30
    rh_status >/dev/null 2>&1
mchristi 63a3144
}
mchristi 63a3144
a4c8b30
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 $?