| 4 |
- |
1 |
#!/bin/sh
|
|
|
2 |
#
|
|
|
3 |
# iscsi: log into iSCSI targets
|
|
|
4 |
#
|
|
|
5 |
# chkconfig: 345 13 89
|
|
|
6 |
# description: Logs into iSCSI targets needed at system startup
|
|
|
7 |
|
|
|
8 |
# Note we should have $network in Required-Start/Stop but we don't because if
|
|
|
9 |
# we would require network chkconfig will put us directly after NetworkManager
|
|
|
10 |
# when using NM, which will make our see if the network is up test succeed
|
|
|
11 |
# while NM is actually still configuring the network. By not requiring network
|
|
|
12 |
# chkconfig will use the chkconfig header to determine our start prio, starting
|
|
|
13 |
# us after the old network service, but before NM (netfs does this the same).
|
|
|
14 |
|
|
|
15 |
### BEGIN INIT INFO
|
|
|
16 |
# Provides: iscsi
|
|
|
17 |
# Required-Start: iscsid
|
|
|
18 |
# Required-Stop: iscsid
|
|
|
19 |
# Default-Start: 3 4 5
|
|
|
20 |
# Default-Stop: 0 1 2 6
|
|
|
21 |
# Short-Description: Starts and stops login and scanning of iSCSI devices.
|
|
|
22 |
# Description: iscsi provides the iSCSI state machine for software iscsi/iser
|
|
|
23 |
# and partial offloaded hardware. iscsi logs into and scans
|
|
|
24 |
# for iSCSI devices, and shuts them down when stopped.
|
|
|
25 |
### END INIT INFO
|
|
|
26 |
|
|
|
27 |
# Source function library.
|
|
|
28 |
. /etc/rc.d/init.d/functions
|
|
|
29 |
|
|
|
30 |
exec="/sbin/iscsiadm"
|
|
|
31 |
prog="iscsi"
|
|
|
32 |
config="/etc/iscsi/initiatorname.iscsi"
|
|
|
33 |
lockfile=/var/lock/subsys/$prog
|
|
|
34 |
iscsid_lockfile=/var/lock/subsys/${prog}_iscsid
|
|
|
35 |
|
|
|
36 |
start() {
|
|
|
37 |
[ -x $exec ] || exit 5
|
|
|
38 |
[ -f $config ] || exit 6
|
|
|
39 |
|
|
|
40 |
# if the network isn't up yet exit cleanly, NetworkManager will call us
|
|
|
41 |
# again when the network is up
|
|
|
42 |
[ ! -f /var/lock/subsys/network -a ! -f /var/lock/subsys/NetworkManager ] && exit 0
|
|
|
43 |
|
|
|
44 |
# if no nodes are setup to startup automatically exit cleanly
|
|
|
45 |
grep -qrs "node.startup = automatic" /var/lib/iscsi/nodes
|
|
|
46 |
[ $? -eq 0 ] || exit 0
|
|
|
47 |
|
|
|
48 |
# this script is normally called from startup so log into
|
|
|
49 |
# nodes marked node.startup=automatic
|
|
|
50 |
echo -n $"Starting $prog: "
|
|
|
51 |
$exec -m node --loginall=automatic 2>&1 > /dev/null | grep iscsiadm
|
|
|
52 |
# Ignore return code, because this command attempts to log into
|
|
|
53 |
# multiple sessions and some sessions could get logged into and
|
|
|
54 |
# some could be down temporarily.
|
|
|
55 |
success $"Starting $prog"
|
|
|
56 |
touch $lockfile
|
|
|
57 |
echo
|
|
|
58 |
return 0
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
iscsi_sessions_running() {
|
|
|
62 |
declare -a iparams=( $(iscsiadm -m session 2>/dev/null | egrep "tcp|iser|bnx2i|be2iscsi|cxgb3i|cxgb4i") )
|
|
|
63 |
if [[ -z "${iparams[*]}" ]]; then
|
|
|
64 |
# no sessions
|
|
|
65 |
return 2
|
|
|
66 |
fi
|
|
|
67 |
|
|
|
68 |
return 0
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
cleanup_successful_stop() {
|
|
|
72 |
success $"Stopping $prog"
|
|
|
73 |
rm -f $lockfile
|
|
|
74 |
echo
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
stop() {
|
|
|
78 |
# Don't turn off iscsi if root is possibly on a iscsi disk.
|
|
|
79 |
rootopts=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $4; }}' /etc/mtab)
|
|
|
80 |
if [[ "$rootopts" =~ "_netdev" ]] ; then
|
|
|
81 |
echo $"Can not shutdown iSCSI. Root is on a iSCSI disk."
|
|
|
82 |
|
|
|
83 |
# Just clean up lock file if this is a system shutdown/reboot.
|
|
|
84 |
if [ "$RUNLEVEL" = "6" -o "$RUNLEVEL" = "0" -o "$RUNLEVEL" = "1" ]; then
|
|
|
85 |
rm -f $lockfile
|
|
|
86 |
fi
|
|
|
87 |
|
|
|
88 |
exit 1
|
|
|
89 |
fi
|
|
|
90 |
|
|
|
91 |
echo -n $"Stopping $prog: "
|
|
|
92 |
|
|
|
93 |
if ! iscsi_sessions_running ; then
|
|
|
94 |
cleanup_successful_stop
|
|
|
95 |
return 0
|
|
|
96 |
fi
|
|
|
97 |
|
|
|
98 |
if [ "$RUNLEVEL" = "6" -o "$RUNLEVEL" = "0" -o "$RUNLEVEL" = "1" ]; then
|
|
|
99 |
$exec -m node --logoutall=all 2>&1 > /dev/null
|
|
|
100 |
else
|
|
|
101 |
$exec -m node --logoutall=automatic 2>&1 > /dev/null
|
|
|
102 |
fi
|
|
|
103 |
|
|
|
104 |
ret=$?
|
|
|
105 |
# ignore ISCSI_ERR_NO_OBJS_FOUND/21
|
|
|
106 |
if [[ "$ret" -ne 0 && "$ret" -ne 21 ]]; then
|
|
|
107 |
failure $"Stopping $prog"
|
|
|
108 |
echo
|
|
|
109 |
return 1
|
|
|
110 |
fi
|
|
|
111 |
|
|
|
112 |
cleanup_successful_stop
|
|
|
113 |
return 0
|
|
|
114 |
}
|
|
|
115 |
|
|
|
116 |
restart() {
|
|
|
117 |
stop
|
|
|
118 |
start
|
|
|
119 |
}
|
|
|
120 |
|
|
|
121 |
reload() {
|
|
|
122 |
return 3
|
|
|
123 |
}
|
|
|
124 |
|
|
|
125 |
force_reload() {
|
|
|
126 |
restart
|
|
|
127 |
}
|
|
|
128 |
|
|
|
129 |
rh_status() {
|
|
|
130 |
[ -f $lockfile ] || { echo $"$prog is stopped" ; return 3 ; }
|
|
|
131 |
|
|
|
132 |
declare -a iparams=( $(iscsiadm -m session 2>/dev/null | egrep "tcp|iser|bnx2i|be2iscsi|cxgb3i|cxgb4i") )
|
|
|
133 |
if [[ -z "${iparams[*]}" ]]; then
|
|
|
134 |
# no sessions
|
|
|
135 |
echo $"No active sessions"
|
|
|
136 |
return 2
|
|
|
137 |
fi
|
|
|
138 |
|
|
|
139 |
iscsiadm -m session -P 3
|
|
|
140 |
return 0
|
|
|
141 |
}
|
|
|
142 |
|
|
|
143 |
rh_status_q() {
|
|
|
144 |
rh_status >/dev/null 2>&1
|
|
|
145 |
}
|
|
|
146 |
|
|
|
147 |
|
|
|
148 |
case "$1" in
|
|
|
149 |
start)
|
|
|
150 |
rh_status_q && exit 0
|
|
|
151 |
$1
|
|
|
152 |
;;
|
|
|
153 |
stop)
|
|
|
154 |
$1
|
|
|
155 |
;;
|
|
|
156 |
restart)
|
|
|
157 |
$1
|
|
|
158 |
;;
|
|
|
159 |
reload)
|
|
|
160 |
rh_status_q || exit 7
|
|
|
161 |
$1
|
|
|
162 |
;;
|
|
|
163 |
force-reload)
|
|
|
164 |
force_reload
|
|
|
165 |
;;
|
|
|
166 |
status)
|
|
|
167 |
rh_status
|
|
|
168 |
;;
|
|
|
169 |
condrestart|try-restart)
|
|
|
170 |
rh_status_q || exit 0
|
|
|
171 |
restart
|
|
|
172 |
;;
|
|
|
173 |
*)
|
|
|
174 |
echo $"Usage: $0
|
|
|
175 |
{start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
|
|
|
176 |
exit 2
|
|
|
177 |
esac
|
|
|
178 |
exit $?
|