Re: [RFC] example init.d script for tgtd

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Tomasz Chmielewski wrote:
FUJITA Tomonori schrieb:
On Mon, 20 Oct 2008 14:37:40 +0200
Tomasz Chmielewski <mangoo@xxxxxxxx> wrote:

Currently, there is no standard way to start and configure tgtd via a init.d script. As a result, even if any distribution packages tgt, it doesn't contain any startup script.

So let's help the packagers!

Really? I thought that Mike has an init script for RHEL.

I don't know the RHEL script you mention (I found no references in the archive), is it this one (scroll down a bit on that page)?


We just added it. It is not my work. It is from Ronnie. I attached the file in the mail. It might be a older version than is in RHEL. I cannot log into our servers because my vpn is down. I think the /var/lock file and /etc/sysconfig/tgtd might be too Red Hat'ish (I do not think other distros use sysconfig).
#!/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

# Check for and source configuration file otherwise set defaults
[ -f /etc/sysconfig/tgtd ] && . /etc/sysconfig/tgtd

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

RETVAL=0

[ -z "${TGTD_CONFIG}" ] && {
	TGTD_CONFIG="/etc/tgt/targets.conf"
}

# We will not support FCOE in this release
#[ -z "${TGTD_FCOE}" ] || {
#	TGTD_OPTIONS="$TGTD_OPTIONS $TGTD_FCOE"
#}


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

	# check we have a config
	[ ! -f "${TGTD_CONFIG}" ] && {
		echo $"Configuration file ${TGTD_CONFIG} is missing"
		failure
		RETVAL=1
		return
	}

	daemon tgtd $TGTD_OPTIONS

	# read the config 
	tgt-admin -e -c "${TGTD_CONFIG}"
	RETVAL=$?
	[ $RETVAL -ne 0 ] && {
		tgtadm --op delete --mode system
		failure
		return
	}

	echo
	touch /var/lock/subsys/tgtd
}

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

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

	if tgtadm --op show -m target | grep "Target" >/dev/null ; then
		if [ "$RUNLEVEL" = "6" -o "$RUNLEVEL" = "0" -o "$RUNLEVEL" = "1" ]; then
			# if the system is going down force the shutdown
			# so the shutdown does not hang
			tgt-admin --delete ALL --force
		else
			tgt-admin --delete ALL
			# must check for running targets here
		fi
	fi

	# shut down tgtd
	tgtadm --op delete --mode system
	RETVAL=$?
	[ $RETVAL -ne 0 ] && {
		echo $"Failed to shutdown target"
		failure
		RETVAL=1
		return
	}

	rm -f /var/lock/subsys/tgtd
	success
	echo
}

# this will kick out any logged in initiators and drop all targets
# This will forcefully shut down TGTD even if there are active
# initiators logged in.
# Data in initiators write-cache not yet committed to the target
# will be lost.
# This will cause an unclean shutdown of the LUN.
forcedstop()
{
	echo "Forced shutdown of the iscsi target may cause data corruption
for initiators that are connected."
	echo "You have 30 seconds to press CTRL-C and abort this operation."
	sleep 30
	tgt-admin --delete ALL --force
	stop
}

restart()
{
	stop
	start
}

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

[Index of Archives]     [Linux SCSI]     [Linux RAID]     [Linux Clusters]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]

  Powered by Linux