Blame | Last modification | View Log | RSS feed
#!/bin/sh## chkconfig: - 39 35#### BEGIN INIT INFO# Provides: tgtd# Required-Start: $network# Short-Description: Starts and stops the generic storage target daemon# Description: tgtd provides the SCSI and software transport target state# machine daemon.### END INIT INFO### pidfile: /var/run/tgtd.pid## Source function library.. /etc/init.d/functionsPATH=/sbin:/bin:/usr/sbin:/usr/binTGTD_CONFIG=/etc/tgt/targets.confprog="SCSI target daemon"exec=tgtdlockfile=/var/lock/subsys/$execstart(){# Check for and source configuration file otherwise use defaults above[ -f /etc/sysconfig/$exec ] && . /etc/sysconfig/$exec[ -x /usr/sbin/$exec ] || exit 5echo -n $"Starting $prog: "# Note /dev/null redirection to silence rdma not found messagesdaemon $exec ${TGTD_OPTIONS} >/dev/null 2>&1retval=$?if [ $retval -ne 0 ] ; thenfailureechoreturn $retvalfisuccessechotouch $lockfile# Put tgtd into "offline" state until all the targets are configured.# We don't want initiators to (re)connect and fail the connection# if it's not ready.tgtadm --op update --mode sys --name State -v offline# Configure the targets.tgt-admin -e -c $TGTD_CONFIG# Put tgtd into "ready" state.tgtadm --op update --mode sys --name State -v readyreturn 0}stop(){if [ "$RUNLEVEL" == 0 -o "$RUNLEVEL" == 6 ] ; thenforce_stopreturn $?fiecho -n $"Stopping $prog: "# Remove all targets. It only removes targets which are not in use.tgt-admin --update ALL -c /dev/null >/dev/null 2>&1# tgtd will exit if all targets were removedtgtadm --op delete --mode system >/dev/null 2>&1retval=$?if [ "$retval" -eq 107 ] ; thenecho -n $"not running"failureechoreturn 7elif [ "$retval" -ne 0 ] ; thenecho -n $"initiators still connected"failureechoreturn 1fisuccessechorm -f $lockfilereturn 0}force_stop(){# NOTE: Forced shutdown of the iscsi target may cause data corruption# for initiators that are connected.echo -n $"Force-stopping $prog: "# Offline everything first. May be needed if we're rebooting, but# expect the initiators to reconnect cleanly when we boot again# (i.e. we don't want them to reconnect to a tgtd which is still# working, but the target is gone).tgtadm --op update --mode sys --name State -v offline >/dev/null 2>&1retval=$?if [ "$retval" -eq 107 ] ; thenecho -n $"not running"failureechoreturn 7elsetgt-admin --offline ALL# Remove all targets, even if they are still in use.tgt-admin --update ALL -c /dev/null -f# It will shut down tgtd only after all targets were removed.tgtadm --op delete --mode systemretval=$?if [ "$retval" -ne 0 ] ; thenfailureechoreturn 1fifisuccessechorm -f $lockfilereturn 0}reload() {# Check for and source configuration file otherwise use defaults above[ -f /etc/sysconfig/$exec ] && . /etc/sysconfig/$exececho -n $"Updating $prog configuration: "# Update configuration for targets. Only targets which# are not in use will be updated.tgt-admin --update ALL -c $TGTD_CONFIG >/dev/null 2>&1retval=$?if [ "$retval" -eq 107 ] ; thenecho -n $"not running"failureechoreturn 7elif [ "$retval" -ne 0 ] ; thenfailureechoreturn 1fisuccessechoreturn 0}force_reload() {# Check for and source configuration file otherwise use defaults above[ -f /etc/sysconfig/$exec ] && . /etc/sysconfig/$exececho -n $"Force-updating $prog configuration: "# Update configuration for targets, even those in use.tgt-admin --update ALL -f -c $TGTD_CONFIG >/dev/null 2>&1retval=$?if [ "$retval" -eq 107 ] ; thenecho -n $"not running"failureechoreturn 7elif [ "$retval" -ne 0 ] ; thenfailureechoreturn 1fisuccessechoreturn 0}restart() {stopstart}rh_status() {# run checks to determine if the service is running or use generic statusstatus $exec}rh_status_q() {rh_status >/dev/null 2>&1}case "$1" instart)[ `id -u` = 0 ] || exit 4rh_status_q && exit 0$1;;stop)[ `id -u` = 0 ] || exit 4rh_status_q || exit 0$1;;force-stop)[ `id -u` = 0 ] || exit 4force_stop;;restart)[ `id -u` = 0 ] || exit 4restart;;force-restart)[ `id -u` = 0 ] || exit 4force_stopstart;;reload)[ `id -u` = 0 ] || exit 4rh_status_q || exit 7$1;;force-reload)[ `id -u` = 0 ] || exit 4force_reload;;status)rh_status;;condrestart|try-restart)[ `id -u` = 0 ] || exit 4rh_status_q || exit 0restart;;*)echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-stop|force-restart|force-reload}"exit 2esacexit $?