diff options
Diffstat (limited to 'sbin/rc')
-rwxr-xr-x | sbin/rc | 189 |
1 files changed, 36 insertions, 153 deletions
@@ -6,30 +6,16 @@ trap ":" INT QUIT TSTP source /sbin/functions.sh umask 022 -# Check that $1 exists ... -check_statedir() { - [ -z "$1" ] && return 0 - - if [ ! -d "$1" ] ; then - if ! mkdir -p "$1" &>/dev/null ; then - echo - eerror "For Gentoo to function properly, \"$1\" needs to exist." - einfo "Rebooting" - /sbin/reboot -f - fi - fi - - return 0 -} - +# void get_critical_services() +# +# Get critical services needed for bootup, and exports CRITICAL_SERVICES +# get_critical_services() { local x= CRITICAL_SERVICES= - if [ -f "/etc/runlevels/${BOOTLEVEL}/.critical" ] - then - for x in $(< /etc/runlevels/${BOOTLEVEL}/.critical) - do + if [[ -f /etc/runlevels/${BOOTLEVEL}/.critical ]] ; then + for x in $(< "/etc/runlevels/${BOOTLEVEL}/.critical") ; do CRITICAL_SERVICES="${CRITICAL_SERVICES} ${x##*/}" done else @@ -42,7 +28,7 @@ get_critical_services() { } # Save $1 -argv1="$1" +argv1=$1 # we need this to prevent a warning below [[ ! -e ${svcdir}/softlevel ]] && touch ${svcdir}/softlevel @@ -52,108 +38,11 @@ argv1="$1" # directly ... if [[ ${argv1} = "sysinit" || ( ${argv1} = "boot" && "$(<${svcdir}/softlevel)" != "sysinit" ) ]] then - # Setup initial $PATH just in case - PATH="/bin:/sbin:/usr/bin:/usr/sbin:${PATH}" - - echo - echo -e "${GOOD}Gentoo Linux${GENTOO_VERS}; ${BRACKET}http://www.gentoo.org/${NORMAL}" - echo -e " Copyright 1999-2005 Gentoo Foundation; Distributed under the GPLv2" - echo - - check_statedir /proc - check_statedir /dev - - # We set the forced softlevel from the kernel command line - # It needs to be run right after proc is mounted for the - # boot runlevel - setup_defaultlevels - - # $BOOT can be used by rc-scripts to test if it is the first time - # the 'boot' runlevel is executed. Now also needed by some stuff in - # the 'sysinit' runlevel ... - export BOOT="yes" - - start_critical_service() { - ( - local retval= - local service=$1 - # Needed for some addons like dm-crypt that starts in critical services - local myservice=$1 - - source "/etc/init.d/${service}" || eerror "Failed to source /etc/init.d/${service}" - retval=$? - [ "${retval}" -ne 0 ] && return "${retval}" - [ -e "/etc/conf.d/${service}" ] && source "/etc/conf.d/${service}" - source /etc/rc.conf - - start || eerror "Failed to start /etc/init.d/${service}" - retval=$? - - return "${retval}" - ) + source "${svclib}"/sh/init.sh || { + echo "Could not source init.sh !?" + exit 1 } - - # We first try to find a locally defined list of critical services - # for a particular runlevel. If we cannot find it, we use the - # defaults. - get_critical_services - - export START_CRITICAL="yes" - # We do not want to break compatibility, so we do not fully integrate - # these into /sbin/rc, but rather start them by hand ... - for x in ${CRITICAL_SERVICES} - do - if ! start_critical_service "${x}" ; then - echo - eerror "One of more critical startup scripts failed to start!" - einfo "Rebooting" - /sbin/reboot -f - fi - done - - unset START_CRITICAL - - # Check that $svcdir exists ... - check_statedir "${svcdir}" - - # Clear $svcdir from stale entries, but leave the caches around, as it - # should help speed things up a bit - rm -rf $(ls -d1 "${svcdir}/"* 2>/dev/null | \ - grep -ve '\(depcache\|deptree\|envcache\)') - - echo "sysinit" > "${svcdir}/softlevel" - - # Update the dependency cache - /sbin/depscan.sh -u - - # Now that the dependency cache are up to date, make sure these - # are marked as started ... - ( - # Needed for mark_service_started() - source "${svclib}/sh/rc-services.sh" - - for x in ${CRITICAL_SERVICES} - do - mark_service_started "${x}" - done - ) - - # Setup login records ... this has to be done here because when - # we exit this runlevel, init will write a boot record to utmp - # If /var/run is readonly, then print a warning, not errors - if touch /var/run/utmp 2>/dev/null - then - > /var/run/utmp - touch /var/log/wtmp - chgrp utmp /var/run/utmp /var/log/wtmp - chmod 0664 /var/run/utmp /var/log/wtmp - # Remove /var/run/utmpx (bug from the past) - rm -f /var/run/utmpx - else - ewarn "Skipping /var/run/utmp initialization (ro root?)" - fi - [[ ${argv1} = "boot" ]] || exit 0 fi # Sysinit ends here @@ -167,67 +56,58 @@ then # We reset argv1 to the bootlevel given on the kernel command line # if there is one - argv1="${BOOTLEVEL}" + argv1=${BOOTLEVEL} fi source "${svclib}/sh/rc-services.sh" -if [ -f "${svcdir}/softlevel" ] -then +if [[ -f ${svcdir}/softlevel ]] ; then # Set OLDSOFTLEVEL if we had a valid SOFTLEVEL - export OLDSOFTLEVEL="$(< ${svcdir}/softlevel)" + export OLDSOFTLEVEL=$(< ${svcdir}/softlevel) else export OLDSOFTLEVEL= fi -if [ -z "${argv1}" ] -then - if [ -f "${svcdir}/softlevel" ] - then - export SOFTLEVEL="$(< ${svcdir}/softlevel)" +if [[ -z ${argv1} ]] ; then + if [[ -f ${svcdir}/softlevel ]] ; then + export SOFTLEVEL=$(< ${svcdir}/softlevel) else - export SOFTLEVEL="${BOOTLEVEL}" + export SOFTLEVEL=${BOOTLEVEL} fi else - export SOFTLEVEL="${argv1}" + export SOFTLEVEL=${argv1} fi -if [ ! -f "${svcdir}/softlevel" ] -then +if [[ ! -f ${svcdir}/softlevel ]] ; then echo "${SOFTLEVEL}" > "${svcdir}/softlevel" fi # For keeping a list of services that fails during boot/halt -if [ ! -d "${svcdir}/failed" ] -then +if [[ ! -d ${svcdir}/failed ]] ; then mkdir -p -m 0755 "${svcdir}/failed" else rm -rf "${svcdir}"/failed/* fi -if [ "${SOFTLEVEL}" = "reboot" -o "${SOFTLEVEL}" = "shutdown" ] -then +if [[ ${SOFTLEVEL} == "reboot" || ${SOFTLEVEL} == "shutdown" ]] ; then myscripts= -elif [ ! -d "/etc/runlevels/${SOFTLEVEL}" ] -then +elif [[ ! -d /etc/runlevels/${SOFTLEVEL} ]] ; then eerror "ERROR: runlevel ${SOFTLEVEL} does not exist; exiting ..." exit 1 else myscripts= - if [ "${SOFTLEVEL}" != "${BOOTLEVEL}" ] - then + if [[ ${SOFTLEVEL} != "${BOOTLEVEL}" ]] ; then # Normal runlevels *include* boot scripts - mylevels="$(dolisting "/etc/runlevels/${SOFTLEVEL}/")" + mylevels=$(dolisting "/etc/runlevels/${SOFTLEVEL}/") mylevels="${mylevels} $(dolisting /etc/runlevels/${BOOTLEVEL}/)" else # Non-normal runlevels don't include boot scripts as default - mylevels="$(dolisting "/etc/runlevels/${SOFTLEVEL}/")" + mylevels=$(dolisting "/etc/runlevels/${SOFTLEVEL}/") fi - for x in ${mylevels} - do - [ -L "${x}" ] && myscripts="${myscripts} ${x##*/}" + for x in ${mylevels} ; do + [[ -L ${x} ]] && myscripts="${myscripts} ${x##*/}" done fi @@ -253,7 +133,7 @@ get_stop_services() { local x list for x in $(dolisting "${svcdir}/inactive/") \ - $(dolisting "${svcdir}/started/") ; do + $(dolisting "${svcdir}/started/") ; do list="${list} ${x##*/}" done @@ -280,7 +160,7 @@ dep_stop() { for dep in $(needsme "${myservice}") ; do #if service_started "${dep}" && \ - if [[ -L "${svcdir}/softscripts.new/${dep}" ]] ; then + if [[ -L ${svcdir}/softscripts.new/${dep} ]] ; then # This dep is valid needsme=1 @@ -294,8 +174,7 @@ dep_stop() { # Stop services if [[ ${SOFTLEVEL} != "reboot" && \ - ${SOFTLEVEL} != "shutdown" ]] -then + ${SOFTLEVEL} != "shutdown" ]] ; then for i in $(get_stop_services) ; do dep_stop "${i}" done @@ -322,7 +201,7 @@ else done # Wait for any services that may still be stopping ... - [ "${RC_PARALLEL_STARTUP}" = "yes" ] && wait + [[ ${RC_PARALLEL_STARTUP} == "yes" ]] && wait export STOP_CRITICAL="yes" # Now stop the rest @@ -345,6 +224,9 @@ if [[ ${SOFTLEVEL} == "reboot" || ${SOFTLEVEL} == "shutdown" ]] ; then rm -rf $(ls -d1 "${svcdir}/"* 2>/dev/null | \ grep -ve '\(depcache\|deptree\|envcache\)') + # Need try(), etc + source "${svclib}"/sh/init-functions.sh + source /etc/init.d/halt.sh # we just die here since we have no init @@ -394,7 +276,7 @@ for i in $(get_start_services) ; do done # Wait for any services that may still be running ... -[ "${RC_PARALLEL_STARTUP}" = "yes" ] && wait +[[ ${RC_PARALLEL_STARTUP} == "yes" ]] && wait # Clean the old runlevel rm -rf "${svcdir}/softscripts.old" &>/dev/null @@ -414,4 +296,5 @@ fi # Remove the cached CONSOLETYPE unset CONSOLETYPE + # vim:ts=4 |