Blob Blame History Raw
#!/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/functions

PATH=/sbin:/bin:/usr/sbin:/usr/bin

RETVAL=0

start()
{
	echo -n $"Starting SCSI target daemon: "
	if [ -f /var/lock/subsys/tgtd ]; then
		echo
		success
		return
	fi

	daemon tgtd
	echo
	RETVAL=$?
	if [ $RETVAL -eq "0" ]; then
		touch /var/lock/subsys/tgtd
	fi
}

stop()
{
	echo -n $"Stopping SCSI target daemon: "

	if [ ! -f /var/lock/subsys/tgtd ]; then
		echo
		success
		return
	fi

	if tgtadm --op show -m target | grep "Target" >/dev/null ; then
		echo $"Targets still in use. Cannot shutdown service."
		RETVAL=1
		return
	fi

	killproc tgtd
	echo
	RETVAL=$?
	[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/tgtd
}

restart()
{
	stop
	start
}

case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	restart)
		restart
		;;
	status)
		status tgtd
		RETVAL=$?
		;;
	condrestart)
		[ -f /var/lock/subsys/tgtd ] && restart
		;;
	*)
		echo $"Usage: $0 {start|stop|restart|status|condrestart}"
		exit 1
esac
exit $RETVAL