/[vps]/baselayout-vserver/branches/baselayout-1_12/sbin/runscript.sh
Gentoo

Diff of /baselayout-vserver/branches/baselayout-1_12/sbin/runscript.sh

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 205 Revision 206
15svcpause="no" 15svcpause="no"
16svcrestart="no" 16svcrestart="no"
17 17
18myscript="$1" 18myscript="$1"
19if [[ -L $1 && ! -L "/etc/init.d/${1##*/}" ]] ; then 19if [[ -L $1 && ! -L "/etc/init.d/${1##*/}" ]] ; then
20 myservice="$(readlink $1)" 20 myservice="$(readlink "$1")"
21else 21else
22 myservice="$1" 22 myservice="$1"
23fi 23fi
24 24
25myservice="${myservice##*/}" 25myservice="${myservice##*/}"
26export SVCNAME="${myservice}" 26export SVCNAME="${myservice}"
27mylevel="$(<${svcdir}/softlevel)" 27mylevel="$(< "${svcdir}/softlevel")"
28 28
29svc_trap() { 29svc_trap() {
30 trap 'eerror "ERROR: \"${myservice}\" caught an interrupt"; exit 1' \ 30 trap 'eerror "ERROR: \"${myservice}\" caught an interrupt"; exit 1' \
31 INT QUIT TSTP 31 INT QUIT TSTP
32} 32}
57# there (if it exists). 57# there (if it exists).
58if [[ ${NETSERVICE} == "yes" ]] ; then 58if [[ ${NETSERVICE} == "yes" ]] ; then
59 conf="$(add_suffix /etc/conf.d/net)" 59 conf="$(add_suffix /etc/conf.d/net)"
60 [[ -e ${conf} ]] && source "${conf}" 60 [[ -e ${conf} ]] && source "${conf}"
61fi 61fi
62conf="$(add_suffix /etc/conf.d/${myservice})" 62conf="$(add_suffix "/etc/conf.d/${myservice}")"
63[[ -e ${conf} ]] && source "${conf}" 63[[ -e ${conf} ]] && source "${conf}"
64conf="$(add_suffix /etc/rc.conf)" 64conf="$(add_suffix /etc/rc.conf)"
65[[ -e ${conf} ]] && source "${conf}" 65[[ -e ${conf} ]] && source "${conf}"
66 66
67# Call svc_quit if we abort AND we have obtained a lock 67# Call svc_quit if we abort AND we have obtained a lock
68svcbegun=1
69service_started "${myservice}" 68service_started "${myservice}"
70svcstarted=$? 69svcstarted="$?"
70service_inactive "${myservice}"
71svcinactive="$?"
71svc_quit() { 72svc_quit() {
72 eerror "ERROR: \"${myservice}\" caught an interrupt" 73 eerror "ERROR: ${myservice} caught an interrupt"
73 if [[ ${svcbegun} == 0 ]] ; then
74 end_service "${myservice}" 74 end_service "${myservice}"
75 svcbegun=1 75 if service_inactive "${myservice}" || [[ ${svcinactive} == 0 ]] ; then
76 fi 76 mark_service_inactive "${myservice}"
77 if [[ ${svcstarted} == 0 ]] ; then 77 elif [[ ${svcstarted} == 0 ]] ; then
78 mark_service_started "${myservice}" 78 mark_service_started "${myservice}"
79 else 79 else
80 mark_service_stopped "${myservice}" 80 mark_service_stopped "${myservice}"
81 fi 81 fi
82 exit 1 82 exit 1
94 # Return success so the symlink gets removed 94 # Return success so the symlink gets removed
95 return 0 95 return 0
96} 96}
97 97
98start() { 98start() {
99 eerror "ERROR: \"${myservice}\" does not have a start function." 99 eerror "ERROR: ${myservice} does not have a start function."
100 # Return failure so the symlink doesn't get created 100 # Return failure so the symlink doesn't get created
101 return 1 101 return 1
102} 102}
103 103
104restart() { 104restart() {
105 svc_restart || return $? 105 svc_restart
106} 106}
107 107
108status() { 108status() {
109 # Dummy function 109 # Dummy function
110 return 0 110 return 0
111} 111}
112 112
113svc_schedule_restart() {
114 local service="$1" restart="$2"
115 [[ ! -d "${svcdir}/restart/${service}" ]] \
116 && mkdir -p "${svcdir}/restart/${service}"
117 [[ ! -e "${svcdir}/restart/${service}/${restart}" ]] \
118 && ln -snf "/etc/init.d/${service}" \
119 "${svcdir}/restart/${service}/${restart}"
120}
121
122svc_start_restart() {
123 [[ ! -d "${svcdir}/restart/${myservice}" ]] && return
124 local x= services= scripts="$(dolisting "${svcdir}/restart/${myservice}/")"
125
126 for x in ${scripts} ; do
127 services="${services} ${x##*/}"
128 done
129
130 for x in $(trace_dependencies "${services}") ; do
131 service_stopped "${x}" && start_service "${x}"
132 rm -f "${svcdir}/restart/${myservice}/${x}"
133 done
134
135 rmdir "${svcdir}/restart/${myservice}"
136}
137
113svc_stop() { 138svc_stop() {
114 local x= mydep= mydeps= retval=0 was_inactive=false 139 local x= mydep= mydeps= retval=0
115 local -a servicelist=() 140 local -a servicelist=()
116 141
117 # Do not try to stop if it had already failed to do so on runlevel change 142 # Do not try to stop if it had already failed to do so on runlevel change
118 if is_runlevel_stop && service_failed "${myservice}" ; then 143 if is_runlevel_stop && service_failed "${myservice}" ; then
119 return 1 144 return 1
120 fi 145 fi
121 146
122 if service_stopped "${myservice}" ; then 147 if service_stopped "${myservice}" ; then
123 ewarn "WARNING: \"${myservice}\" has not yet been started." 148 ewarn "WARNING: ${myservice} has not yet been started."
124 return 0 149 return 0
125 fi 150 fi
126 151
127 service_inactive "${myservice}" && was_inactive=true
128 if ! mark_service_stopping "${myservice}" ; then 152 if ! mark_service_stopping "${myservice}" ; then
129 ewarn "WARNING: \"${myservice}\" is already stopping." 153 ewarn "WARNING: ${myservice} is already stopping."
130 return 0 154 return 0
131 fi 155 fi
132 # Lock service starting too ... 156 # Lock service starting too ...
133 mark_service_starting "${myservice}" 157 mark_service_starting "${myservice}"
134 158
135 # Ensure that we clean up if we abort for any reason 159 # Ensure that we clean up if we abort for any reason
136 trap "svc_quit" INT QUIT TSTP 160 trap "svc_quit" INT QUIT TSTP
137 161
138 begin_service "${myservice}" 162 begin_service "${myservice}"
139 svcbegun=$?
140 163
141 service_message "Stopping service ${myservice}" 164 service_message "Stopping service ${myservice}"
142 165
143 if in_runlevel "${myservice}" "${BOOTLEVEL}" && \ 166 if in_runlevel "${myservice}" "${BOOTLEVEL}" && \
144 [[ ${SOFTLEVEL} != "reboot" && ${SOFTLEVEL} != "shutdown" ]] ; then 167 [[ ${SOFTLEVEL} != "reboot" && ${SOFTLEVEL} != "shutdown" ]] ; then
148 if [[ ${svcpause} != "yes" ]] ; then 171 if [[ ${svcpause} != "yes" ]] ; then
149 if [[ ${NETSERVICE} == "yes" ]] ; then 172 if [[ ${NETSERVICE} == "yes" ]] ; then
150 # A net.* service 173 # A net.* service
151 if in_runlevel "${myservice}" "${BOOTLEVEL}" || \ 174 if in_runlevel "${myservice}" "${BOOTLEVEL}" || \
152 in_runlevel "${myservice}" "${mylevel}" ; then 175 in_runlevel "${myservice}" "${mylevel}" ; then
153 # Only worry about net.* services if this is the last one running, 176 # Only worry about net.* services if this is the last one
154 # or if RC_NET_STRICT_CHECKING is set ... 177 # running or if RC_NET_STRICT_CHECKING is set ...
155 if ! is_net_up ; then 178 ! is_net_up && mydeps="net"
156 mydeps="net"
157 fi 179 fi
158 fi
159
160 mydeps="${mydeps} ${myservice}" 180 mydeps="${mydeps} ${myservice}"
161 else 181 else
162 mydeps="${myservice}" 182 mydeps="${myservice}"
163 fi 183 fi
164 fi 184 fi
175 service_list=( "${service_list[@]}" "${x}" ) 195 service_list=( "${service_list[@]}" "${x}" )
176 fi 196 fi
177 done 197 done
178 done 198 done
179 199
200 [[ ${RC_PARALLEL_STARTUP} == "yes" ]] && wait
201
180 for x in "${service_list[@]}" ; do 202 for x in "${service_list[@]}" ; do
203 # We need to test if the service has been marked stopped
204 # as the fifo may still be around if called by custom code
205 # such as postup from a net script.
206 service_stopped "${mynetservice}" && continue
207
181 wait_service "${x}" 208 wait_service "${x}"
182 if ! service_stopped "${x}" ; then 209 if ! service_stopped "${x}" ; then
183 retval=1 210 retval=1
184 break 211 break
185 fi 212 fi
187 214
188 IN_BACKGROUND="${ib_save}" 215 IN_BACKGROUND="${ib_save}"
189 216
190 if [[ ${retval} != 0 ]] ; then 217 if [[ ${retval} != 0 ]] ; then
191 eerror "ERROR: problems stopping dependent services." 218 eerror "ERROR: problems stopping dependent services."
192 eerror " \"${myservice}\" is still up." 219 eerror " ${myservice} is still up."
193 else 220 else
221 # Now that deps are stopped, stop our service
222 (
223 exit() {
224 RC_QUIET_STDOUT="no"
225 eerror "DO NOT USE EXIT IN INIT.D SCRIPTS"
226 eerror "This IS a bug, please fix your broken init.d"
227 unset -f exit
228 exit "$@"
229 }
194 # Stop einfo/ebegin/eend from working as parallel messes us up 230 # Stop einfo/ebegin/eend from working as parallel messes us up
195 [[ ${RC_PARALLEL_STARTUP} == "yes" ]] && RC_QUIET_STDOUT="yes" 231 [[ ${RC_PARALLEL_STARTUP} == "yes" ]] && RC_QUIET_STDOUT="yes"
196
197 # Now that deps are stopped, stop our service
198 ( stop ) 232 stop
233 )
199 retval=$? 234 retval="$?"
200 235
201 # If a service has been marked inactive, exit now as something 236 # If a service has been marked inactive, exit now as something
202 # may attempt to start it again later 237 # may attempt to start it again later
203 if service_inactive "${myservice}" ; then 238 if service_inactive "${myservice}" ; then
204 [[ ${svcbegun} == 0 ]] && end_service "${myservice}" 0 239 svcinactive=0
240 end_service "${myservice}" 0
205 return 0 241 return 0
206 fi 242 fi
207 fi 243 fi
208 244
209 if [[ ${retval} != 0 ]] ; then 245 if [[ ${retval} != 0 ]] ; then
211 # runlevel change. Note this is only used at runlevel change ... 247 # runlevel change. Note this is only used at runlevel change ...
212 is_runlevel_stop && mark_service_failed "${myservice}" 248 is_runlevel_stop && mark_service_failed "${myservice}"
213 249
214 # If we are halting the system, do it as cleanly as possible 250 # If we are halting the system, do it as cleanly as possible
215 if [[ ${SOFTLEVEL} != "reboot" && ${SOFTLEVEL} != "shutdown" ]] ; then 251 if [[ ${SOFTLEVEL} != "reboot" && ${SOFTLEVEL} != "shutdown" ]] ; then
216 if ${was_inactive} ; then 252 if [[ ${svcinactive} == 0 ]] ; then
217 mark_service_inactive "${myservice}" 253 mark_service_inactive "${myservice}"
218 else 254 else
219 mark_service_started "${myservice}" 255 mark_service_started "${myservice}"
220 fi 256 fi
221 fi 257 fi
223 service_message "eerror" "FAILED to stop service ${myservice}!" 259 service_message "eerror" "FAILED to stop service ${myservice}!"
224 else 260 else
225 # If we're stopped from a daemon that sets ${IN_BACKGROUND} such as 261 # If we're stopped from a daemon that sets ${IN_BACKGROUND} such as
226 # wpa_monitor when we mark as inactive instead of taking the down 262 # wpa_monitor when we mark as inactive instead of taking the down
227 svcstarted=1 263 svcstarted=1
228 if ${IN_BACKGROUND:-false} ; then
229 mark_service_inactive "${myservice}" 264 if service_inactive "${myservice}" ; then
265 svcinactive=0
230 else 266 else
231 mark_service_stopped "${myservice}" 267 mark_service_stopped "${myservice}"
232 fi 268 fi
233 service_message "Stopped service ${myservice}" 269 service_message "Stopped service ${myservice}"
234 fi 270 fi
235 271
236 if [[ ${svcbegun} == 0 ]] ; then
237 end_service "${myservice}" "${retval}" 272 end_service "${myservice}" "${retval}"
238 svcbegun=1
239 fi
240 273
241 # Reset the trap 274 # Reset the trap
242 svc_trap 275 svc_trap
243 276
244 return "${retval}" 277 return "${retval}"
245} 278}
246 279
247svc_start() { 280svc_start() {
248 local x= y= retval=0 was_inactive=false startfail="no" 281 local x= y= retval=0 startfail= startinactive=
249 282
250 # Do not try to start if i have done so already on runlevel change 283 # Do not try to start if i have done so already on runlevel change
251 if is_runlevel_start && service_failed "${myservice}" ; then 284 if is_runlevel_start && service_failed "${myservice}" ; then
252 return 1 285 return 1
253 fi 286 fi
254 287
255 if service_started "${myservice}" ; then 288 if service_started "${myservice}" ; then
256 ewarn "WARNING: \"${myservice}\" has already been started." 289 ewarn "WARNING: ${myservice} has already been started."
257 return 0 290 return 0
258 elif service_stopping "${myservice}" ; then 291 elif service_stopping "${myservice}" ; then
259 eerror "ERROR: please wait for \"${myservice}\" to stop first." 292 eerror "ERROR: please wait for ${myservice} to stop first."
260 return 1 293 return 1
261 elif service_inactive "${myservice}" ; then 294 elif service_inactive "${myservice}" ; then
262 if [[ ${IN_BACKGROUND} != "true" ]] ; then 295 if [[ ${IN_BACKGROUND} != "true" ]] ; then
263 ewarn "WARNING: \"${myservice}\" has already been started." 296 ewarn "WARNING: ${myservice} has already been started."
264 return 0 297 return 0
265 fi 298 fi
266 fi 299 fi
267 300
268 service_inactive "${myservice}" && was_inactive=true
269 if ! mark_service_starting "${myservice}" ; then 301 if ! mark_service_starting "${myservice}" ; then
270 ewarn "WARNING: \"${myservice}\" is already starting." 302 ewarn "WARNING: ${myservice} is already starting."
271 return 0 303 return 0
272 fi 304 fi
273 305
274 # Ensure that we clean up if we abort for any reason 306 # Ensure that we clean up if we abort for any reason
275 trap "svc_quit" INT QUIT TSTP 307 trap "svc_quit" INT QUIT TSTP
276 308
277 begin_service "${myservice}" 309 begin_service "${myservice}"
278 svcbegun=$?
279
280 service_message "Starting service ${myservice}" 310 service_message "Starting service ${myservice}"
311
312 # Save the IN_BACKGROUND var as we need to clear it for starting depends
313 local ib_save="${IN_BACKGROUND}"
314 unset IN_BACKGROUND
281 315
282 local startupservices="$(trace_dependencies $(ineed "${myservice}") \ 316 local startupservices="$(trace_dependencies $(ineed "${myservice}") \
283 $(valid_iuse ${myservice}))" 317 $(valid_iuse "${myservice}"))"
284 local netservices="$(dolisting "/etc/runlevels/${BOOTLEVEL}/net.*") \ 318 local netservices="$(dolisting "/etc/runlevels/${BOOTLEVEL}/net.*") \
285 $(dolisting "/etc/runlevels/${mylevel}/net.*")" 319 $(dolisting "/etc/runlevels/${mylevel}/net.*")"
286 local mynetservice= 320 local startupnetservices=
287 321
288 # Start dependencies, if any. 322 # Start dependencies, if any.
289 # We don't handle "after" deps here as it's the job of rc to start them. 323 # We don't handle "after" deps here as it's the job of rc to start them.
290 for x in ${startupservices} ; do 324 for x in ${startupservices} ; do
291 if [[ ${x} == "net" && ${NETSERVICE} != "yes" ]] && ! is_net_up ; then 325 if [[ ${x} == "net" && ${NETSERVICE} != "yes" ]] && ! is_net_up ; then
292 for y in ${netservices} ; do 326 for y in ${netservices} ; do
293 mynetservice="${y##*/}" 327 y="${y##*/}"
294 if service_stopped "${mynetservice}" ; then 328 service_stopped "${y}" && start_service "${y}"
295 start_service "${mynetservice}"
296 fi
297 done 329 done
298 elif [[ ${x} != "net" ]] ; then 330 elif [[ ${x} != "net" ]] ; then
299 if service_stopped "${x}" ; then 331 if service_stopped "${x}" ; then
300 start_service "${x}" 332 start_service "${x}"
301 fi 333 fi
302 fi 334 fi
303 done 335 done
304 336
337 [[ ${RC_PARALLEL_STARTUP} == "yes" ]] && wait
338
305 # We also wait for any services we're after to finish incase they 339 # We also wait for any services we're after to finish incase they
306 # have a "before" dep but we don't dep on them. 340 # have a "before" dep but we don't dep on them.
307 if is_runlevel_start ; then 341 if is_runlevel_start ; then
308 startupservices="${startupservices} $(valid_iafter ${myservice})" 342 startupservices="${startupservices} $(valid_iafter "${myservice}")"
309 fi 343 fi
310 344
311 # Wait for dependencies to finish. 345 # Wait for dependencies to finish.
312 for x in ${startupservices} ; do 346 for x in ${startupservices} ; do
313 if [[ ${x} == "net" && ${NETSERVICE} != "yes" ]] ; then 347 if [[ ${x} == "net" && ${NETSERVICE} != "yes" ]] ; then
314 for y in ${netservices} ; do 348 for y in ${netservices} ; do
315 mynetservice="${y##*/}" 349 y="${y##*/}"
316 350 # Don't wait if it's already been started
351 service_started "${y}" && continue
317 wait_service "${mynetservice}" 352 wait_service "${y}"
318
319 if ! service_started "${mynetservice}" ; then 353 if ! service_started "${y}" ; then
320 # A 'need' dependency is critical for startup 354 # A 'need' dependency is critical for startup
321 if ineed -t "${myservice}" "${x}" >/dev/null ; then 355 if ineed -t "${myservice}" "${x}" >/dev/null ; then
322 # Only worry about a net.* service if we do not have one
323 # up and running already, or if RC_NET_STRICT_CHECKING
324 # is set ....
325 if ! is_net_up ; then 356 if ! is_net_up ; then
357 if service_inactive "${y}" ; then
358 svc_schedule_restart "${y}" "${myservice}"
359 startinactive="${y}"
360 else
326 startfail="yes" 361 startfail="${y}"
362 fi
363 break
327 fi 364 fi
328 fi 365 fi
329 fi 366 fi
330 done 367 done
331 elif [[ ${x} != "net" ]] ; then 368 elif [[ ${x} != "net" ]] ; then
369 # Don't wait if it's already been started
370 service_started "${x}" && continue
332 wait_service "${x}" 371 wait_service "${x}"
333 if ! service_started "${x}" ; then 372 if ! service_started "${x}" ; then
334 # A 'need' dependacy is critical for startup 373 # A 'need' dependacy is critical for startup
335 if ineed -t "${myservice}" "${x}" >/dev/null ; then 374 if ineed -t "${myservice}" "${x}" >/dev/null ; then
375 if service_inactive "${x}" ; then
376 svc_schedule_restart "${x}"
377 startinactive="${x}"
378 else
336 startfail="yes" 379 startfail="${x}"
380 fi
381 break
337 fi 382 fi
338 fi 383 fi
339 fi 384 fi
340 done 385 done
341 386
342 if [[ ${startfail} == "yes" ]] ; then 387 if [[ ${startfail} == "yes" ]] ; then
343 eerror "ERROR: Problem starting needed services." 388 eerror "ERROR: Problem starting needed service ${startfail}."
344 eerror " \"${myservice}\" was not started." 389 eerror " ${myservice} was not started."
390 retval=1
391 elif [[ -n ${startinactive} ]] ; then
392 ewarn "WARNING: ${myservice} is scheduled to start when ${startinactive} has started."
345 retval=1 393 retval=1
346 elif broken "${myservice}" ; then 394 elif broken "${myservice}" ; then
347 eerror "ERROR: Some services needed are missing. Run" 395 eerror "ERROR: Some services needed are missing. Run"
348 eerror " './${myservice} broken' for a list of those" 396 eerror " './${myservice} broken' for a list of those"
349 eerror " services. \"${myservice}\" was not started." 397 eerror " services. ${myservice} was not started."
350 retval=1 398 retval=1
351 else 399 else
400 IN_BACKGROUND="${ib_save}"
352 ( 401 (
353 exit() { 402 exit() {
354 RC_QUIET_STDOUT="no" 403 RC_QUIET_STDOUT="no"
355 eerror "DO NOT USE EXIT IN INIT.D SCRIPTS" 404 eerror "DO NOT USE EXIT IN INIT.D SCRIPTS"
356 eerror "This IS a bug, please fix your broken init.d" 405 eerror "This IS a bug, please fix your broken init.d"
357 unset -f exit 406 unset -f exit
358 exit $@ 407 exit "$@"
359 } 408 }
360 # Stop einfo/ebegin/eend from working as parallel messes us up 409 # Stop einfo/ebegin/eend from working as parallel messes us up
361 [[ ${RC_PARALLEL_STARTUP} == "yes" ]] && RC_QUIET_STDOUT="yes" 410 [[ ${RC_PARALLEL_STARTUP} == "yes" ]] && RC_QUIET_STDOUT="yes"
362 start 411 start
363 ) 412 )
364 retval=$? 413 retval="$?"
365 414
366 # If a service has been marked inactive, exit now as something 415 # If a service has been marked inactive, exit now as something
367 # may attempt to start it again later 416 # may attempt to start it again later
368 if service_inactive "${myservice}" ; then 417 if service_inactive "${myservice}" ; then
369 [[ ${svcbegun} == 0 ]] && end_service "${myservice}" 1 418 svcinactive=0
419 end_service "${myservice}" 1
370 return 1 420 return 1
371 fi 421 fi
372 fi 422 fi
373 423
374 if [[ ${retval} != 0 ]] ; then 424 if [[ ${retval} != 0 ]] ; then
375 is_runlevel_start && mark_service_failed "${myservice}"
376
377 # Remove link if service didn't start; but only if we're not booting 425 # Remove link if service didn't start; but only if we're not booting
378 # If we're booting, we need to continue and do our best to get the 426 # If we're booting, we need to continue and do our best to get the
379 # system up. 427 # system up.
380 if [[ ${SOFTLEVEL} != "${BOOTLEVEL}" ]] ; then 428 if [[ ${SOFTLEVEL} != "${BOOTLEVEL}" ]] ; then
381 if ${was_inactive} ; then 429 if [[ ${svcinactive} == 0 ]] ; then
382 mark_service_inactive "${myservice}" 430 mark_service_inactive "${myservice}"
383 else 431 else
384 mark_service_stopped "${myservice}" 432 mark_service_stopped "${myservice}"
385 fi 433 fi
386 fi 434 fi
387 435
436 if [[ -z ${startinactive} ]] ; then
437 is_runlevel_start && mark_service_failed "${myservice}"
388 service_message "eerror" "FAILED to start service ${myservice}!" 438 service_message "eerror" "FAILED to start service ${myservice}!"
439 fi
389 else 440 else
390 svcstarted=0 441 svcstarted=0
391 mark_service_started "${myservice}" 442 mark_service_started "${myservice}"
392
393 service_message "Service ${myservice} started OK" 443 service_message "Service ${myservice} started OK"
394 fi 444 fi
395 445
396 if [[ ${svcbegun} == 0 ]] ; then
397 end_service "${myservice}" "${retval}" 446 end_service "${myservice}" "${retval}"
398 svcbegun=1
399 fi
400
401 # Reset the trap 447 # Reset the trap
402 svc_trap 448 svc_trap
403 449
404 return "${retval}" 450 return "${retval}"
405} 451}
406 452
407svc_restart() { 453svc_restart() {
408 if ! service_stopped "${myservice}" ; then 454 if ! service_stopped "${myservice}" ; then
409 svc_stop || return "$?" 455 svc_stop || return "$?"
410 fi 456 fi
411 svc_start || return "$?" 457 svc_start
412} 458}
413 459
414svc_status() { 460svc_status() {
415 # The basic idea here is to have some sort of consistent 461 # The basic idea here is to have some sort of consistent
416 # output in the status() function which scripts can use 462 # output in the status() function which scripts can use
441 fi 487 fi
442 [[ ${RC_QUIET_STDOUT} != "yes" ]] \ 488 [[ ${RC_QUIET_STDOUT} != "yes" ]] \
443 && ${efunc} "status: ${state}" 489 && ${efunc} "status: ${state}"
444 490
445 status 491 status
446 [[ ${efunc} != "eerror" ]] 492 # Return 0 if started, otherwise 1
493 [[ ${state} == "started" ]]
447} 494}
448 495
449rcscript_errors="$(bash -n ${myscript} 2>&1)" || { 496rcscript_errors="$(bash -n "${myscript}" 2>&1)" || {
450 [[ -n ${rcscript_errors} ]] && echo "${rcscript_errors}" >&2 497 [[ -n ${rcscript_errors} ]] && echo "${rcscript_errors}" >&2
451 eerror "ERROR: \"${myscript}\" has syntax errors in it; aborting ..." 498 eerror "ERROR: ${myscript} has syntax errors in it; aborting ..."
452 exit 1 499 exit 1
453} 500}
454 501
455# set *after* wrap_rcscript, else we get duplicates. 502# set *after* wrap_rcscript, else we get duplicates.
456opts="start stop restart" 503opts="start stop restart"
510done 557done
511for arg in $* ; do 558for arg in $* ; do
512 case "${arg}" in 559 case "${arg}" in
513 stop) 560 stop)
514 if [[ -e "${svcdir}/restart/${myservice}" ]] ; then 561 if [[ -e "${svcdir}/restart/${myservice}" ]] ; then
515 rm -f "${svcdir}/restart/${myservice}" 562 rm -Rf "${svcdir}/restart/${myservice}"
516 fi 563 fi
517 564
518 # Stoped from the background - treat this as a restart so that 565 # Stoped from the background - treat this as a restart so that
519 # stopped services come back up again when started. 566 # stopped services come back up again when started.
520 if [[ ${IN_BACKGROUND} == "true" ]] ; then 567 if [[ ${IN_BACKGROUND} == "true" ]] ; then
521 rm -rf "${svcdir}/snapshot/$$" 568 rm -rf "${svcdir}/snapshot/$$"
522 mkdir -p "${svcdir}/snapshot/$$" 569 mkdir -p "${svcdir}/snapshot/$$"
523 cp -a "${svcdir}"/started/* "${svcdir}/snapshot/$$/" 570 cp -pP "${svcdir}"/started/* "${svcdir}/snapshot/$$/"
524 fi 571 fi
525 572
526 svc_stop 573 svc_stop
527 574 retval="$?"
575
528 if [[ ${IN_BACKGROUND} == "true" ]] ; then 576 if [[ ${IN_BACKGROUND} == "true" ]] ; then
529 res=
530 for x in $(dolisting "${svcdir}/snapshot/$$/") ; do 577 for x in $(dolisting "${svcdir}/snapshot/$$/") ; do
531 if service_stopped "${x##*/}" ; then 578 if service_stopped "${x##*/}" ; then
532 res="${res}${x##*/} " 579 svc_schedule_restart "${myservice}" "${x##*/}"
533 fi 580 fi
534 done 581 done
535 [[ -n ${res} ]] && echo "${res}" > "${svcdir}/restart/${myservice}"
536 fi 582 fi
583
584 exit "${retval}"
537 ;; 585 ;;
538 start) 586 start)
539 svc_start 587 svc_start
540 retval=$? 588 retval=$?
541 if ! is_runlevel_start && [[ -s "${svcdir}/restart/${myservice}" ]] ; then 589 service_started "${myservice}" && svc_start_restart
542 for x in $(trace_dependencies $(< "${svcdir}/restart/${myservice}")) ; do
543 service_stopped "${x}" && start_service "${x}"
544 done
545 fi
546 if [[ -e "${svcdir}/restart/${myservice}" ]] ; then
547 rm -f "${svcdir}/restart/${myservice}"
548 fi
549 exit ${retval} 590 exit "${retval}"
550 ;; 591 ;;
551 needsme|ineed|usesme|iuse|broken) 592 needsme|ineed|usesme|iuse|broken)
552 trace_dependencies "-${arg}" 593 trace_dependencies "-${arg}"
553 ;; 594 ;;
554 status) 595 status)
572 RC_KILL_CHILDREN="no" 613 RC_KILL_CHILDREN="no"
573 614
574 # Create a snapshot of started services 615 # Create a snapshot of started services
575 rm -rf "${svcdir}/snapshot/$$" 616 rm -rf "${svcdir}/snapshot/$$"
576 mkdir -p "${svcdir}/snapshot/$$" 617 mkdir -p "${svcdir}/snapshot/$$"
577 cp -a "${svcdir}"/started/* "${svcdir}/snapshot/$$/" 618 cp -pP "${svcdir}"/started/* "${svcdir}/snapshot/$$/"
578 619
579 # Simple way to try and detect if the service use svc_{start,stop} 620 # Simple way to try and detect if the service use svc_{start,stop}
580 # to restart if it have a custom restart() funtion. 621 # to restart if it have a custom restart() funtion.
581 if [[ -n $(egrep '^[[:space:]]*restart[[:space:]]*()' "/etc/init.d/${myservice}") ]] ; then 622 if [[ -n $(egrep '^[[:space:]]*restart[[:space:]]*()' "/etc/init.d/${myservice}") ]] ; then
582 if [[ -z $(egrep 'svc_stop' "/etc/init.d/${myservice}") || \ 623 if [[ -z $(egrep 'svc_stop' "/etc/init.d/${myservice}") || \
592 fi 633 fi
593 else 634 else
594 restart 635 restart
595 fi 636 fi
596 637
638 [[ -e "${svcdir}/restart/${myservice}" ]] \
639 && rm -f "${svcdir}/restart/${myservice}"
640
597 # Restart dependencies as well 641 # Restart dependencies as well
598 if service_started "${myservice}" ; then 642 if service_inactive "${myservice}" ; then
599 for x in $(trace_dependencies \
600 $(dolisting "${svcdir}/snapshot/$$/") ) ; do 643 for x in $(dolisting "${svcdir}/snapshot/$$/") ; do
601 if service_stopped "${x##*/}" ; then 644 if service_stopped "${x##*/}" ; then
602 start_service "${x##*/}" 645 svc_schedule_restart "${myservice}" "${x##*/}"
603 fi 646 fi
604 done 647 done
605 elif service_inactive "${myservice}" ; then 648 elif service_started "${myservice}" ; then
606 res= 649 svc_start_restart
607 for x in $(dolisting "${svcdir}/snapshot/$$/") ; do
608 if service_stopped "${x##*/}" ; then
609 res="${res}${x##*/} "
610 fi 650 fi
611 done
612 [[ -n ${res} ]] && echo "${res}" > "${svcdir}/restart/${myservice}"
613 fi
614
615 # Wait for any services that may still be running ...
616 [[ ${RC_PARALLEL_STARTUP} == "yes" ]] && wait
617 651
618 rm -rf "${svcdir}/snapshot/$$" 652 rm -rf "${svcdir}/snapshot/$$"
619 svcrestart="no" 653 svcrestart="no"
620 ;; 654 ;;
621 pause) 655 pause)

Legend:
Removed from v.205  
changed lines
  Added in v.206

  ViewVC Help
Powered by ViewVC 1.1.20