Blame | Last modification | View Log | RSS feed
#!/bin/sh## iscsi: log into iSCSI targets## chkconfig: 345 13 89# description: Logs into iSCSI targets needed at system startup# Note we should have $network in Required-Start/Stop but we don't because if# we would require network chkconfig will put us directly after NetworkManager# when using NM, which will make our see if the network is up test succeed# while NM is actually still configuring the network. By not requiring network# chkconfig will use the chkconfig header to determine our start prio, starting# us after the old network service, but before NM (netfs does this the same).### BEGIN INIT INFO# Provides: iscsi# Required-Start: iscsid# Required-Stop: iscsid# Default-Start: 3 4 5# Default-Stop: 0 1 2 6# 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# Source function library.. /etc/rc.d/init.d/functionsexec="/sbin/iscsiadm"prog="iscsi"config="/etc/iscsi/initiatorname.iscsi"lockfile=/var/lock/subsys/$progiscsid_lockfile=/var/lock/subsys/${prog}_iscsidstart() {[ -x $exec ] || exit 5[ -f $config ] || exit 6# if the network isn't up yet exit cleanly, NetworkManager will call us# again when the network is up[ ! -f /var/lock/subsys/network -a ! -f /var/lock/subsys/NetworkManager ] && exit 0# if no nodes are setup to startup automatically exit cleanlygrep -qrs "node.startup = automatic" /var/lib/iscsi/nodes[ $? -eq 0 ] || exit 0# this script is normally called from startup so log into# nodes marked node.startup=automaticecho -n $"Starting $prog: "$exec -m node --loginall=automatic 2>&1 > /dev/null | grep iscsiadm# Ignore return code, because this command attempts to log into# multiple sessions and some sessions could get logged into and# some could be down temporarily.success $"Starting $prog"touch $lockfileechoreturn 0}iscsi_sessions_running() {declare -a iparams=( $(iscsiadm -m session 2>/dev/null | egrep "tcp|iser|bnx2i|be2iscsi|cxgb3i|cxgb4i") )if [[ -z "${iparams[*]}" ]]; then# no sessionsreturn 2fireturn 0}cleanup_successful_stop() {success $"Stopping $prog"rm -f $lockfileecho}stop() {# 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" ]] ; thenecho $"Can not shutdown iSCSI. Root is on a iSCSI disk."# Just clean up lock file if this is a system shutdown/reboot.if [ "$RUNLEVEL" = "6" -o "$RUNLEVEL" = "0" -o "$RUNLEVEL" = "1" ]; thenrm -f $lockfilefiexit 1fiecho -n $"Stopping $prog: "if ! iscsi_sessions_running ; thencleanup_successful_stopreturn 0fiif [ "$RUNLEVEL" = "6" -o "$RUNLEVEL" = "0" -o "$RUNLEVEL" = "1" ]; then$exec -m node --logoutall=all 2>&1 > /dev/nullelse$exec -m node --logoutall=automatic 2>&1 > /dev/nullfiret=$?# ignore ISCSI_ERR_NO_OBJS_FOUND/21if [[ "$ret" -ne 0 && "$ret" -ne 21 ]]; thenfailure $"Stopping $prog"echoreturn 1ficleanup_successful_stopreturn 0}restart() {stopstart}reload() {return 3}force_reload() {restart}rh_status() {[ -f $lockfile ] || { echo $"$prog is stopped" ; return 3 ; }declare -a iparams=( $(iscsiadm -m session 2>/dev/null | egrep "tcp|iser|bnx2i|be2iscsi|cxgb3i|cxgb4i") )if [[ -z "${iparams[*]}" ]]; then# no sessionsecho $"No active sessions"return 2fiiscsiadm -m session -P 3return 0}rh_status_q() {rh_status >/dev/null 2>&1}case "$1" instart)rh_status_q && exit 0$1;;stop)$1;;restart)$1;;reload)rh_status_q || exit 7$1;;force-reload)force_reload;;status)rh_status;;condrestart|try-restart)rh_status_q || exit 0restart;;*)echo $"Usage: $0{start|stop|status|restart|condrestart|try-restart|reload|force-reload}"exit 2esacexit $?