Hi, Please find attached to this mail, a working init script (thanks to jcristau for sharing what he hacked). Also, please consider fixing this bug in Wheezy (for example, through wheezy-proposed-updates).
If I don't hear from you, I will ask the release team if this patch may be considered for an NMU (probably, after the release, through proposed-updates). Cheers, Thomas
diff -Nru tgt-1.0.17/debian/changelog tgt-1.0.17/debian/changelog --- tgt-1.0.17/debian/changelog 2011-06-21 17:48:54.000000000 +0800 +++ tgt-1.0.17/debian/changelog 2013-04-11 23:25:22.000000000 +0800 @@ -1,3 +1,10 @@ +tgt (1:1.0.17-1.1) unstable; urgency=low + + * Non-maintainer upload. + * Adds an init script. + + -- Thomas Goirand <z...@debian.org> Thu, 11 Apr 2013 23:25:08 +0800 + tgt (1:1.0.17-1) unstable; urgency=low * New upstream release. diff -Nru tgt-1.0.17/debian/init.d tgt-1.0.17/debian/init.d --- tgt-1.0.17/debian/init.d 1970-01-01 08:00:00.000000000 +0800 +++ tgt-1.0.17/debian/init.d 2013-04-11 23:26:43.000000000 +0800 @@ -0,0 +1,158 @@ +#!/bin/bash +### BEGIN INIT INFO +# Provides: tgtd +# Required-Start: $remote_fs $syslog +# Required-Stop: $remote_fs $syslog +# Should-Start: zfs +# Should-Stop: zfs +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: iscsi target daemon +# Description: iscsi target daemon +### END INIT INFO + +# This is an example init.d script for stopping/starting/reconfiguring tgtd. + +TGTD_CONFIG=/etc/tgt/targets.conf + +TASK=$1 + +start() +{ + echo "Starting target framework daemon" + # Start tgtd first. + tgtd &>/dev/null + RETVAL=$? + if [ "$RETVAL" -ne 0 ] ; then + echo "Could not start tgtd (is tgtd already running?)" + exit 1 + fi + # 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 ready +} + +stop() +{ + if [ "$RUNLEVEL" == 0 -o "$RUNLEVEL" == 6 ] ; then + forcedstop + fi + echo "Stopping target framework daemon" + # Remove all targets. It only removes targets which are not in use. + tgt-admin --update ALL -c /dev/null &>/dev/null + # tgtd will exit if all targets were removed + tgtadm --op delete --mode system &>/dev/null + RETVAL=$? + if [ "$RETVAL" -eq 107 ] ; then + echo "tgtd is not running" + [ "$TASK" != "restart" ] && exit 1 + elif [ "$RETVAL" -ne 0 ] ; then + echo "Some initiators are still connected - could not stop tgtd" + exit 2 + fi + echo -n +} + +forcedstop() +{ + # NOTE: Forced shutdown of the iscsi target may cause data corruption + # for initiators that are connected. + echo "Force-stopping target framework daemon" + # 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 + RETVAL=$? + if [ "$RETVAL" -eq 107 ] ; then + echo "tgtd is not running" + [ "$TASK" != "restart" ] && exit 1 + else + tgt-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 system + RETVAL=$? + if [ "$RETVAL" -ne 0 ] ; then + echo "Failed to shutdown tgtd" + exit 1 + fi + fi + echo -n +} + +reload() +{ + echo "Updating target framework daemon configuration" + # Update configuration for targets. Only targets which + # are not in use will be updated. + tgt-admin --update ALL -c $TGTD_CONFIG &>/dev/null + RETVAL=$? + if [ "$RETVAL" -eq 107 ] ; then + echo "tgtd is not running" + exit 1 + fi +} + +forcedreload() +{ + echo "Force-updating target framework daemon configuration" + # Update configuration for targets, even those in use. + tgt-admin --update ALL -f -c $TGTD_CONFIG &>/dev/null + RETVAL=$? + if [ "$RETVAL" -eq 107 ] ; then + echo "tgtd is not running" + exit 1 + fi +} + +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 +} + +case $1 in + start) + start + ;; + stop) + stop + ;; + forcedstop) + forcedstop + ;; + restart) + TASK=restart + stop && start + ;; + forcedrestart) + TASK=restart + forcedstop && start + ;; + reload) + reload + ;; + forcedreload) + forcedreload + ;; + status) + status + ;; + *) + echo "Usage: $0 {start|stop|forcedstop|restart|forcedrestart|reload|forcedreload|status}" + exit 2 + ;; +esac +