/[baselayout]/branches/rc-scripts-1_6/bin/rc-status
Gentoo

Diff of /branches/rc-scripts-1_6/bin/rc-status

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

Revision 1024 Revision 1025
76 ;; 76 ;;
77 esac 77 esac
78} 78}
79for opt in "$@" ; do 79for opt in "$@" ; do
80 do_opt ${opt} 80 do_opt ${opt}
81 [ -n "$2" ] && shift 81 [[ -n $2 ]] && shift
82done 82done
83 83
84################################################################################ 84################################################################################
85# Find the current runlevel being queried. This is either something supplied # 85# Find the current runlevel being queried. This is either something supplied #
86# on the command line, or pulled from softlevel # 86# on the command line, or pulled from softlevel #
87################################################################################ 87################################################################################
88if [ -z "${runlevel}" ] ; then 88if [[ -z "${runlevel}" ]] ; then
89 if [ -e "${svcdir}/softlevel" ] ; then 89 if [[ -e "${svcdir}/softlevel" ]] ; then
90 runlevel="$(<${svcdir}/softlevel)" 90 runlevel="$( <${svcdir}/softlevel )"
91 else 91 else
92 ewarn "Could not local current runlevel in ${svcdir}/softlevel" 92 ewarn "Could not local current runlevel in ${svcdir}/softlevel"
93 if [ -d "${runleveldir}/single" ] ; then 93 if [[ -d "${runleveldir}/single" ]] ; then
94 runlevel=single 94 runlevel=single
95 elif [ -d "${runleveldir}/default" ] ; then 95 elif [[ -d "${runleveldir}/default" ]] ; then
96 runlevel=default 96 runlevel=default
97 else 97 else
98 eerror "Your installation is probably broken ... please \`emerge baselayout\`" 98 eerror "Your installation is probably broken ... please \`emerge baselayout\`"
99 exit 1 99 exit 1
100 fi 100 fi
101 ewarn "Assuming current runrevel is '${runlevel}'" 101 ewarn "Assuming current runrevel is '${runlevel}'"
102 fi 102 fi
103fi 103fi
104if [ ! -d "${runleveldir}/${runlevel}" ] ; then 104if [[ ! -d "${runleveldir}/${runlevel}" ]] ; then
105 eerror "${runlevel} is not a valid run level !" 105 eerror "${runlevel} is not a valid run level !"
106 eerror "Valid runlevels (obtained from \`rc-status --list\`):" 106 eerror "Valid runlevels (obtained from \`rc-status --list\`):"
107 rc-status --list 107 rc-status --list
108 exit 1 108 exit 1
109fi 109fi
113# trivial case, this is simply the current runlevel. If --all was specified, # 113# trivial case, this is simply the current runlevel. If --all was specified, #
114# we gather information about all of the runlevels. If --unused was # 114# we gather information about all of the runlevels. If --unused was #
115# specified, we pull info about all of the services and filter for the ones # 115# specified, we pull info about all of the services and filter for the ones #
116# that don't appear in any runlevel. # 116# that don't appear in any runlevel. #
117################################################################################ 117################################################################################
118runlevelidxs=`ls ${runleveldir}` 118runlevelidxs=$( ls ${runleveldir} )
119declare -a runlevels 119declare -a runlevels
120# For each directory in /etc/runlevels, do ... 120# For each directory in /etc/runlevels, do ...
121arridx=0 121arridx=0
122for level in ${runlevelidxs} ; do 122for level in ${runlevelidxs} ; do
123 if [ "${level}" == "${runlevel}" ] || [ -n "${ALL}" ] ; then 123 if [[ ${level} == ${runlevel} || -n ${ALL} ]] ; then
124 runlevels[${arridx}]=$(find ${runleveldir}/${level} -maxdepth 1 -type l -printf '%f ') 124 runlevels[${arridx}]=$( find ${runleveldir}/${level} -maxdepth 1 -type l -printf '%f ' )
125 let "arridx += 1" 125 let "arridx += 1"
126 fi 126 fi
127done 127done
128 128
129# In case --all was specified, get a list of all the services set up in 129# In case --all was specified, get a list of all the services set up in
130# /etc/init.d; services can be added, but not enabled, and we need to 130# /etc/init.d; services can be added, but not enabled, and we need to
131# identify these 'orphan' services. 131# identify these 'orphan' services.
132in_list() { #$1=list $2=find 132in_list() { #$1=list $2=find
133 for ele in $1 ; do 133 for ele in $1 ; do
134 if [ "${ele}" == "$2" ] ; then 134 if [[ ${ele} == $2 ]] ; then
135 echo 1 135 echo 1
136 return 0 136 return 0
137 fi 137 fi
138 done 138 done
139 echo 0 139 echo 0
140 return 0 140 return 0
141} 141}
142if [ -n "${ALL}" ] ; then 142if [[ -n ${ALL} ]] ; then
143 unassigned= 143 unassigned=
144 allservices= 144 allservices=
145 for service in `ls -1 /etc/init.d | grep -v '\.sh$'` ; do 145 for service in $( ls -1 /etc/init.d | grep -v '\.sh$' ) ; do
146 if [ $(in_list "${runlevels[*]}" "${service}") -eq 0 ] ; then 146 if [[ $( in_list "${runlevels[*]}" "${service}" ) -eq 0 ]] ; then
147 unassigned="${unassigned} ${service}" 147 unassigned="${unassigned} ${service}"
148 fi 148 fi
149 allservices="${allservices} ${service}" 149 allservices="${allservices} ${service}"
150 done 150 done
151 runlevelidxs="${runlevelidxs} UNASSIGNED" 151 runlevelidxs="${runlevelidxs} UNASSIGNED"
156################################################################################ 156################################################################################
157# Now collect information about the status of the various services; whether # 157# Now collect information about the status of the various services; whether #
158# they're started, broken, or failed. Put all of this into arrays. # 158# they're started, broken, or failed. Put all of this into arrays. #
159################################################################################ 159################################################################################
160# Read services from ${svcdir}/{started,failed,broken} 160# Read services from ${svcdir}/{started,failed,broken}
161[[ -x "${svcdir}/starting" ]] && starting=$( ls ${svcdir}/starting )
162[[ -x "${svcdir}/inactive" ]] && inactive=$( ls ${svcdir}/inactive )
161[ -x ${svcdir}/started ] && started=`ls ${svcdir}/started` 163[[ -x "${svcdir}/started" ]] && started=$( ls ${svcdir}/started )
164[[ -x "${svcdir}/stopping" ]] && stopping=$( ls ${svcdir}/stopping )
162[ -x ${svcdir}/failed ] && failed=`ls ${svcdir}/failed` 165[[ -x "${svcdir}/failed" ]] && failed=$( ls ${svcdir}/failed )
163[ -x ${svcdir}/broken ] && broken=`ls ${svcdir}/broken` 166[[ -x "${svcdir}/broken" ]] && broken=$( ls ${svcdir}/broken )
164 167
165################################################################################ 168################################################################################
166# Now print out the information we've gathered. We do this by going through # 169# Now print out the information we've gathered. We do this by going through #
167# the hash of 'runlevels' information, and for each String key/Array value # 170# the hash of 'runlevels' information, and for each String key/Array value #
168# pair, print the runlevel; then for each service in that runlevel, print the # 171# pair, print the runlevel; then for each service in that runlevel, print the #
172print_msg() { 175print_msg() {
173 printf " %-$((COLS - 5 - ${#3}))s%s\n" "$1" "${BRACKET}[ $2$3 ${BRACKET}]${NORMAL}" 176 printf " %-$((COLS - 5 - ${#3}))s%s\n" "$1" "${BRACKET}[ $2$3 ${BRACKET}]${NORMAL}"
174} 177}
175 178
176# if --all wasnt specified, dont print everything 179# if --all wasnt specified, dont print everything
177[ -z "${ALL}" ] && runlevelidxs="${runlevel}" 180[[ -z ${ALL} ]] && runlevelidxs=${runlevel}
178if [ -z "${UNUSED}" ] ; then 181if [[ -z ${UNUSED} ]] ; then
179 if [ -z "${SERVICELIST}" ] ; then 182 if [[ -z ${SERVICELIST} ]] ; then
180 arridx=0 183 arridx=0
181 else 184 else
182 runlevelidxs="all" 185 runlevelidxs="all"
183 let "arridx += 1" 186 let "arridx += 1"
184 fi 187 fi
187fi 190fi
188 191
189for level in ${runlevelidxs} ; do 192for level in ${runlevelidxs} ; do
190 echo "Runlevel: ${HILITE}${level}${NORMAL}" 193 echo "Runlevel: ${HILITE}${level}${NORMAL}"
191 for service in ${runlevels[${arridx}]} ; do 194 for service in ${runlevels[${arridx}]} ; do
195 if [[ -n ${inactive} && $( in_list "${inactive}" "${service}" ) -eq 1 ]] ; then
196 print_msg "${service}" "${WARN}" 'inactive'
192 if [ $(in_list "${started}" "${service}") -eq 1 ] ; then 197 elif [[ $(in_list "${started}" "${service}") -eq 1 ]] ; then
193 print_msg "${service}" "${GOOD}" 'started' 198 print_msg "${service}" "${GOOD}" 'started'
199 elif [[ -n ${starting} && $( in_list "${starting}" "${service}" ) -eq 1 ]] ; then
200 print_msg "${service}" "${GOOD}" 'starting'
201 elif [[ -n ${stopping} && $( in_list "${stopping}" "${service}" ) -eq 1 ]] ; then
202 print_msg "${service}" "${BAD}" 'stopping'
203 elif [[ -n ${failed} && $( in_list "${failed}" "${service}" ) -eq 1 ]] ; then
204 print_msg "${service}" "${BAD}" 'failed'
205 elif [[ -n ${broken} && $( in_list "${broken}" "${service}" ) -eq 1 ]] ; then
206 print_msg "${service}" "${BAD}" 'broken'
194 else 207 else
195 if [ -n "${failed}" ] && [ $(in_list "${failed}" "${service}") -eq 1 ] ; then
196 print_msg "${service}" "${BAD}" 'failed'
197 elif [ -n "${broken}" ] && [ $(in_list "${broken}" "${service}") -eq 1 ] ; then
198 print_msg "${service}" "${BAD}" 'broken'
199 else
200 print_msg "${service}" "${WARN}" ' off' 208 print_msg "${service}" "${WARN}" ' off'
201 fi
202 fi 209 fi
203 done 210 done
204 let "arridx += 1" 211 let "arridx += 1"
205 [ -n "${UNUSED}" ] && exit 0 212 [ -n "${UNUSED}" ] && exit 0
206done 213done

Legend:
Removed from v.1024  
changed lines
  Added in v.1025

  ViewVC Help
Powered by ViewVC 1.1.20