Subversion Repositories configs

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4 - 1
#!/bin/sh
2
#
3
# chkconfig: - 39 35
4
#
5
### BEGIN INIT INFO
6
# Provides:          tgtd
7
# Required-Start:    $network
8
# Short-Description: Starts and stops the generic storage target daemon
9
# Description: tgtd provides the SCSI and software transport target state
10
#              machine daemon.
11
### END INIT INFO
12
#
13
#
14
# pidfile: /var/run/tgtd.pid
15
#
16
# Source function library.
17
. /etc/init.d/functions
18
 
19
PATH=/sbin:/bin:/usr/sbin:/usr/bin
20
TGTD_CONFIG=/etc/tgt/targets.conf
21
 
22
prog="SCSI target daemon"
23
exec=tgtd
24
lockfile=/var/lock/subsys/$exec
25
 
26
start()
27
{
28
	# Check for and source configuration file otherwise use defaults above
29
	[ -f /etc/sysconfig/$exec ] && . /etc/sysconfig/$exec
30
 
31
	[ -x /usr/sbin/$exec ] || exit 5
32
	echo -n $"Starting $prog: "
33
	# Note /dev/null redirection to silence rdma not found messages
34
	daemon $exec ${TGTD_OPTIONS} >/dev/null 2>&1
35
	retval=$?
36
	if [ $retval -ne 0 ] ; then
37
		failure
38
		echo
39
		return $retval
40
	fi
41
 
42
	success
43
	echo
44
	touch $lockfile
45
 
46
	# Put tgtd into "offline" state until all the targets are configured.
47
	# We don't want initiators to (re)connect and fail the connection
48
	# if it's not ready.
49
	tgtadm --op update --mode sys --name State -v offline
50
	# Configure the targets.
51
	tgt-admin -e -c $TGTD_CONFIG
52
	# Put tgtd into "ready" state.
53
	tgtadm --op update --mode sys --name State -v ready
54
 
55
	return 0
56
}
57
 
58
stop()
59
{
60
	if [ "$RUNLEVEL" == 0 -o "$RUNLEVEL" == 6 ] ; then
61
		force_stop
62
		return $?
63
	fi
64
 
65
	echo -n $"Stopping $prog: "
66
	# Remove all targets. It only removes targets which are not in use.
67
	tgt-admin --update ALL -c /dev/null >/dev/null 2>&1
68
	# tgtd will exit if all targets were removed
69
	tgtadm --op delete --mode system >/dev/null 2>&1
70
	retval=$?
71
	if [ "$retval" -eq 107 ] ; then
72
		echo -n $"not running"
73
		failure
74
		echo
75
		return 7
76
	elif [ "$retval" -ne 0 ] ; then
77
		echo -n $"initiators still connected"
78
		failure
79
		echo
80
		return 1
81
	fi
82
 
83
	success
84
	echo
85
	rm -f $lockfile
86
	return 0
87
}
88
 
89
force_stop()
90
{
91
	# NOTE: Forced shutdown of the iscsi target may cause data corruption
92
	# for initiators that are connected.
93
	echo -n $"Force-stopping $prog: "
94
	# Offline everything first. May be needed if we're rebooting, but
95
	# expect the initiators to reconnect cleanly when we boot again
96
	# (i.e. we don't want them to reconnect to a tgtd which is still
97
	# working, but the target is gone).
98
	tgtadm --op update --mode sys --name State -v offline >/dev/null 2>&1
99
	retval=$?
100
	if [ "$retval" -eq 107 ] ; then
101
		echo -n $"not running"
102
		failure
103
		echo
104
		return 7
105
	else
106
		tgt-admin --offline ALL
107
		# Remove all targets, even if they are still in use.
108
		tgt-admin --update ALL -c /dev/null -f
109
		# It will shut down tgtd only after all targets were removed.
110
		tgtadm --op delete --mode system
111
		retval=$?
112
		if [ "$retval" -ne 0 ] ; then
113
			failure
114
			echo
115
			return 1
116
		fi
117
	fi
118
 
119
	success
120
	echo
121
	rm -f $lockfile
122
	return 0
123
}
124
 
125
reload() {
126
	# Check for and source configuration file otherwise use defaults above
127
	[ -f /etc/sysconfig/$exec ] && . /etc/sysconfig/$exec
128
 
129
	echo -n $"Updating $prog configuration: "
130
	# Update configuration for targets. Only targets which
131
	# are not in use will be updated.
132
	tgt-admin --update ALL -c $TGTD_CONFIG >/dev/null 2>&1
133
	retval=$?
134
	if [ "$retval" -eq 107 ] ; then
135
		echo -n $"not running"
136
		failure
137
		echo
138
		return 7
139
	elif [ "$retval" -ne 0 ] ; then
140
		failure
141
		echo
142
		return 1
143
	fi
144
 
145
	success
146
	echo
147
	return 0
148
}
149
 
150
force_reload() {
151
	# Check for and source configuration file otherwise use defaults above
152
	[ -f /etc/sysconfig/$exec ] && . /etc/sysconfig/$exec
153
 
154
	echo -n $"Force-updating $prog configuration: "
155
	# Update configuration for targets, even those in use.
156
	tgt-admin --update ALL -f -c $TGTD_CONFIG >/dev/null 2>&1
157
	retval=$?
158
	if [ "$retval" -eq 107 ] ; then
159
		echo -n $"not running"
160
		failure
161
		echo
162
		return 7
163
	elif [ "$retval" -ne 0 ] ; then
164
		failure
165
		echo
166
		return 1
167
	fi
168
 
169
	success
170
	echo
171
	return 0
172
}
173
 
174
restart() {
175
	stop
176
	start
177
}
178
 
179
rh_status() {
180
	# run checks to determine if the service is running or use generic status
181
	status $exec
182
}
183
 
184
rh_status_q() {
185
	rh_status >/dev/null 2>&1
186
}
187
 
188
case "$1" in
189
	start)
190
		[ `id -u` = 0 ] || exit 4
191
 
192
		rh_status_q && exit 0
193
		$1
194
		;;
195
	stop)
196
		[ `id -u` = 0 ] || exit 4
197
 
198
		rh_status_q || exit 0
199
		$1
200
		;;
201
	force-stop)
202
		[ `id -u` = 0 ] || exit 4
203
		force_stop
204
		;;
205
	restart)
206
		[ `id -u` = 0 ] || exit 4
207
 
208
		restart
209
		;;
210
	force-restart)
211
		[ `id -u` = 0 ] || exit 4
212
 
213
		force_stop
214
		start
215
		;;
216
	reload)
217
		[ `id -u` = 0 ] || exit 4
218
 
219
		rh_status_q || exit 7
220
		$1
221
		;;
222
	force-reload)
223
		[ `id -u` = 0 ] || exit 4
224
		force_reload
225
		;;
226
	status)
227
		rh_status
228
		;;
229
	condrestart|try-restart)
230
		[ `id -u` = 0 ] || exit 4
231
 
232
		rh_status_q || exit 0
233
		restart
234
		;;
235
	*)
236
		echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-stop|force-restart|force-reload}"
237
		exit 2
238
esac
239
exit $?