diff options
Diffstat (limited to 'sbin/rc-services.sh')
-rwxr-xr-x | sbin/rc-services.sh | 164 |
1 files changed, 81 insertions, 83 deletions
diff --git a/sbin/rc-services.sh b/sbin/rc-services.sh index d928a5f..4a177cd 100755 --- a/sbin/rc-services.sh +++ b/sbin/rc-services.sh @@ -7,7 +7,7 @@ RC_GOT_SERVICES="yes" [[ ${RC_GOT_FUNCTIONS} != "yes" ]] && source /sbin/functions.sh -if [[ ${RC_GOT_DEPTREE_INFO} != "yes" ]]; then +if [[ ${RC_GOT_DEPTREE_INFO} != "yes" ]] ; then # Only try and update if we are root if [[ ${EUID} == "0" ]] && ! /sbin/depscan.sh -u ; then echo @@ -17,7 +17,7 @@ if [[ ${RC_GOT_DEPTREE_INFO} != "yes" ]]; then fi source "${svcdir}/deptree" - if [[ ${RC_GOT_DEPTREE_INFO} != "yes" ]]; then + if [[ ${RC_GOT_DEPTREE_INFO} != "yes" ]] ; then echo eerror "Dependency info is missing! Please run" eerror " # /sbin/depscan.sh" @@ -53,23 +53,23 @@ rc_mtime= # Print the index of 'service'. 'index' is the current index. # get_service_index() { - if [[ -z $1 || -z $2 ]]; then + if [[ -z $1 || -z $2 ]] ; then echo "0" return 1 fi - local x myservice="$1" index="$2" + local x myservice=$1 index=$2 # Do we already have the index? if [[ -n ${index} && ${index} -gt 0 \ - && ${myservice} == ${RC_DEPEND_TREE[${index}]} ]]; then + && ${myservice} == "${RC_DEPEND_TREE[${index}]}" ]] ; then echo "${index}" return 0 fi for (( x=1; x<=${RC_DEPEND_TREE[0]}; x++ )); do index=$(( ${x} * ${rc_index_scale} )) - if [[ ${myservice} == ${RC_DEPEND_TREE[${index}]} ]]; then + if [[ ${myservice} == "${RC_DEPEND_TREE[${index}]}" ]] ; then echo "${index}" return 0 fi @@ -86,10 +86,10 @@ get_service_index() { get_dep_info() { [[ -z $1 ]] && return 1 - local myservice="$1" + local myservice=$1 # We already have the right stuff ... - [[ ${myservice} == ${rc_name} && -n ${rc_mtime} ]] && return 0 + [[ ${myservice} == "${rc_name}" && -n ${rc_mtime} ]] && return 0 rc_index="`get_service_index "${myservice}" "${rc_index}"`" rc_mtime="${RC_DEPEND_TREE[$((${rc_index} + ${rc_type_mtime}))]}" @@ -97,7 +97,7 @@ get_dep_info() { # Verify that we have the correct index (rc_index) ... # [[ ${rc_index} == "0" ]] && return 1 - rc_name="${RC_DEPEND_TREE[${rc_index}]}" + rc_name=${RC_DEPEND_TREE[${rc_index}]} rc_ineed="${RC_DEPEND_TREE[$((${rc_index} + ${rc_type_ineed}))]}" rc_needsme="${RC_DEPEND_TREE[$((${rc_index} + ${rc_type_needsme}))]}" rc_iuse="${RC_DEPEND_TREE[$((${rc_index} + ${rc_type_iuse}))]}" @@ -125,11 +125,11 @@ check_dependency() { local x myservice deps # Set the dependency variables to relate to 'service1' - if [[ $2 == "-t" ]]; then + if [[ $2 == "-t" ]] ; then [[ -z $3 || -z $4 ]] && return 1 - myservice="$3" + myservice=$3 else - myservice="$2" + myservice=$2 fi if ! get_dep_info "${myservice}" >/dev/null ; then @@ -146,8 +146,8 @@ check_dependency() { if [[ $2 == "-t" && -n $4 ]]; then # Check if 'service1' have 'deptype' dependency on 'service2' - for x in ${deps}; do - [[ ${x} == $4 ]] && return 0 + for x in ${deps} ; do + [[ ${x} == "$4" ]] && return 0 done return 1 else @@ -213,14 +213,14 @@ is_fake_service() { [[ -z $1 || -z $2 ]] && return 1 - [[ $2 != ${BOOTLEVEL} && -e "/etc/runlevels/${BOOTLEVEL}/.fake" ]] \ - && fake_services="$( < /etc/runlevels/${BOOTLEVEL}/.fake )" + [[ $2 != "${BOOTLEVEL}" && -e /etc/runlevels/${BOOTLEVEL}/.fake ]] && \ + fake_services=$( < /etc/runlevels/${BOOTLEVEL}/.fake ) - [[ -e "/etc/runlevels/$2/.fake" ]] \ - && fake_services="${fake_services} $( < /etc/runlevels/$2/.fake )" + [[ -e /etc/runlevels/$2/.fake ]] && \ + fake_services="${fake_services} $( < /etc/runlevels/$2/.fake )" - for x in ${fake_services}; do - [[ $1 == ${x##*/} ]] && return 0 + for x in ${fake_services} ; do + [[ $1 == "${x##*/}" ]] && return 0 done return 1 @@ -233,7 +233,7 @@ is_fake_service() { in_runlevel() { [[ -z $1 || -z $2 ]] && return 1 - [[ -L "/etc/runlevels/$2/$1" ]] && return 0 + [[ -L /etc/runlevels/$2/$1 ]] && return 0 return 1 } @@ -269,15 +269,15 @@ service_message() { [[ ${RC_PARALLEL_STARTUP} != "yes" ]] && return local cmd="einfo" - if [[ $1 == 1 || $1 == "error" || $1 == "eerror" ]]; then + if [[ $1 == "1" || $1 == "error" || $1 == "eerror" ]] ; then cmd="eerror" shift fi - local r="${RC_QUIET_STDOUT}" + local r=${RC_QUIET_STDOUT} RC_QUIET_STDOUT="no" ${cmd} "$@" - RC_QUIET_STDOUT="${r}" + RC_QUIET_STDOUT=${r} } # bool begin_service( service ) @@ -289,8 +289,7 @@ service_message() { # whatever is in here can only be executed by one process # end_service service # fi -begin_service() -{ +begin_service() { [[ {$START_CRITICAL} == "yes" ]] && return 0 mkfifo "${svcdir}/exclusive/${service}" 2> /dev/null @@ -302,9 +301,8 @@ begin_service() # stops executing a exclusive region and # wakes up anybody who is waiting for the exclusive region # -end_service() -{ - local service="$1" exitstatus="$2" +end_service() { + local service=$1 exitstatus=$2 # if we are doing critical services, there is no fifo [[ ${START_CRITICAL} == "yes" ]] && return @@ -315,7 +313,7 @@ end_service() # move the fifo to a unique name so no-one is waiting for it local fifo="${svcdir}/exclusive/${service}" - if [[ -e "${fifo}" ]]; then + if [[ -e ${fifo} ]] ; then local tempname="${fifo}.$$" mv -f "${fifo}" "${tempname}" @@ -332,9 +330,8 @@ end_service() # If a service has started, or a fifo does not exist return 0 # Otherwise, wait until we get an exit code via the fifo and return # that instead. -wait_service() -{ - local service="$1" +wait_service() { + local service=$1 local fifo="${svcdir}/exclusive/${service}" [[ ${START_CRITICAL} == "yes" || ${STOP_CRITICAL} == "yes" ]] && return 0 @@ -353,10 +350,10 @@ wait_service() # Start 'service' if it is not already running. # start_service() { - local service="$1" + local service=$1 [[ -z ${service} ]] && return 1 - if [[ ! -e "/etc/init.d/${service}" ]]; then + if [[ ! -e "/etc/init.d/${service}" ]] ; then mark_service_stopped "${service}" return 1 fi @@ -371,19 +368,19 @@ start_service() { fi begin_service "${service}" || return 0 - if [[ ${RC_PARALLEL_STARTUP} != "yes" \ - || ${START_CRITICAL} == "yes" ]] ; then + if [[ ${RC_PARALLEL_STARTUP} != "yes" || \ + ${START_CRITICAL} == "yes" ]] ; then # if we can not start the services in parallel # then just start it and return the exit status ( "/etc/init.d/${service}" start ) - retval="$?" + retval=$? end_service "${service}" "${retval}" return "${retval}" else # if parallel startup is allowed, start it in background ( "/etc/init.d/${service}" start - retval="$?" + retval=$? end_service "${service}" "${retval}" ) & return 0 @@ -395,10 +392,10 @@ start_service() { # Stop 'service' if it is not already running. # stop_service() { - local service="$1" + local service=$1 [[ -z ${service} ]] && return 1 - if [[ ! -e "/etc/init.d/${service}" ]]; then + if [[ ! -e /etc/init.d/${service} ]] ; then mark_service_stopped "${service}" return 0 fi @@ -407,7 +404,7 @@ stop_service() { service_stopped "${service}" && return 0 local level="${SOFTLEVEL}" - is_runlevel_stop && level="${OLDSOFTLEVEL}" + is_runlevel_stop && level=${OLDSOFTLEVEL} if is_fake_service "${service}" "${level}" ; then mark_service_stopped "${service}" @@ -416,19 +413,19 @@ stop_service() { begin_service "${service}" || return 0 - if [[ ${RC_PARALLEL_STARTUP} != "yes" \ - || ${STOP_CRITICAL} == "yes" ]] ; then + if [[ ${RC_PARALLEL_STARTUP} != "yes" || \ + ${STOP_CRITICAL} == "yes" ]] ; then # if we can not start the services in parallel # then just start it and return the exit status ( "/etc/init.d/${service}" stop ) - retval="$?" + retval=$? end_service "${service}" "${retval}" return "${retval}" else # if parallel startup is allowed, start it in background ( ( "/etc/init.d/${service}" stop ) - retval="$?" + retval=$? end_service "${service}" "${retval}" ) & return 0 @@ -445,9 +442,9 @@ mark_service_starting() { ln -snf "/etc/init.d/$1" "${svcdir}/starting/$1" local retval=$? - [[ -f "${svcdir}/started/$1" ]] && rm -f "${svcdir}/started/$1" - [[ -f "${svcdir}/inactive/$1" ]] && rm -f "${svcdir}/inactive/$1" - [[ -f "${svcdir}/stopping/$1" ]] && rm -f "${svcdir}/stopping/$1" + [[ -f ${svcdir}/started/$1 ]] && rm -f "${svcdir}/started/$1" + [[ -f ${svcdir}/inactive/$1 ]] && rm -f "${svcdir}/inactive/$1" + [[ -f ${svcdir}/stopping/$1 ]] && rm -f "${svcdir}/stopping/$1" return "${retval}" } @@ -460,11 +457,11 @@ mark_service_started() { [[ -z $1 ]] && return 1 ln -snf "/etc/init.d/$1" "${svcdir}/started/$1" - local retval="$?" + local retval=$? - [[ -f "${svcdir}/starting/$1" ]] && rm -f "${svcdir}/starting/$1" - [[ -f "${svcdir}/inactive/$1" ]] && rm -f "${svcdir}/inactive/$1" - [[ -f "${svcdir}/stopping/$1" ]] && rm -f "${svcdir}/stopping/$1" + [[ -f ${svcdir}/starting/$1 ]] && rm -f "${svcdir}/starting/$1" + [[ -f ${svcdir}/inactive/$1 ]] && rm -f "${svcdir}/inactive/$1" + [[ -f ${svcdir}/stopping/$1 ]] && rm -f "${svcdir}/stopping/$1" return "${retval}" } @@ -477,10 +474,10 @@ mark_service_inactive() { [[ -z $1 ]] && return 1 ln -snf "/etc/init.d/$1" "${svcdir}/inactive/$1" - local retval="$?" - [[ -f "${svcdir}/started/$1" ]] && rm -f "${svcdir}/started/$1" - [[ -f "${svcdir}/starting/$1" ]] && rm -f "${svcdir}/starting/$1" - [[ -f "${svcdir}/stopping/$1" ]] && rm -f "${svcdir}/stopping/$1" + local retval=$? + [[ -f ${svcdir}/started/$1 ]] && rm -f "${svcdir}/started/$1" + [[ -f ${svcdir}/starting/$1 ]] && rm -f "${svcdir}/starting/$1" + [[ -f ${svcdir}/stopping/$1 ]] && rm -f "${svcdir}/stopping/$1" return "${retval}" } @@ -493,11 +490,11 @@ mark_service_stopping() { [[ -z $1 ]] && return 1 ln -snf "/etc/init.d/$1" "${svcdir}/stopping/$1" - local retval="$?" + local retval=$? - [ -f "${svcdir}/starting/$1" ] && rm -f "${svcdir}/starting/$1" - [ -f "${svcdir}/started/$1" ] && rm -f "${svcdir}/started/$1" - [ -f "${svcdir}/inactive/$1" ] && rm -f "${svcdir}/inactive/$1" + [ -f ${svcdir}/starting/$1 ] && rm -f "${svcdir}/starting/$1" + [ -f ${svcdir}/started/$1 ] && rm -f "${svcdir}/started/$1" + [ -f ${svcdir}/inactive/$1 ] && rm -f "${svcdir}/inactive/$1" return "${retval}" } @@ -509,10 +506,11 @@ mark_service_stopping() { mark_service_stopped() { [[ -z $1 ]] && return 1 - [[ -f "${svcdir}/starting/$1" ]] && rm -f "${svcdir}/starting/$1" - [[ -f "${svcdir}/started/$1" ]] && rm -f "${svcdir}/started/$1" - [[ -f "${svcdir}/inactive/$1" ]] && rm -f "${svcdir}/inactive/$1" - [[ -f "${svcdir}/stopping/$1" ]] && rm -f "${svcdir}/stopping/$1" + [[ -f ${svcdir}/daemons/$1 ]] && rm -f "${svcdir}/daemons/$1" + [[ -f ${svcdir}/starting/$1 ]] && rm -f "${svcdir}/starting/$1" + [[ -f ${svcdir}/started/$1 ]] && rm -f "${svcdir}/started/$1" + [[ -f ${svcdir}/inactive/$1 ]] && rm -f "${svcdir}/inactive/$1" + [[ -f ${svcdir}/stopping/$1 ]] && rm -f "${svcdir}/stopping/$1" return $? } @@ -529,7 +527,7 @@ test_service_state() { # Service is in the state requested [[ -L ${f} ]] && return 0 - if [[ ! -e ${f} ]]; then + if [[ ! -e ${f} ]] ; then rm -f "${f}" return 1 fi @@ -590,7 +588,7 @@ service_stopped() { # this is only valid on runlevel change ... # mark_service_failed() { - [[ -z $1 || ! -d "${svcdir}/failed" ]] && return 1 + [[ -z $1 || ! -d ${svcdir}/failed ]] && return 1 ln -snf "/etc/init.d/$1" "${svcdir}/failed/$1" } @@ -600,7 +598,7 @@ mark_service_failed() { # Return true if 'service' have failed during this runlevel. # service_failed() { - [[ -n $1 && -L "${svcdir}/failed/$1" ]] + [[ -n $1 && -L ${svcdir}/failed/$1 ]] } # bool dependon(service1, service2) @@ -625,10 +623,9 @@ valid_i() { # Cannot be SOFTLEVEL, as we need to know current runlevel [[ -f ${svcdir}/softlevel ]] && mylevel=$( < "${svcdir}/softlevel" ) - for x in $( i$1 "$2" ) - do - [[ -e "/etc/runlevels/${BOOTLEVEL}/${x}" \ - || -e "/etc/runlevels/${mylevel}/${x}" ]] \ + for x in $( i$1 "$2" ) ; do + [[ -e /etc/runlevels/${BOOTLEVEL}/${x} || \ + -e "/etc/runlevels/${mylevel}/${x}" ]] \ && echo "${x}" done @@ -661,8 +658,8 @@ trace_dependencies() { local -a services=( "$@" ) deps local i j - if [[ $1 == -* ]]; then - deptype="${1/-}" + if [[ $1 == -* ]] ; then + deptype=${1/-} services=( "${myservice}" ) fi @@ -672,9 +669,9 @@ trace_dependencies() { } local last="" - while [[ ${services[@]} != "${last}" ]]; do + while [[ ${services[@]} != "${last}" ]] ; do last="${services[*]}" - for (( i=0; i<${#services[@]}; i++ )); do + for (( i=0; i<${#services[@]}; i++ )) ; do if [[ -n ${deptype} ]] ; then deps=( "${deps[@]}" $( "${deptype}" "${services[i]}" ) ) else @@ -698,34 +695,34 @@ trace_dependencies() { # revisit any dependencies. Finally we add ourselves to the sorted list. # This should never get into an infinite loop, thanks to our dead array. local -a dead=() deadname=() sorted=() - for (( i=0; i<${#services[@]}; i++ )); do - dead[i]=false; + for (( i=0; i<${#services[@]}; i++ )) ; do + dead[i]="false" deadname[i]="${services[i]}" done after_visit() { - local service="$1" i + local service=$1 i - for (( i=0; i<${#deadname[@]}; i++)); do + for (( i=0; i<${#deadname[@]}; i++)) ; do [[ ${service} == ${deadname[i]} ]] && break done ${dead[i]} && return - dead[i]=true + dead[i]="true" local x deps="$( ineed ${service} ) $( valid_iuse ${service} )" if is_runlevel_start || is_runlevel_stop ; then deps="${deps} $( valid_iafter ${service} )" fi - for x in ${deps}; do + for x in ${deps} ; do after_visit "${x}" done sorted=( "${sorted[@]}" "${service}" ) } - for (( i=0; i<${#services[*]}; i++ )); do + for (( i=0; i<${#services[*]}; i++ )) ; do after_visit "${services[i]}" done services=( "${sorted[@]}" ) @@ -758,4 +755,5 @@ query_before() { return 1 } + # vim:ts=4 |