~upstart-devel/upstart/upstart-jobs

« back to all changes in this revision

Viewing changes to vivid/etc/init.d/open-iscsi

  • Committer: Dimitri John Ledkov
  • Date: 2014-11-19 12:58:41 UTC
  • Revision ID: dimitri.j.ledkov@intel.com-20141119125841-98dr37roy8dvcv3b
auto update

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /bin/sh
 
2
### BEGIN INIT INFO
 
3
# Provides:          open-iscsi iscsi
 
4
# Required-Start:    $network $remote_fs
 
5
# Required-Stop:     $network $remote_fs sendsigs
 
6
# Default-Start:     S
 
7
# Default-Stop:      0 1 6
 
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
 
10
### END INIT INFO
 
11
 
 
12
PATH=/sbin:/bin:/usr/sbin:/usr/bin
 
13
DAEMON=/usr/sbin/iscsid
 
14
ADM=/usr/bin/iscsiadm
 
15
PIDFILE=/run/iscsid.pid
 
16
NAMEFILE=/etc/iscsi/initiatorname.iscsi
 
17
CONFIGFILE=/etc/iscsi/iscsid.conf
 
18
 
 
19
[ -x "$DAEMON" ] || exit 0
 
20
 
 
21
. /lib/lsb/init-functions
 
22
 
 
23
# Include defaults if available
 
24
if [ -f /etc/default/open-iscsi ]; then
 
25
        . /etc/default/open-iscsi
 
26
fi
 
27
 
 
28
 
 
29
if [ ! -d /sys/class/ ]; then
 
30
  log_failure_msg "iSCSI requires a mounted sysfs, not started."
 
31
  exit 0
 
32
fi
 
33
 
 
34
nodestartup_re='s/^node\.conn\[0]\.startup[     ]*=[    ]*//p'
 
35
 
 
36
RETVAL=0
 
37
 
 
38
sanitychecks() {
 
39
        # Do sanity checks before we start..
 
40
        if [ ! -e "$CONFIGFILE" ]; then
 
41
                echo
 
42
                echo "Error: configuration file $CONFIGFILE is missing!"
 
43
                echo "The iSCSI driver has not been correctly installed and cannot start."
 
44
                echo
 
45
                exit 1
 
46
        elif [ -s $PIDFILE ] && kill -0 `head -1 $PIDFILE` >/dev/null ; then
 
47
                echo
 
48
                echo "iSCSI daemon already running"
 
49
                echo
 
50
                exit 0
 
51
        fi
 
52
 
 
53
        if [ ! -f $NAMEFILE ] ; then
 
54
            echo
 
55
            echo "Error: InitiatorName file $NAMEFILE is missing!"
 
56
            echo "The iSCSI driver has not been correctly installed and cannot start."
 
57
            echo
 
58
            exit 1
 
59
        fi
 
60
 
 
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"
 
66
                exit 1;
 
67
            fi
 
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
 
77
                chmod 600 $NAMEFILE
 
78
            else
 
79
                echo "Error: failed to generate an iSCSI InitiatorName, driver cannot start."
 
80
                echo
 
81
                exit 1;
 
82
            fi
 
83
        fi
 
84
 
 
85
        # make sure there is a valid InitiatorName for the driver
 
86
        if ! grep -q "^InitiatorName=[^ \t\n]" $NAMEFILE ; then
 
87
            echo
 
88
            echo "Error: $NAMEFILE does not contain a valid InitiatorName."
 
89
            echo "The iSCSI driver has not been correctly installed and cannot start."
 
90
            echo
 
91
            exit 1
 
92
        fi
 
93
}
 
94
 
 
95
start() {
 
96
        log_daemon_msg "Starting iSCSI initiator service" "iscsid"
 
97
        sanitychecks
 
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
 
101
        RETVAL=$?
 
102
        log_end_msg $RETVAL
 
103
 
 
104
        starttargets
 
105
 
 
106
        udevadm settle || true;
 
107
 
 
108
 
 
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."
 
112
                LMVGROUPS=""
 
113
        fi
 
114
 
 
115
        if [ -n "$LVMGROUPS" ]; then
 
116
                log_daemon_msg "Activating iSCSI volume groups"
 
117
                for vg in "$LVMGROUPS"; do
 
118
                        log_progress_msg $vg
 
119
                        vgchange --available=y $vg
 
120
                done
 
121
                log_end_msg 0
 
122
        fi
 
123
 
 
124
        # Now let's mount
 
125
        log_daemon_msg "Mounting network filesystems"
 
126
        MOUNT_RESULT=1
 
127
        if mount -a -O _netdev >/dev/null 2>&1; then
 
128
                MOUNT_RESULT=0
 
129
                break
 
130
        fi
 
131
        log_end_msg $MOUNT_RESULT
 
132
}
 
133
 
 
134
starttargets() {
 
135
        log_daemon_msg "Setting up iSCSI targets"
 
136
        echo
 
137
        $ADM -m node --loginall=automatic
 
138
        log_end_msg 0
 
139
}
 
140
 
 
141
stoptargets() {
 
142
        log_daemon_msg "Disconnecting iSCSI targets"
 
143
        sync
 
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
 
147
        fi
 
148
 
 
149
        log_end_msg 0
 
150
}
 
151
 
 
152
stop() {
 
153
        if [ -f /etc/iscsi/iscsi.initramfs ]; then
 
154
                log_warning_msg "/etc/iscsi/iscsi.initramfs present, not stopping iscsid yet"
 
155
                return 0
 
156
        fi
 
157
 
 
158
        # Call umountiscsi.sh to unmount iSCSI devices first
 
159
        invoke-rc.d umountiscsi.sh stop
 
160
        exit_status=$?
 
161
        if [ $exit_status -ne 0 ]; then
 
162
                log_failure_msg "Couldn't unmount all iSCSI devices. Cannot stop iSCSI service"
 
163
                exit 1
 
164
        fi
 
165
 
 
166
        stoptargets
 
167
        log_daemon_msg "Stopping iSCSI initiator service"
 
168
        start-stop-daemon --stop --quiet --pidfile $PIDFILE --signal TERM --exec $DAEMON
 
169
        rm -f $PIDFILE
 
170
        modprobe -r ib_iser 2>/dev/null
 
171
        modprobe -r iscsi_tcp 2>/dev/null
 
172
        log_end_msg 0
 
173
}
 
174
 
 
175
restart() {
 
176
        stop
 
177
        start
 
178
}
 
179
 
 
180
restarttargets() {
 
181
        stoptargets
 
182
        starttargets
 
183
}
 
184
 
 
185
status() {
 
186
        #XXX FIXME: what to do here?
 
187
        #status iscsid
 
188
        # list active sessions
 
189
        echo Current active iSCSI sessions:
 
190
        $ADM -m session
 
191
}
 
192
 
 
193
case "$1" in
 
194
        start|starttargets|stop|stoptargets|restart|restarttargets|status)
 
195
                $1
 
196
                ;;
 
197
        force-reload)
 
198
                restart
 
199
                ;;
 
200
        *)
 
201
                echo "Usage: $0 {start|stop|restart|force-reload|status}"
 
202
                exit 1
 
203
                ;;
 
204
esac
 
205
exit $RETVAL