/[baselayout]/trunk/sbin/runscript.sh
Gentoo

Diff of /trunk/sbin/runscript.sh

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

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

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

  ViewVC Help
Powered by ViewVC 1.1.20