/[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 2465 Revision 2466
69 set +f 69 set +f
70fi 70fi
71 71
72# State variables 72# State variables
73svcpause="no" 73svcpause="no"
74svcrestart="no"
75 74
76# Functions to handle dependencies and services 75# Functions to handle dependencies and services
77[[ ${RC_GOT_SERVICES} != "yes" ]] && source "${svclib}/sh/rc-services.sh" 76[[ ${RC_GOT_SERVICES} != "yes" ]] && source "${svclib}/sh/rc-services.sh"
78# Functions to control daemons 77# Functions to control daemons
79[[ ${RC_GOT_DAEMON} != "yes" ]] && source "${svclib}/sh/rc-daemon.sh" 78[[ ${RC_GOT_DAEMON} != "yes" ]] && source "${svclib}/sh/rc-daemon.sh"
134 # Return failure so the symlink doesn't get created 133 # Return failure so the symlink doesn't get created
135 return 1 134 return 1
136} 135}
137 136
138restart() { 137restart() {
138 if ! service_stopped "${SVCNAME}" ; then
139 svc_stop || return "$?"
140 fi
139 svc_restart 141 svc_start
140} 142}
141 143
142status() { 144status() {
143 # Dummy function 145 # Dummy function
144 return 0 146 return 0
468 470
469 return "${retval}" 471 return "${retval}"
470} 472}
471 473
472svc_restart() { 474svc_restart() {
475 # We don't kill child processes if we're restarting
476 # This is especically important for sshd ....
477 RC_KILL_CHILDREN="no"
478
479 # Create a snapshot of started services
480 rm -rf "${svcdir}/snapshot/$$"
481 mkdir -p "${svcdir}/snapshot/$$"
482 cp -pP "${svcdir}"/started/* "${svcdir}"/inactive/* \
483 "${svcdir}/snapshot/$$/" 2>/dev/null
484 rm -f "${svcdir}/snapshot/$$/${SVCNAME}"
485
486 # Simple way to try and detect if the service use svc_{start,stop}
487 # to restart if it have a custom restart() funtion.
488 if [[ -n $(egrep '^[[:space:]]*restart[[:space:]]*()' "/etc/init.d/${SVCNAME}") ]] ; then
489 if [[ -z $(egrep 'svc_stop' "/etc/init.d/${SVCNAME}") || \
490 -z $(egrep 'svc_start' "/etc/init.d/${SVCNAME}") ]] ; then
491 echo
492 ewarn "Please use 'svc_stop; svc_start' and not 'stop; start' to"
493 ewarn "restart the service in its custom 'restart()' function."
494 ewarn "Run ${SVCNAME} without arguments for more info."
495 echo
473 if ! service_stopped "${SVCNAME}" ; then 496 if ! service_stopped "${SVCNAME}" ; then
474 svc_stop || return "$?" 497 svc_stop || return "$?"
475 fi 498 fi
476 svc_start 499 svc_start
500 else
501 restart
502 fi
503 else
504 restart
505 fi
506 retval="$?"
507
508 [[ -e "${svcdir}/scheduled/${SVCNAME}" ]] \
509 && rm -Rf "${svcdir}/scheduled/${SVCNAME}"
510
511 # Restart dependencies as well
512 for x in $(dolisting "${svcdir}/snapshot/$$/") ; do
513 if [[ -x ${x} ]] && service_stopped "${x##*/}" ; then
514 if service_inactive "${SVCNAME}" \
515 || service_wasinactive "${SVCNAME}" ; then
516 svc_schedule_start "${SVCNAME}" "${x##*/}"
517 ewarn "WARNING: ${x##*/} is scheduled to start when ${SVCNAME} has started."
518 elif service_started "${SVCNAME}" ; then
519 start_service "${x##*/}"
520 fi
521 fi
522 done
523 rm -rf "${svcdir}/snapshot/$$"
524
525 service_started "${SVCNAME}" && svc_start_scheduled
526
527 # Wait for services to come up
528 if [[ ${IN_BACKGROUND} != "true" \
529 && ${IN_BACKGROUND} != "1" ]] ; then
530 [[ ${RC_PARALLEL_STARTUP} == "yes" ]] && wait
531 fi
532
533 return ${retval}
477} 534}
478 535
479svc_status() { 536svc_status() {
480 # The basic idea here is to have some sort of consistent 537 # The basic idea here is to have some sort of consistent
481 # output in the status() function which scripts can use 538 # output in the status() function which scripts can use
627 zap) 684 zap)
628 einfo "Manually resetting ${SVCNAME} to stopped state." 685 einfo "Manually resetting ${SVCNAME} to stopped state."
629 mark_service_stopped "${SVCNAME}" 686 mark_service_stopped "${SVCNAME}"
630 ;; 687 ;;
631 restart) 688 restart)
632 svcrestart="yes" 689 svc_restart
633 690 retval="$?"
634 # We don't kill child processes if we're restarting 691 ;;
635 # This is especically important for sshd .... 692 condrestart|conditionalrestart)
636 RC_KILL_CHILDREN="no" 693 if service_started "${SVCNAME}" ; then
637
638 # Create a snapshot of started services
639 rm -rf "${svcdir}/snapshot/$$"
640 mkdir -p "${svcdir}/snapshot/$$"
641 cp -pP "${svcdir}"/started/* "${svcdir}"/inactive/* \
642 "${svcdir}/snapshot/$$/" 2>/dev/null
643 rm -f "${svcdir}/snapshot/$$/${SVCNAME}"
644
645 # Simple way to try and detect if the service use svc_{start,stop}
646 # to restart if it have a custom restart() funtion.
647 if [[ -n $(egrep '^[[:space:]]*restart[[:space:]]*()' "/etc/init.d/${SVCNAME}") ]] ; then
648 if [[ -z $(egrep 'svc_stop' "/etc/init.d/${SVCNAME}") || \
649 -z $(egrep 'svc_start' "/etc/init.d/${SVCNAME}") ]] ; then
650 echo
651 ewarn "Please use 'svc_stop; svc_start' and not 'stop; start' to"
652 ewarn "restart the service in its custom 'restart()' function."
653 ewarn "Run ${SVCNAME} without arguments for more info."
654 echo
655 svc_restart 694 svc_restart
656 else
657 restart
658 fi 695 fi
659 else
660 restart
661 fi
662 retval="$?" 696 retval="$?"
663
664 [[ -e "${svcdir}/scheduled/${SVCNAME}" ]] \
665 && rm -Rf "${svcdir}/scheduled/${SVCNAME}"
666
667 # Restart dependencies as well
668 for x in $(dolisting "${svcdir}/snapshot/$$/") ; do
669 if [[ -x ${x} ]] && service_stopped "${x##*/}" ; then
670 if service_inactive "${SVCNAME}" \
671 || service_wasinactive "${SVCNAME}" ; then
672 svc_schedule_start "${SVCNAME}" "${x##*/}"
673 ewarn "WARNING: ${x##*/} is scheduled to start when ${SVCNAME} has started."
674 elif service_started "${SVCNAME}" ; then
675 start_service "${x##*/}"
676 fi
677 fi
678 done
679 rm -rf "${svcdir}/snapshot/$$"
680
681 service_started "${SVCNAME}" && svc_start_scheduled
682
683 # Wait for services to come up
684 if [[ ${IN_BACKGROUND} != "true" \
685 && ${IN_BACKGROUND} != "1" ]] ; then
686 [[ ${RC_PARALLEL_STARTUP} == "yes" ]] && wait
687 fi
688
689 svcrestart="no"
690 ;; 697 ;;
691 pause) 698 pause)
692 svcpause="yes" 699 svcpause="yes"
693 svc_stop 700 svc_stop
694 retval="$?" 701 retval="$?"

Legend:
Removed from v.2465  
changed lines
  Added in v.2466

  ViewVC Help
Powered by ViewVC 1.1.20