3
# Provides: open-iscsi iscsi
4
# Required-Start: $network $remote_fs
5
# Required-Stop: $network $remote_fs sendsigs
8
# Short-Description: Starts and stops the iSCSI initiator services and logs in to default targets
9
# Description: Starts and stops the iSCSI initiator services and logs in to default targets
12
PATH=/sbin:/bin:/usr/sbin:/usr/bin
13
DAEMON=/usr/sbin/iscsid
15
PIDFILE=/run/iscsid.pid
16
NAMEFILE=/etc/iscsi/initiatorname.iscsi
17
CONFIGFILE=/etc/iscsi/iscsid.conf
19
[ -x "$DAEMON" ] || exit 0
21
. /lib/lsb/init-functions
23
# Include defaults if available
24
if [ -f /etc/default/open-iscsi ]; then
25
. /etc/default/open-iscsi
29
if [ ! -d /sys/class/ ]; then
30
log_failure_msg "iSCSI requires a mounted sysfs, not started."
34
nodestartup_re='s/^node\.conn\[0]\.startup[ ]*=[ ]*//p'
39
# Do sanity checks before we start..
40
if [ ! -e "$CONFIGFILE" ]; then
42
echo "Error: configuration file $CONFIGFILE is missing!"
43
echo "The iSCSI driver has not been correctly installed and cannot start."
46
elif [ -s $PIDFILE ] && kill -0 `head -1 $PIDFILE` >/dev/null ; then
48
echo "iSCSI daemon already running"
53
if [ ! -f $NAMEFILE ] ; then
55
echo "Error: InitiatorName file $NAMEFILE is missing!"
56
echo "The iSCSI driver has not been correctly installed and cannot start."
61
# see if we need to generate a unique iSCSI InitiatorName
62
# this should only happen if the
63
if grep -q "^GenerateName=yes" $NAMEFILE ; then
64
if [ ! -x /usr/sbin/iscsi-iname ] ; then
65
echo "Error: /usr/sbin/iscsi-iname does not exist, driver was not successfully installed"
68
# Generate a unique InitiatorName and save it
69
INAME=`/usr/sbin/iscsi-iname -p iqn.1993-08.org.debian:01`
70
if [ "$INAME" != "" ] ; then
71
echo "## DO NOT EDIT OR REMOVE THIS FILE!" > $NAMEFILE
72
echo "## If you remove this file, the iSCSI daemon will not start." >> $NAMEFILE
73
echo "## If you change the InitiatorName, existing access control lists" >> $NAMEFILE
74
echo "## may reject this initiator. The InitiatorName must be unique">> $NAMEFILE
75
echo "## for each iSCSI initiator. Do NOT duplicate iSCSI InitiatorNames." >> $NAMEFILE
76
printf "InitiatorName=$INAME\n" >> $NAMEFILE
79
echo "Error: failed to generate an iSCSI InitiatorName, driver cannot start."
85
# make sure there is a valid InitiatorName for the driver
86
if ! grep -q "^InitiatorName=[^ \t\n]" $NAMEFILE ; then
88
echo "Error: $NAMEFILE does not contain a valid InitiatorName."
89
echo "The iSCSI driver has not been correctly installed and cannot start."
96
log_daemon_msg "Starting iSCSI initiator service" "iscsid"
98
modprobe -q iscsi_tcp 2>/dev/null || :
99
modprobe -q ib_iser 2>/dev/null || :
100
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON
106
udevadm settle || true;
109
# Handle iSCSI LVM devices
110
if [ ! -x "/sbin/vgchange" -a -n "$LVMGROUPS" ]; then
111
log_warning_msg "LVM2 tools are not installed, not honouring LVMGROUPS."
115
if [ -n "$LVMGROUPS" ]; then
116
log_daemon_msg "Activating iSCSI volume groups"
117
for vg in "$LVMGROUPS"; do
119
vgchange --available=y $vg
125
log_daemon_msg "Mounting network filesystems"
127
if mount -a -O _netdev >/dev/null 2>&1; then
131
log_end_msg $MOUNT_RESULT
135
log_daemon_msg "Setting up iSCSI targets"
137
$ADM -m node --loginall=automatic
142
log_daemon_msg "Disconnecting iSCSI targets"
144
# only logout if daemon is running, iscsiadm hangs otherwise
145
if [ -s $PIDFILE ] && kill -0 `head -1 $PIDFILE` >/dev/null ; then
146
$ADM -m node --logoutall=all
153
if [ -f /etc/iscsi/iscsi.initramfs ]; then
154
log_warning_msg "/etc/iscsi/iscsi.initramfs present, not stopping iscsid yet"
158
# Call umountiscsi.sh to unmount iSCSI devices first
159
invoke-rc.d umountiscsi.sh stop
161
if [ $exit_status -ne 0 ]; then
162
log_failure_msg "Couldn't unmount all iSCSI devices. Cannot stop iSCSI service"
167
log_daemon_msg "Stopping iSCSI initiator service"
168
start-stop-daemon --stop --quiet --pidfile $PIDFILE --signal TERM --exec $DAEMON
170
modprobe -r ib_iser 2>/dev/null
171
modprobe -r iscsi_tcp 2>/dev/null
186
#XXX FIXME: what to do here?
188
# list active sessions
189
echo Current active iSCSI sessions:
194
start|starttargets|stop|stoptargets|restart|restarttargets|status)
201
echo "Usage: $0 {start|stop|restart|force-reload|status}"