/etc/init.d/target is in targetcli 1:3.0~pre4.1~ga55d018-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 | #! /bin/sh
### BEGIN INIT INFO
# Provides: target
# Required-Start: $network $remote_fs $syslog
# Required-Stop: $network $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: The Linux SCSI Target service
### END INIT INFO
# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="The Linux SCSI Target"
NAME=target
DAEMON=/usr/bin/targetcli
DAEMON_ARGS=""
SCRIPTNAME=/etc/init.d/$NAME
CFS_BASE="/sys/kernel/config"
CFS_TGT="${CFS_BASE}/target"
CORE_MODS="target_core_mod target_core_pscsi target_core_iblock target_core_file"
STARTUP_CONFIG="/etc/target/scsi_target.lio"
# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
# How we log messages depends on the system
if [ -r /lib/lsb/init-functions ]; then
# LSB systems like Debian
. /lib/lsb/init-functions
elif [ -r /etc/init.d/functions ]; then
# RHEL without optional redhat-lsb
. /etc/init.d/functions
fi
is_func() {
type $1 2>/dev/null | grep -q 'function'
}
log_success () {
if is_func log_success_msg; then
log_success_msg "$*"
elif is_func success; then
echo -n $*; success "$*"; echo
else
echo "[ ok ] $*"
fi
}
log_failure () {
if is_func log_failure_msg; then
log_failure_msg "$*"
elif is_func failure; then
echo -n $*; failure "$*"; echo
else
echo "[FAIL] $* ... failed!"
fi
}
log_warning () {
if is_func log_warning_msg; then
log_warning_msg "$*"
elif is_func warning; then
echo -n $*; warning "$*"; echo
else
echo "[warn] $* ... (warning)."
fi
}
log_action () {
if is_func log_action_msg; then
log_action_msg "$*"
elif is_func action; then
echo -n $*; passed "$*"; echo
else
echo "[info] $*."
fi
}
load_specfiles()
{
FABRIC_MODS=$(python << EOF
from rtslib import list_specfiles, parse_specfile
print(" ".join(["%(kernel_module)s:%(configfs_group)s" % parse_specfile(spec)
for spec in list_specfiles()]))
EOF
)
}
save_running_config()
{
python << EOF
import rtslib
config = rtslib.Config()
config.load_live()
config.save("${STARTUP_CONFIG}")
EOF
}
check_install()
{
# Check the system installation
INSTALL=ok
python -c "from rtslib import Config" > /dev/null 2>&1
if [ $? != 0 ]; then
log_failure "Cannot load rtslib"
INSTALL=nok
fi
SYSTEM_DIRS="/var/target/pr /var/target/alua /etc/target"
for DIR in ${SYSTEM_DIRS}; do
if [ ! -d ${DIR} ]; then
log_warning "Creating missing directory ${DIR}"
mkdir -p ${DIR}
fi
done
if [ "${INSTALL}" != ok ]; then
exit 0
else
log_action "${DESC} looks properly installed"
fi
}
load_configfs()
{
modprobe configfs > /dev/null 2>&1
if [ "$?" != 0 ]; then
log_failure "Failed to load configfs kernel module"
return 1
fi
mount -t configfs configfs ${CFS_BASE} > /dev/null 2>&1
case "$?" in
0) log_warning "The configfs filesystem was not mounted, consider adding it to fstab";;
32) log_action "The configfs filesystem is already mounted";;
*) log_failure "Failed to mount configfs"; return 1;;
esac
}
load_modules()
{
for MODULE in ${CORE_MODS}; do
if [ ! -z "$(cat /proc/modules | grep ^${MODULE}\ )" ]; then
log_warning "Core module ${MODULE} already loaded"
else
modprobe "${MODULE}" > /dev/null 2>&1
if [ "$?" != 0 ]; then
log_failure "Failed to load core module ${MODULE}"
return 1
else
log_action "Loaded core module ${MODULE}"
fi
fi
done
for MOD_SPEC in ${FABRIC_MODS}; do
MODULE="$(echo ${MOD_SPEC} | awk -F : '{print $1}')"
if [ ! -z "$(cat /proc/modules | grep ^${MODULE}\ )" ]; then
log_warning "Fabric module ${MODULE} already loaded"
else
modprobe "${MODULE}" > /dev/null 2>&1
if [ "$?" != 0 ]; then
log_warning "Failed to load fabric module ${MODULE}"
else
log_action "Loaded fabric module ${MODULE}"
fi
fi
done
}
unload_modules()
{
RETCODE=0
for MOD_SPEC in ${FABRIC_MODS}; do
MODULE="$(echo ${MOD_SPEC} | awk -F : '{print $1}')"
CFS_GROUP="${CFS_TGT}/$(echo ${MOD_SPEC} | awk -F : '{print $2}')"
if [ ! -z "$(lsmod | grep ^${MODULE}\ )" ]; then
rmdir "${CFS_GROUP}" > /dev/null 2>&1
if [ -d "${CFS_GROUP}" ]; then
log_failure "Failed to remove ${CFS_GROUP}"
RETCODE=1
else
rmmod "${MODULE}" > /dev/null 2>&1
if [ "$?" != 0 ]; then
log_failure "Failed to unload fabric module ${MODULE}"
RETCODE=1
else
log_action "Unloaded ${MODULE} fabric module"
fi
fi
else
log_warning "Fabric module ${MODULE} is not loaded"
fi
done
MODULES="$(echo ${CORE_MODS} | tac -s ' ')"
for MODULE in ${MODULES}; do
if [ ! -z "$(lsmod | grep ^${MODULE}\ )" ]; then
rmmod "${MODULE}" > /dev/null 2>&1
if [ "$?" != 0 ]; then
log_failure "Failed to unload target core module ${MODULE}"
RETCODE=1
else
log_action "Unloaded ${MODULE} target core module"
fi
else
log_warning "Target core module ${MODULE} is not loaded"
fi
done
return "${RETCODE}"
}
load_config()
{
if [ $(cat /etc/target/scsi_target.lio 2>/dev/null | tr -d " \n\t" | wc -c) = 0 ]; then
log_warning "Startup config ${STARTUP_CONFIG} is empty, skipping"
elif [ -e "${STARTUP_CONFIG}" ]; then
export __STARTUP_CONFIG="${STARTUP_CONFIG}"
python 2> /dev/null << EOF
import os, rtslib
config = rtslib.Config()
config.load(os.environ['__STARTUP_CONFIG'], allow_new_attrs=True)
list(config.apply())
EOF
if [ "$?" != 0 ]; then
unset __STARTUP_CONFIG
log_failure "Failed to load ${STARTUP_CONFIG}"
return 1
else
unset __STARTUP_CONFIG
log_action "Loaded ${STARTUP_CONFIG}"
fi
else
log_warning "No ${STARTUP_CONFIG} to load"
fi
}
clear_config()
{
python 2> /dev/null << EOF
from rtslib import Config
config = Config()
list(config.apply())
EOF
if [ "$?" != 0 ]; then
log_failure "Failed to clear configuration"
return 1
else
log_action "Cleared configuration"
fi
}
do_start()
{
# If the target is running and we do not have a config file on the
# system, dump the running system config to the config file. This
# helps migrating away from lio-utils or other legacy/devel systems.
if [ ! -e "${STARTUP_CONFIG}" ] && [ $(ls /sys/kernel/config/target/core/ 2>/dev/null | wc -l) -gt 1 ]; then
log_action "Possible config migration detected, saving the " \
"running target to ${STARTUP_CONFIG}"
save_running_config
elif [ -d ${CFS_TGT} ]; then
log_failure "Not starting: ${CFS_TGT} already exists"
return 1
fi
load_specfiles # Fill in FABRIC_MODS and CFS_GROUPS
check_install && load_configfs && load_modules && load_config
if [ "$?" != 0 ]; then
log_failure "Could not start ${DESC}"
return 1
else
log_success "Started ${DESC}"
fi
}
do_stop()
{
if [ ! -d ${CFS_TGT} ]; then
log_success "${DESC} is already stopped"
else
load_specfiles # Fill in FABRIC_MODS and CFS_GROUPS
clear_config && unload_modules
if [ "$?" != 0 ]; then
log_failure "Could not stop ${DESC}"
return 1
else
log_success "Stopped ${DESC}"
fi
fi
}
do_status()
{
if [ -d ${CFS_TGT} ]; then
log_action "${DESC} is started"
return 0
else
log_action "${DESC} is stopped"
return 1
fi
}
case "$1" in
start)
# FIXME This is because stop fails with systemd on debian jessie
do_stop
do_start
;;
stop)
do_stop
;;
status)
do_status ;;
restart|force-reload)
do_stop && do_start ;;
*)
echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
exit 3
;;
esac
|