[stgt] [RFC] example init.d script for tgtd

Tomasz Chmielewski mangoo at wpkg.org
Mon Oct 20 14:37:40 CEST 2008


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!


Below, an example init.d script which is not distribution specific.
Perhaps tgt-admin needs to exit with more meaningful codes - right now, it exits with 
non zero if something failed totally. It should exit with a specified code in several cases
(i.e., target update was generally successful, but some targets were in use - not updated).


I suggest placing it in scripts/init.d/tgt.example.



Signed-off-by: Tomasz Chmielewski <mangoo at wpkg.org>


#!/bin/sh

# This is an example init.d script for stopping/starting/reconfiguring tgtd.

case $1 in
	start)
		echo "Starting target framework daemon"
		# Start tgtd first.
		tgtd
		# ~1 second is needed to daemonize.
		sleep 1s
		# Put it into "offline" state until all the targets are configured.
		tgtadm --op update --mode sys --name State -v offline
		# Configure the targets.
		tgt-admin -e
		# Put tgtd into "ready" state.
		tgtadm --op update --mode sys --name State -v ready
  		;;
	stop)
		echo "Stopping target framework daemon"
		# Remove all targets. It only removes targets which are not in use.
		tgt-admin --update ALL -c /dev/null
		# tgtd will exit if all targets were removed
		tgtadm --op delete --mode system
  		;;
	force-stop)
		echo "Force-stopping target framework daemon"
		# Remove all targets, even if they are still in use.
		tgt-admin --update ALL -c /dev/null -f
		# tgtd will exit if all targets were removed.
		tgtadm --op delete --mode system
  		;;
	restart)
		$0 stop && $0 start
  		;;
	force-restart)
		$0 force-stop && $0 start
		;;
	reload)
		echo "Updating target framework daemon configuration"
		# Update configuration for targets which are not in use.
		tgt-admin --update ALL
		;;
	force-reload)
		echo "Force-updating target framework daemon configuration"
		# Update configuration for targets, even those in use.
		tgt-admin --update ALL -f
		;;
	status)
		# Don't name this script "tgtd"...
		TGTD_PROC=$(ps -C tgtd | grep -c tgtd)
		if [ "$TGTD_PROC" -eq 2 ] ; then
		    echo "tgtd is running. Run \`tgt-admin -s' to see detailed target info."
		else
		    echo "tgtd is NOT running."
		fi
		;;
	*)
		echo "Usage: $0 {start|stop|force-stop|restart|force-restart|reload|force-reload|status}"
		exit 2
		;;
esac



-- 
Tomasz Chmielewski
http://wpkg.org
--
To unsubscribe from this list: send the line "unsubscribe stgt" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html



More information about the stgt mailing list