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

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

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

Revision 1818 Revision 1819
112status() { 112status() {
113 # Dummy function 113 # Dummy function
114 return 0 114 return 0
115} 115}
116 116
117svc_schedule_restart() {
118 local service="$1"
119 if [[ ! -e "${svcdir}/restart/${service}" ]] \
120 || ! grep -q "^${myservice}$" "${svcdir}/restart/${service}" ; then
121 echo "${myservice}" >> "${svcdir}/restart/${service}"
122 fi
123}
124
117svc_stop() { 125svc_stop() {
118 local x= mydep= mydeps= retval=0 126 local x= mydep= mydeps= retval=0
119 local -a servicelist=() 127 local -a servicelist=()
120 128
121 # Do not try to stop if it had already failed to do so on runlevel change 129 # Do not try to stop if it had already failed to do so on runlevel change
122 if is_runlevel_stop && service_failed "${myservice}" ; then 130 if is_runlevel_stop && service_failed "${myservice}" ; then
123 return 1 131 return 1
124 fi 132 fi
125 133
126 if service_stopped "${myservice}" ; then 134 if service_stopped "${myservice}" ; then
127 ewarn "WARNING: \"${myservice}\" has not yet been started." 135 ewarn "WARNING: ${myservice} has not yet been started."
128 return 0 136 return 0
129 fi 137 fi
130 138
131 if ! mark_service_stopping "${myservice}" ; then 139 if ! mark_service_stopping "${myservice}" ; then
132 ewarn "WARNING: \"${myservice}\" is already stopping." 140 ewarn "WARNING: ${myservice} is already stopping."
133 return 0 141 return 0
134 fi 142 fi
135 # Lock service starting too ... 143 # Lock service starting too ...
136 mark_service_starting "${myservice}" 144 mark_service_starting "${myservice}"
137 145
196 204
197 IN_BACKGROUND="${ib_save}" 205 IN_BACKGROUND="${ib_save}"
198 206
199 if [[ ${retval} != 0 ]] ; then 207 if [[ ${retval} != 0 ]] ; then
200 eerror "ERROR: problems stopping dependent services." 208 eerror "ERROR: problems stopping dependent services."
201 eerror " \"${myservice}\" is still up." 209 eerror " ${myservice} is still up."
202 else 210 else
203 # Now that deps are stopped, stop our service 211 # Now that deps are stopped, stop our service
204 ( 212 (
205 exit() { 213 exit() {
206 RC_QUIET_STDOUT="no" 214 RC_QUIET_STDOUT="no"
261 269
262 return "${retval}" 270 return "${retval}"
263} 271}
264 272
265svc_start() { 273svc_start() {
266 local x= y= retval=0 startfail="no" 274 local x= y= retval=0 startfail= startinactive=
267 275
268 # Do not try to start if i have done so already on runlevel change 276 # Do not try to start if i have done so already on runlevel change
269 if is_runlevel_start && service_failed "${myservice}" ; then 277 if is_runlevel_start && service_failed "${myservice}" ; then
270 return 1 278 return 1
271 fi 279 fi
272 280
273 if service_started "${myservice}" ; then 281 if service_started "${myservice}" ; then
274 ewarn "WARNING: \"${myservice}\" has already been started." 282 ewarn "WARNING: ${myservice} has already been started."
275 return 0 283 return 0
276 elif service_stopping "${myservice}" ; then 284 elif service_stopping "${myservice}" ; then
277 eerror "ERROR: please wait for \"${myservice}\" to stop first." 285 eerror "ERROR: please wait for ${myservice} to stop first."
278 return 1 286 return 1
279 elif service_inactive "${myservice}" ; then 287 elif service_inactive "${myservice}" ; then
280 if [[ ${IN_BACKGROUND} != "true" ]] ; then 288 if [[ ${IN_BACKGROUND} != "true" ]] ; then
281 ewarn "WARNING: \"${myservice}\" has already been started." 289 ewarn "WARNING: ${myservice} has already been started."
282 return 0 290 return 0
283 fi 291 fi
284 fi 292 fi
285 293
286 if ! mark_service_starting "${myservice}" ; then 294 if ! mark_service_starting "${myservice}" ; then
287 ewarn "WARNING: \"${myservice}\" is already starting." 295 ewarn "WARNING: ${myservice} is already starting."
288 return 0 296 return 0
289 fi 297 fi
290 298
291 # Ensure that we clean up if we abort for any reason 299 # Ensure that we clean up if we abort for any reason
292 trap "svc_quit" INT QUIT TSTP 300 trap "svc_quit" INT QUIT TSTP
309 # Start dependencies, if any. 317 # Start dependencies, if any.
310 # We don't handle "after" deps here as it's the job of rc to start them. 318 # We don't handle "after" deps here as it's the job of rc to start them.
311 for x in ${startupservices} ; do 319 for x in ${startupservices} ; do
312 if [[ ${x} == "net" && ${NETSERVICE} != "yes" ]] && ! is_net_up ; then 320 if [[ ${x} == "net" && ${NETSERVICE} != "yes" ]] && ! is_net_up ; then
313 for y in ${netservices} ; do 321 for y in ${netservices} ; do
314 local mynetservice="${y##*/}" 322 y="${y##*/}"
315 if service_stopped "${mynetservice}" ; then 323 service_stopped "${y}" && start_service "${y}"
316 start_service "${mynetservice}"
317 startupnetservices="${startupnetservices}${mynetservice} "
318 fi
319 done 324 done
320 elif [[ ${x} != "net" ]] ; then 325 elif [[ ${x} != "net" ]] ; then
321 if service_stopped "${x}" ; then 326 if service_stopped "${x}" ; then
322 start_service "${x}" 327 start_service "${x}"
323 fi 328 fi
331 fi 336 fi
332 337
333 # Wait for dependencies to finish. 338 # Wait for dependencies to finish.
334 for x in ${startupservices} ; do 339 for x in ${startupservices} ; do
335 if [[ ${x} == "net" && ${NETSERVICE} != "yes" ]] ; then 340 if [[ ${x} == "net" && ${NETSERVICE} != "yes" ]] ; then
336 for y in ${startupnetservices} ; do 341 for y in ${netservices} ; do
342 y="${y##*/}"
337 # Don't wait if it's already been started 343 # Don't wait if it's already been started
338 service_started "${y}" && continue 344 service_started "${y}" && continue
339 wait_service "${y}" 345 wait_service "${y}"
340 if ! service_started "${y}" ; then 346 if ! service_started "${y}" ; then
341 # A 'need' dependency is critical for startup 347 # A 'need' dependency is critical for startup
342 if ineed -t "${myservice}" "${x}" >/dev/null ; then 348 if ineed -t "${myservice}" "${x}" >/dev/null ; then
343 if ! is_net_up ; then 349 if ! is_net_up ; then
350 if service_inactive "${y}" ; then
351 svc_schedule_restart "${y}"
352 startinactive="${y}"
353 else
344 startfail="yes" 354 startfail="${y}"
355 fi
345 break 356 break
346 fi 357 fi
347 fi 358 fi
348 fi 359 fi
349 done 360 done
352 service_started "${x}" && continue 363 service_started "${x}" && continue
353 wait_service "${x}" 364 wait_service "${x}"
354 if ! service_started "${x}" ; then 365 if ! service_started "${x}" ; then
355 # A 'need' dependacy is critical for startup 366 # A 'need' dependacy is critical for startup
356 if ineed -t "${myservice}" "${x}" >/dev/null ; then 367 if ineed -t "${myservice}" "${x}" >/dev/null ; then
368 if service_inactive "${x}" ; then
369 svc_schedule_restart "${x}"
370 startinactive="${x}"
371 else
357 startfail="yes" 372 startfail="${x}"
373 fi
358 break 374 break
359 fi 375 fi
360 fi 376 fi
361 fi 377 fi
362 done 378 done
363 379
364 if [[ ${startfail} == "yes" ]] ; then 380 if [[ ${startfail} == "yes" ]] ; then
365 eerror "ERROR: Problem starting needed services." 381 eerror "ERROR: Problem starting needed service ${startfail}."
366 eerror " \"${myservice}\" was not started." 382 eerror " ${myservice} was not started."
383 retval=1
384 elif [[ -n ${startinactive} ]] ; then
385 ewarn "WARNING: ${myservice} is scheduled to start when ${startinactive} has started."
367 retval=1 386 retval=1
368 elif broken "${myservice}" ; then 387 elif broken "${myservice}" ; then
369 eerror "ERROR: Some services needed are missing. Run" 388 eerror "ERROR: Some services needed are missing. Run"
370 eerror " './${myservice} broken' for a list of those" 389 eerror " './${myservice} broken' for a list of those"
371 eerror " services. \"${myservice}\" was not started." 390 eerror " services. ${myservice} was not started."
372 retval=1 391 retval=1
373 else 392 else
374 IN_BACKGROUND="${ib_save}" 393 IN_BACKGROUND="${ib_save}"
375 ( 394 (
376 exit() { 395 exit() {
394 return 1 413 return 1
395 fi 414 fi
396 fi 415 fi
397 416
398 if [[ ${retval} != 0 ]] ; then 417 if [[ ${retval} != 0 ]] ; then
399 is_runlevel_start && mark_service_failed "${myservice}"
400
401 # Remove link if service didn't start; but only if we're not booting 418 # Remove link if service didn't start; but only if we're not booting
402 # If we're booting, we need to continue and do our best to get the 419 # If we're booting, we need to continue and do our best to get the
403 # system up. 420 # system up.
404 if [[ ${SOFTLEVEL} != "${BOOTLEVEL}" ]] ; then 421 if [[ ${SOFTLEVEL} != "${BOOTLEVEL}" ]] ; then
405 if [[ ${svcinactive} == 0 ]] ; then 422 if [[ ${svcinactive} == 0 ]] ; then
407 else 424 else
408 mark_service_stopped "${myservice}" 425 mark_service_stopped "${myservice}"
409 fi 426 fi
410 fi 427 fi
411 428
429 if [[ -z ${startinactive} ]] ; then
430 is_runlevel_start && mark_service_failed "${myservice}"
412 service_message "eerror" "FAILED to start service ${myservice}!" 431 service_message "eerror" "FAILED to start service ${myservice}!"
432 fi
413 else 433 else
414 svcstarted=0 434 svcstarted=0
415 mark_service_started "${myservice}" 435 mark_service_started "${myservice}"
416
417 service_message "Service ${myservice} started OK" 436 service_message "Service ${myservice} started OK"
418 fi 437 fi
419 438
420 if [[ ${svcbegun} == 0 ]] ; then 439 if [[ ${svcbegun} == 0 ]] ; then
421 end_service "${myservice}" "${retval}" 440 end_service "${myservice}" "${retval}"
548 cp -pP "${svcdir}"/started/* "${svcdir}/snapshot/$$/" 567 cp -pP "${svcdir}"/started/* "${svcdir}/snapshot/$$/"
549 fi 568 fi
550 569
551 svc_stop 570 svc_stop
552 retval="$?" 571 retval="$?"
553 572
554 if [[ ${IN_BACKGROUND} == "true" ]] ; then 573 if [[ ${IN_BACKGROUND} == "true" ]] ; then
555 res= 574 res=
556 for x in $(dolisting "${svcdir}/snapshot/$$/") ; do 575 for x in $(dolisting "${svcdir}/snapshot/$$/") ; do
557 if service_stopped "${x##*/}" ; then 576 service_stopped "${x##*/}" && svc_schedule_restart "${x##*/}"
558 res="${res}${x##*/} "
559 fi
560 done 577 done
561 [[ -n ${res} ]] && echo "${res}" > "${svcdir}/restart/${myservice}"
562 fi 578 fi
563 579
564 exit "${retval}" 580 exit "${retval}"
565 ;; 581 ;;
566 start) 582 start)

Legend:
Removed from v.1818  
changed lines
  Added in v.1819

  ViewVC Help
Powered by ViewVC 1.1.20