mchristi 63a3144
#!/bin/sh
mchristi 63a3144
#
a4c8b30
# iscsi: log into iSCSI targets
a4c8b30
#
d3d8564
# chkconfig: 345 13 89
mchristi 63a3144
# description: Logs into iSCSI targets needed at system startup
a4c8b30
a4c8b30
# Note we should have $network in Required-Start/Stop but we don't because if
a4c8b30
# we would require network chkconfig will put us directly after NetworkManager
a4c8b30
# when using NM, which will make our see if the network is up test succeed
a4c8b30
# while NM is actually still configuring the network. By not requiring network
a4c8b30
# chkconfig will use the chkconfig header to determine our start prio, starting
a4c8b30
# us after the old network service, but before NM (netfs does this the same).
a4c8b30
5a3872e
### BEGIN INIT INFO
5a3872e
# Provides:          iscsi
a4c8b30
# Required-Start:    iscsid
a4c8b30
# Required-Stop:     iscsid
a4c8b30
# Default-Start: 3 4 5
a4c8b30
# Default-Stop: 0 1 2 6
5a3872e
# Short-Description: Starts and stops login and scanning of iSCSI devices.
5a3872e
# Description: iscsi provides the iSCSI state machine for software iscsi/iser
5a3872e
#              and partial offloaded hardware. iscsi logs into and scans
5a3872e
#              for iSCSI devices, and shuts them down when stopped.
5a3872e
### END INIT INFO
a4c8b30
mchristi 63a3144
# Source function library.
a4c8b30
. /etc/rc.d/init.d/functions
a4c8b30
a4c8b30
exec="/sbin/iscsiadm"
a4c8b30
prog="iscsi"
a4c8b30
config="/etc/iscsi/initiatorname.iscsi"
a4c8b30
lockfile=/var/lock/subsys/$prog
a4c8b30
iscsid_lockfile=/var/lock/subsys/${prog}_iscsid
a4c8b30
a4c8b30
start() {
a4c8b30
    [ -x $exec ] || exit 5
a4c8b30
    [ -f $config ] || exit 6
a4c8b30
a4c8b30
    # if the network isn't up yet exit cleanly, NetworkManager will call us
a4c8b30
    # again when the network is up
a4c8b30
    [ ! -f /var/lock/subsys/network -a ! -f /var/lock/subsys/NetworkManager ] && exit 0
a4c8b30
a4c8b30
    # if no nodes are setup to startup automatically exit cleanly
a4c8b30
    grep -qrs "node.startup = automatic" /var/lib/iscsi/nodes
a4c8b30
    [ $? -eq 0 ] || exit 0
a4c8b30
a4c8b30
    # this script is normally called from startup so log into
a4c8b30
    # nodes marked node.startup=automatic
a4c8b30
    echo -n $"Starting $prog: "
a4c8b30
    $exec -m node --loginall=automatic 2>&1 > /dev/null | grep iscsiadm
a4c8b30
a4c8b30
    # <sigh> iscsiadm does not always give a non 0 exit status in case of
a4c8b30
    # error so we grep for any messages to stderr and see those as errors too
a4c8b30
    if [ ${PIPESTATUS[0]} -ne 0 -o ${PIPESTATUS[1]} -eq 0 ]; then
a4c8b30
        failure $"Starting $prog"
a4c8b30
        echo
a4c8b30
        return 1
a4c8b30
    fi
a4c8b30
a4c8b30
    success $"Starting $prog"
a4c8b30
    touch $lockfile
a4c8b30
    echo
a4c8b30
    return 0
mchristi 63a3144
}
mchristi 63a3144
a4c8b30
stop() {
a4c8b30
    echo -n $"Stopping $prog: "
a4c8b30
    $exec -m node --logoutall=automatic 2>&1 > /dev/null | grep iscsiadm
a4c8b30
a4c8b30
    # <sigh> iscsiadm does not always give a non 0 exit status in case of
a4c8b30
    # error so we grep for any messages to stderr and see those as errors too
a4c8b30
    if [ ${PIPESTATUS[0]} -ne 0 -o ${PIPESTATUS[1]} -eq 0 ]; then
a4c8b30
        failure $"Stopping $prog"
a4c8b30
        echo
a4c8b30
        return 1
a4c8b30
    fi
a4c8b30
a4c8b30
    success $"Stopping $prog"
a4c8b30
    rm -f $lockfile
a4c8b30
    echo
a4c8b30
    return 0
a4c8b30
}
a4c8b30
a4c8b30
restart() {
a4c8b30
    stop
a4c8b30
    start
5003024
}
5003024
a4c8b30
reload() {
a4c8b30
    return 3
mchristi 63a3144
}
mchristi 63a3144
a4c8b30
force_reload() {
a4c8b30
    restart
a4c8b30
}
a4c8b30
a4c8b30
rh_status() {
a4c8b30
    [ -f $lockfile ] || return 3
a4c8b30
a4c8b30
    declare -a iparams=( $(iscsiadm -m session 2>/dev/null | egrep "tcp|iser") )
a4c8b30
    if [[ -z "${iparams[*]}" ]]; then
a4c8b30
        # no sessions
a4c8b30
        return 2
a4c8b30
    fi
a4c8b30
a4c8b30
    return 0
a4c8b30
}
a4c8b30
a4c8b30
rh_status_q() {
a4c8b30
    rh_status >/dev/null 2>&1
a4c8b30
}
a4c8b30
a4c8b30
mchristi 63a3144
case "$1" in
a4c8b30
    start)
a4c8b30
        rh_status_q && exit 0
a4c8b30
        $1
a4c8b30
        ;;
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 $?