/etc/init.d/target is in lio-utils 3.1+git2.fd0b34fd-2.
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 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 | #!/bin/bash
#
# Filename: /etc/init.d/target
# target: Bring up/down target_core_mod and iscsi_target_mod v3.0
#
# Bring up/down iscsi target networking
#
# chkconfig: 2345 18 01
# description: Target_Core_Mod + LIO-target + ConfigFS v3.x
# config: /etc/sysconfig/target
#
#########################################################################
#
# For SuSE, the following information is read by "insserv" program and the
# start/stoplinks are installed at appropriate runlevels.
# The network interface and logger has to be up for starting target service
### BEGIN INIT INFO
# Provides: target
# Required-Start: $network $syslog $remote_fs
# Required-Stop: $network $syslog $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Description: TCM/ConfigFS and LIO-Target
# Short-Description: Start service at boot time
### END INIT INFO
# Source function library.
#. /etc/init.d/functions
#########################################################################
# Our product file definitions
MODNAME="target_core_mod"
TCM_CFS_DIR="/sys/kernel/config/target/core"
LIO_CFS_DIR="/sys/kernel/config/target/iscsi"
FILE_TCFG="/etc/sysconfig/target"
LOCK_TARGET="/var/lock/subsys/target"
LOG_EVENT="/var/log/iscsi/target.log"
TCM_NODE="/usr/sbin/tcm_node"
LIO_NODE="/usr/sbin/lio_node"
TCM_FABRIC="/usr/sbin/tcm_fabric"
SEMA_TARGET="/var/crash/target.fault"
CONFIGFS_SCRIPT_DIR="/etc/target"
TCM_CONFIGFS_SCRIPT="/etc/target/tcm_start.sh"
LIO_CONFIGFS_SCRIPT="/etc/target/lio_start.sh"
#########################################################################
# Allows saving command & arguments into a file for subsequent debugging
# Enable: Set DEBUG=1 Disable: Set DEBUG=0
DEBUG=0
LOGFILE=/var/log/tgtctl.dbug
if [ $DEBUG != 0 ]; then
echo "$0 $*" >> $LOGFILE
fi
#########################################################################
if [ ! -f ${TCM_NODE} ]; then
echo "${TCM_NODE} does not exist"
exit 1
fi
if [ ! -f ${LIO_NODE} ]; then
echo "${LIO_NODE} does not exist"
exit 1
fi
if [ ! -d /var/crash ]; then
mkdir /var/crash
fi
if [ ! -d /var/lock/subsys ]; then
mkdir -p /var/lock/subsys
fi
if [ ! -d /var/target/pr ]; then
mkdir -p /var/target/pr
fi
if [ ! -d /var/target/alua ]; then
mkdir -p /var/target/alua
fi
ARGS_CHECK=2
ARGS_COUNT=$#
cd / # to avoid making the CWD unmountable
#########################################################################
PATH="/sbin:/bin:/usr/sbin:/usr/bin:$PATH"
RETVAL=0
function run_fabric_cfs_ops() {
DATETIME=$1
for i in $( ls $CONFIGFS_SCRIPT_DIR); do
CONFIGFS_SCRIPT_PATH="$CONFIGFS_SCRIPT_DIR/$i"
if [ ! -f $CONFIGFS_SCRIPT_PATH ]; then
continue
fi
# target core is handled in run_tcm_cfs_ops()
if [ $i == "tcm_start.sh" ]; then
continue
fi
# iscsi-target fabric module is handled in run_lio_target_cfs_ops()
if [ $i == "lio_start.sh" ]; then
continue
fi
# Skip RPM package save+orig+new
if [[ $i =~ ".rpmsave" ]]; then
continue
fi
if [[ $i =~ ".rpmorig" ]]; then
continue
fi
if [[ $i =~ ".rpmnew" ]]; then
continue
fi
# Skip dpkg dist
if [[ $i =~ ".dpkg-dist" ]]; then
continue
fi
# Skip emacs state files
if [[ $i =~ ~$ ]]; then
continue
fi
if [ $DATETIME != "0" ]; then
FABRICNAME=`echo $i | sed -e s/_start.sh//`
BACKUPFILE=$FABRICNAME"_backup-$DATETIME.sh"
CONFIGFS_SCRIPT_PATH="/etc/target/backup/$BACKUPFILE"
if [ ! -f $CONFIGFS_SCRIPT_PATH ]; then
echo "Unable to locate config file $CONFIGFS_SCRIPT_PATH"
exit 1
fi
fi
echo -n $"Calling ConfigFS script $CONFIGFS_SCRIPT_PATH: "
sh ${CONFIGFS_SCRIPT_PATH} > /dev/null 2>&1
RET=$?
if [ $RET == 0 ]; then
echo " [OK]"
else
echo " [FAILED]"
fi
done
}
function run_lio_target_cfs_ops() {
DATETIME=$1
if [ ! -f ${LIO_CONFIGFS_SCRIPT} ]; then
exit 1
fi
if [ $DATETIME != "0" ]; then
LIO_CONFIGFS_SCRIPT="/etc/target/backup/lio_backup-$DATETIME.sh"
if [ ! -f $LIO_CONFIGFS_SCRIPT ]; then
echo "Unable to locate config file $LIO_CONFIGFS_SCRIPT"
exit 1
fi
fi
echo -n $"Calling ConfigFS script $LIO_CONFIGFS_SCRIPT for iscsi_target_mod: "
if [ -f $LIO_CONFIGFS_SCRIPT ]; then
sh ${LIO_CONFIGFS_SCRIPT} > /dev/null 2>&1
RET=$?
if [ $RET == 0 ]; then
echo " [OK]"
else
echo " [FAILED]"
fi
fi
}
function run_tcm_cfs_ops() {
DATETIME=$1
if [ ! -f ${TCM_CONFIGFS_SCRIPT} ]; then
exit 1
fi
if [ $DATETIME != "0" ]; then
TCM_CONFIGFS_SCRIPT="/etc/target/backup/tcm_backup-$DATETIME.sh"
if [ ! -f $TCM_CONFIGFS_SCRIPT ]; then
echo "Unable to locate config file $TCM_CONFIGFS_SCRIPT"
exit 1
fi
fi
echo -n $"Calling ConfigFS script $TCM_CONFIGFS_SCRIPT for target_core_mod: "
if [ -f $TCM_CONFIGFS_SCRIPT ]; then
sh ${TCM_CONFIGFS_SCRIPT} > /dev/null 2>&1
RET=$?
if [ $RET == 0 ]; then
echo " [OK]"
else
echo " [FAILED]"
fi
fi
run_lio_target_cfs_ops $1
run_fabric_cfs_ops $1
}
function load_scsi_disk() {
if test "x`grep "sd" /proc/devices | awk '{ if ($2 == "sd") print "sd" }'`" != x ; then
:
else
echo -n $"Loading SCSI Disk: "
modprobe -q sd_mod
if lsmod | grep -q "^sd_mod" ; then
echo " [OK]"
else
echo -n $"SCSI Core ERROR, abort iSCSI Target Stack: "
echo "error"
exit 1
fi
fi
}
function check_configfs_mount() {
if [ ! -d /sys/kernel/config ]; then
modprobe configfs
mount -t configfs configfs /sys/kernel/config
RET=$?
if [ $RET != 0 ]; then
echo "ERROR: Unable to mount configfs on /sys/kernel/config"
return 1
fi
fi
}
function unload_lio_mode() {
echo -n $"Unload Linux-iSCSI.org Fabric module"
rmmod iscsi_target_mod
RETVAL=$?
if [ $RETVAL == 0 ]; then
echo " [OK]"
else
echo " [FAILED]: $RETVAL"
fi
}
function load_tcm_mod() {
check_configfs_mount
RETVAL=$?
if [ $RETVAL != 0 ]; then
return 1
fi
echo -n $"Loading target_core_mod/ConfigFS core: "
modprobe -q ${MODNAME} > /dev/null
RETVAL=$?
if [ $RETVAL == 0 ]; then
echo " [OK]"
else
echo " [FAILED]: $RETVAL"
fi
return 0
}
function shutdown_fabrics() {
echo -n $"Unloading fabric/configfs: "
${TCM_FABRIC} --unloadall
RETVAL=$?
if [ $RETVAL == 0 ]; then
echo " [OK]"
else
echo " [FAILED]: $RETVAL"
fi
}
function shutdown_lio_mod () {
if [ ! -d /sys/kernel/config/target/iscsi/ ]; then
return 0
fi
echo -n $"Unloading LIO-Target/ConfigFS fabric: "
${LIO_NODE} --unload
RETVAL=$?
if [ $RETVAL == 0 ]; then
echo " [OK]"
else
echo " [FAILED]: $RETVAL"
fi
}
function unload_tcm_mod() {
shutdown_fabrics
shutdown_lio_mod
echo -n $"Unloading target_core_mod/ConfigFS core: "
$TCM_NODE --unload
RETVAL=$?
if [ $RETVAL == 0 ]; then
echo " [OK]"
return 0
else
echo " [FAILED]: $RETVAL"
return 1
fi
}
start () {
if [ -d ${TCM_CFS_DIR} ]; then
echo -n $"Calling START $0 "
RETVAL=1
echo "ERROR, target_core_mod/ConfigFS already active"
return $RETVAL
fi
if test "x `lsmod | grep ${MODNAME} | awk '{ if ($$1 == "${MODNAME}") print $$1 }'`" == x ; then
echo -n $"Calling START $0 "
RETVAL=1
echo "ERROR, target_core_mod/ConfigFS already active"
return $RETVAL
else
if [ -e ${LOCK_TARGET} ]; then
rm -f ${LOCK_TARGET}
fi
fi
# Prevent multiple driver panics from hanging system (probably via scsi or target driver).
# HINT: Most likely cause is a problem within '/etc/iscsi/install.target'.
# Save a backup of the file, then NULL'd it to troubleshoot this variant.
if [ -e ${SEMA_TARGET} ]; then
RETVAL=1
echo "See ${SEMA_TARGET}"
return $RETVAL
fi
# Put message in semaphore file to aid in troubleshooting should
# the file still exist during a subsequent boot.
echo "$0: Created: " `date` > ${SEMA_TARGET}
echo "$0: " >> ${SEMA_TARGET}
echo "$0: This file has been created as a result of a potentially" >> ${SEMA_TARGET}
echo "$0: recursive module startup problem. Probable cause is an" >> ${SEMA_TARGET}
echo "$0: iSCSI device configuration problem which finds its way" >> ${SEMA_TARGET}
echo "$0: catastrophically into the Target Core Stack." >> ${SEMA_TARGET}
echo "$0: " >> ${SEMA_TARGET}
echo "$0: You must remove /var/crash/target.fault before attempting" >> ${SEMA_TARGET}
echo "$0: to start again." >> ${SEMA_TARGET}
echo "$0: " >> ${SEMA_TARGET}
echo "$0: Continued startup problems might be researched by saving" >> ${SEMA_TARGET}
echo "$0: off the current /etc/iscsi/install.target file and then" >> ${SEMA_TARGET}
echo "$0: replacing it with a dummy file which contains no entries." >> ${SEMA_TARGET}
echo "$0: If bootup is then successful, contact the iSCSI Target" >> ${SEMA_TARGET}
echo "$0: Stack manufacturer for assistance with problems within" >> ${SEMA_TARGET}
echo "$0: the target configuration file." >> ${SEMA_TARGET}
sync ; sync
# load_scsi_disk
if [ -e ${LOCK_TARGET} ]; then
rm -f ${SEMA_TARGET}
echo -n $"Calling START $0 "
RETVAL=1
echo "ERROR, target_core_mod already active"
return $RETVAL
fi
load_tcm_mod
if [ $RETVAL != 0 ]; then
rm -f ${SEMA_TARGET}
return $RETVAL
fi
sleep 1
${PGM_SET_TNAME}
RETVAL=$?
if [ $RETVAL == 2 ]; then
rm -f ${SEMA_TARGET}
unload_tcm_mod
return $RETVAL
fi
run_tcm_cfs_ops $1
touch ${LOCK_TARGET}
rm -f ${SEMA_TARGET}
return $RETVAL
}
stop () {
rm -f ${SEMA_TARGET}
unload_tcm_mod
RET=$?
if [ $RET != 0 ]; then
return 1
fi
sleep 1
rm -f ${LOCK_TARGET}
echo "Successfully unloaded target_core_mod/ConfigFS core"
return $RET
}
function lio_version () {
if [ ! -d ${LIO_CFS_DIR} ]; then
exit 1
fi
lio_node --version
}
function lio_status () {
if [ ! -d ${LIO_CFS_DIR} ]; then
exit 1
fi
lio_node --listendpoints
}
function tcm_version () {
if [ ! -d ${TCM_CFS_DIR} ]; then
exit 1
fi
tcm_node --version
}
function tcm_status () {
if [ ! -d ${TCM_CFS_DIR} ]; then
exit 1
fi
echo "[---------------------------] TCM/ConfigFS Status [----------------------------]"
tcm_node --listhbas
echo ""
echo "[---------------------------] LIO-Target Status [----------------------------]"
lio_status
echo ""
tcm_version
lio_version
}
restart () {
stop 1
start 0
RETVAL=$?
}
case "$1" in
start)
start 0
;;
startbak)
if [ "$ARGS_COUNT" -ne "$ARGS_CHECK" ]; then
echo "Usage: /etc/init.d/target startbak <DATE_TIME>"
exit 1
fi
start $2
;;
stop)
stop 1
;;
status)
tcm_status
RETVAL=$?
;;
restart|reload|force-reload)
restart 1
;;
*)
echo $"Usage: $0 {start|startbak|stop|status|restart}"
exit 1
esac
exit $?
|