This file is indexed.

/etc/init.d/tgt is in tgt 1:1.0.51-1.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/bin/sh
### BEGIN INIT INFO
# Provides:          tgtd tgt
# 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

DESC="target framework daemon"
NAME=tgtd
DAEMON=/usr/sbin/${NAME}
PIDFILE=/run/${NAME}.pid

TGTD_CONFIG=/etc/tgt/targets.conf

. /lib/lsb/init-functions

[ -x $DAEMON ] || exit 0

start()
{
	log_daemon_msg "Starting $DESC" "$NAME"
	# Start tgtd first.
	if ! start-stop-daemon --start --quiet --oknodo --pidfile $PIDFILE \
		--make-pidfile --background --exec $DAEMON -- -f; then
		log_end_msg 1
		exit 1
	fi

	log_end_msg 0
	# 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()
{
	# NOTE: Forced shutdown of the iscsi target may cause data corruption
	# for initiators that are connected.
	log_daemon_msg "Force-stopping $DESC" "$NAME"
	# 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>&1
	RETVAL=$?
	if [ "$RETVAL" -eq 107 ] ; then
	    # tgtd not running
	    log_end_msg 0
	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
		log_end_msg 1
		echo "Failed to shutdown tgtd"
		exit 1
	    fi
	    log_end_msg 0
	    rm -f $PIDFILE
	fi
}

reload()
{
	log_daemon_msg "Reloading configuration of $DESC" "$NAME"
	# Update configuration for targets. Only targets which
	# are not in use will be updated.
	tgt-admin --update ALL -c $TGTD_CONFIG >/dev/null 2>&1
	RETVAL=$?
	if [ "$RETVAL" -eq 107 ] ; then
		log_end_msg 1
		echo "tgtd is not running"
		exit 1
	fi
	log_end_msg 0
}

forcedreload()
{
	log_daemon_msg "Forced-reload configuration of $DESC" "$NAME"
	# Update configuration for targets, even those in use.
	tgt-admin --update ALL -f -c $TGTD_CONFIG >/dev/null 2>&1
	RETVAL=$?
	if [ "$RETVAL" -eq 107 ] ; then
		log_end_msg 1
		echo "tgtd is not running"
		exit 1
	else
		log_end_msg 0
	fi
}

case $1 in
	start)
		start
		;;
	stop|forcedstop)
		stop
		;;
	restart|forcedrestart)
		stop && start
		;;
	reload)
		reload
		;;
	force-reload)
		forcedreload
		;;
	status)
		status_of_proc -p $PIDFILE /usr/sbin/tgtd tgtd
		exit $?
		;;
	*)
		echo "Usage: $0 {start|stop|forcedstop|restart|forcedrestart|reload|force-reload|status}"
		exit 2
		;;
esac