X-Git-Url: http://gitweb.hugovil.com/?a=blobdiff_plain;f=stage1%2Fbootscripts%2Frc;h=f9654f59df474b2a4c0382c0605539d1f54dba10;hb=6007645124befc70ffe2fae5500022b215d59ce6;hp=9e4087d7648195c8906e553a7ddca32d1b4c89a5;hpb=6d3d50c17b24ef41f917f5776696eca810198092;p=hvlinux.git diff --git a/stage1/bootscripts/rc b/stage1/bootscripts/rc index 9e4087d..f9654f5 100755 --- a/stage1/bootscripts/rc +++ b/stage1/bootscripts/rc @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # rc @@ -43,12 +43,12 @@ check_script_status() echo "$1 is not a valid symlink" return ${EXIT_CODE_FAILURE} fi - + if [ ! -x $1 ]; then echo "$1 is not executable, skipping" return ${EXIT_CODE_FAILURE} fi - + return ${EXIT_CODE_SUCCESS} } @@ -61,7 +61,7 @@ trap ":" INT QUIT TSTP runlevel=${1} # If no runlevel was passed as an argument, we won't change runlevels. -if [ "${runlevel}" = "" ]; then +if [ "${runlevel}" == "" ]; then echo "Usage: ${0} " >&2 exit ${EXIT_CODE_FAILURE} fi @@ -81,69 +81,87 @@ if [ ! -d /etc/rc.d/rc${runlevel}.d ]; then fi # First, attempt to stop all services started by previous runlevel, -# and killed in this runlevel (K8 scripts +# and killed in this runlevel (K* scripts # If so, first collect all the K* scripts in the new run level. if [ ${previous} != N ]; then for kill_script in $(ls /etc/rc.d/rc${runlevel}.d/K* 2> /dev/null); do - if [ -f ${kill_script} ]; then - # "suffix" will contain the script name without the leading Kxx. - suffix="${kill_script##*/K[0-9][0-9]}" - - # If there is a S script in the previous runlevel corresponding - # to this K script, determine what it's full path is. - previous_start="/etc/rc.d/rc${previous}.d/S[0-9][0-9]${suffix}" - - # If no start script was found in the previous run level it could - # be that something was started in rcsysinit.d (sysinit level) so we'll - # determine the path for that possibility as well. - sysinit_start="/etc/rc.d/rcsysinit.d/S[0-9][0-9]${suffix}" - - # Stop the service if there is a start script in the previous run - # level or in the sysinit level. Otherwise, don't execute this K - # script because the service is not active. - if [ -f ${previous_start} -o -f ${sysinit_start} ]; then - startup ${kill_script} stop - retval=${?} - if [ ${retval} -ne ${EXIT_CODE_SUCCESS} -a ${retval} -ne ${EXIT_CODE_WARNING} ]; then - print_error_msg ${kill_script} ${retval} - fi - fi + check_script_status ${kill_script} + if [ ${?} != ${EXIT_CODE_SUCCESS} ]; then + continue + fi + + # "suffix" will contain the script name without the leading Kxx. + suffix="${kill_script##*/K[0-9][0-9]}" + + # If there is a S script in the previous runlevel corresponding + # to this K script, determine what it's full path is. + previous_start="/etc/rc.d/rc${previous}.d/S[0-9][0-9]${suffix}" + + # If no start script was found in the previous run level it could + # be that something was started in rcsysinit.d (sysinit level) so we'll + # determine the path for that possibility as well. + sysinit_start="/etc/rc.d/rcsysinit.d/S[0-9][0-9]${suffix}" + + # Stop the service if there is a start script in the previous run + # level or in the sysinit level. Otherwise, don't execute this K + # script because the service is not active. + if [ "${runlevel}" != "0" -a "${runlevel}" != "6" ]; then + if [ ! -f ${previous_start} -a ! -f ${sysinit_start} ]; then + echo "Warning: script ${kill_script} cannot be stopped because it was not started" + echo "in the previous runlevel" + continue + fi + fi + + startup ${kill_script} stop + retval=${?} + if [ ${retval} -ne ${EXIT_CODE_SUCCESS} -a ${retval} -ne ${EXIT_CODE_WARNING} ]; then + print_error_msg ${kill_script} ${retval} fi done fi # Now run the START scripts for this runlevel. for start_script in $(ls /etc/rc.d/rc${runlevel}.d/S* 2> /dev/null); do - # "suffix" will contain the script name without the leading Sxx. - suffix=${start_script#/etc/rc.d/rc${runlevel}.d/S[0-9][0-9]} + if [ "${previous}" != "N" ]; then + # "suffix" will contain the script name without the leading Sxx. + suffix=${start_script#/etc/rc.d/rc${runlevel}.d/S[0-9][0-9]} - # If there is a K script in the current runlevel corresponding - # to this S script, determine what it's full path is. - current_stop=/etc/rc.d/rc${runlevel}.d/K[0-9][0-9]${suffix} + # If there is a K script in the current runlevel corresponding + # to this S script, determine what it's full path is. + current_stop=/etc/rc.d/rc${runlevel}.d/K[0-9][0-9]${suffix} - if [ ${previous} != "N" ]; then # If there is a S script in the previous runlevel corresponding # to this S script, determine what it's full path is. previous_start=/etc/rc.d/rc${previous}.d/S[0-9][0-9]${suffix} - else - previous_start="" + + if [ -f ${previous_start} -a ! -f ${current_stop} ]; then + # If the service was started in the previous level and was not stopped + # in this runlevel, then we don't have to re-start it. + continue + fi fi - if [ -f "$previous_start" -a ! -f "$current_stop" ]; then - # If the service was started in the previous level and was not stopped - # in this runlevel, then we don't have to re-start it. - continue - else - # If the service was not started in the previous level, or if we just - # stopped it in this runlevel, then we need to start or restart it. - check_script_status ${start_script} - if [ ${?} = ${EXIT_CODE_SUCCESS} ]; then - startup ${start_script} start - retval=${?} - if [ ${retval} -ne ${EXIT_CODE_SUCCESS} -a ${retval} -ne ${EXIT_CODE_WARNING} ]; then - print_error_msg ${start_script} ${retval} - fi - fi + check_script_status ${start_script} + if [ ${?} != ${EXIT_CODE_SUCCESS} ]; then + continue + fi + + # If the service was not started in the previous level, or if we just + # stopped it in this runlevel, then we need to start or restart it. + + case ${runlevel} in + 0|6) + startup ${start_script} stop + ;; + *) + startup ${start_script} start + ;; + esac + + retval=${?} + if [ ${retval} -ne ${EXIT_CODE_SUCCESS} -a ${retval} -ne ${EXIT_CODE_WARNING} ]; then + print_error_msg ${start_script} ${retval} fi done