Go to:
Gentoo Home
Documentation
Forums
Lists
Bugs
Planet
Store
Wiki
Get Gentoo!
Gentoo's Bugzilla – Attachment 2738 Details for
Bug 4222
A couple of extra scripts for Gentoo's RC system
Home
|
New
–
[Ex]
|
Browse
|
Search
|
Privacy Policy
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
the /usr/sbin/rc-status script rewritten in bash
rc-status-bash (text/plain), 8.91 KB, created by
SpanKY
on 2002-08-02 07:49:12 UTC
(
hide
)
Description:
the /usr/sbin/rc-status script rewritten in bash
Filename:
MIME Type:
Creator:
SpanKY
Created:
2002-08-02 07:49:12 UTC
Size:
8.91 KB
patch
obsolete
>#!/bin/bash >################################################################################ ># # ># Author: Sean E. Russell <ser@germane-software.com> # ># Version: 1.0 # ># Date: Jun 26, 2002 # ># Adaptation: Mike Frysinger [SpanKY] <vapier@netzero.com> # ># Original code was in Ruby ... recoded into bash (at syntax level) # ># # ># This application displays information about the RC system used by Gentoo. # ># In particular, it displays a tree-like format of a run level, showing # ># all of the services that are installed at that level, and what each # ># service's status is (running, stopped, etc.) # ># # ># -a can be used to display all runlevels # ># -d can be used to display service dependancies # ># -u will display all unassigned services # ># -n will turn off colors # ># -h will display help # ># <runlevel> is used to choose the run level for which information is # ># displayed # ># # ># By default, rc-status only displays information about the current # ># runlevel; services installed and services running. # ># # >################################################################################ > >#require 'getoptlong' # For parsing options > >COLS=( `stty size` ) ; let "COLS = ${COLS[1]} - 14" >#COLS=`stty size`.split[1].to_i - 14 # Get the number of columns of the term > >#filter = proc {|f| f =~ /^\..*/} # A dirlist filter for .* files > > >################################################################################ ># # ># Parse command line options # ># # >################################################################################ >#opts = GetoptLong.new( [ '--all', '-a', GetoptLong::NO_ARGUMENT], ># [ '--unused', '-u', GetoptLong::NO_ARGUMENT], ># [ '--help', '-h', GetoptLong::NO_ARGUMENT], ># [ '--nocolors', '-n', GetoptLong::NO_ARGUMENT], ># [ '--list', '-l', GetoptLong::NO_ARGUMENT]) >do_opt() { > case $1 in > "--all" | "-a" ) > ALL=true;; > "--depend" ) > DEPEND=true;; > "--unused" | "-u" ) > ALL=true > UNUSED=true;; > "--nocolors" | "-n" ) > NOCOLORS=true;; > "--list" | "-l" ) > for runlvl in `ls /etc/runlevels` ; do > echo $runlvl > done > exit 0;; > "--help" | "-h" | -* ) > echo "USAGE: $0 [--nocolors] [--all | --list | --unused | <runlevel>]" > echo " --all -a Show services at all run levels" > echo " --list -l Show list of run levels" > echo " --unused -u Show services not assigned to any run level" > echo " --nocolors -n Turn off colors" > echo " <runlevel> Show services assigned to <runlevel>" > echo "If no arguments are supplied, shows services for current run level." > exit 0;; > * ) > runlevel=$1;; > esac >} >for opt in $* ; do > do_opt ${opt} > [ -n "$2" ] && shift >done > >################################################################################ ># # ># Find the current runlever being queried. This is either something supplied # ># on the command line, or pulled from softlevel # ># # >################################################################################ >[ -z "${runlevel}" ] && runlevel=`</mnt/.init.d/softlevel` > >################################################################################ ># # ># Define a bunch of terminal colors. If the user chose --nocolors, we simply # ># define the colors to be the empty string # ># # >################################################################################ >if [ -n "${NOCOLORS}" ] ; then > NORMAL= > GOOD= > WARN= > BAD= > HILITE= > BLUE= >else > # These were stolen from /etc/init.d/functions.sh, and are the standard > # Gentoo console colors > NORMAL="\033[0m" > GOOD="\e[32;01m" > WARN="\e[33;01m" > BAD="\e[31;01m" > HILITE="\e[36;01m" > BLUE="\e[34;01m" >fi > >################################################################################ ># # ># Build up a hash of the services associated with each run level. In the most # ># trivial case, this is simply the current runlevel. If --all was specified, # ># we gather information about all of the runlevels. If --unused was # ># specified, we pull info about all of the services and filter for the ones # ># that don't appear in any runlevel. # ># # >################################################################################ >runlevelidxs=`ls /etc/runlevels` >declare -a runlevels ># For each directory in /etc/runlevels, do ... >arridx=0 >for level in ${runlevelidxs} ; do > let "${level} = ${arridx}" > let "arridx += 1" > if [ "${level}" == "${runlevel}" ] || [ -n "${ALL}" ] ; then > runlevels[${!level}]=`ls /etc/runlevels/${level}` > fi >done > ># In case --all was specified, get a list of all the services set up in ># /etc/init.d; services can be added, but not enabled, and we need to ># identify these 'orphan' services. >in_list () { #$1=list $2=find > for ele in $1 ; do > if [ "${ele}" == "$2" ] ; then > echo 1 > return 0 > fi > done > echo 0 > return 0 >} >if [ -n "${ALL}" ] ; then > unassigned= > for service in `ls -1 /etc/init.d | grep -v .sh$` ; do > if [ $(in_list "${runlevels[*]}" "${service}") -eq 0 ] ; then > unassigned="${unassigned} ${service}" > fi > done > let "UNASSIGNED = ${arridx}" > runlevelidxs="UNASSIGNED ${runlevelidxs}" > runlevels[${UNASSIGNED}]="${unassigned}" >fi > >################################################################################ ># # ># Now collect information about the status of the various services; whether # ># they're started, broken, or failed. Put all of this into arrays. # ># # >################################################################################ ># Read services from /mnt/.init.d/{started,failed,broken} >[ -x /mnt/.init.d/started ] && started=`ls /mnt/.init.d/started` >[ -x /mnt/.init.d/failed ] && failed=`ls /mnt/.init.d/failed` >[ -x /mnt/.init.d/broken ] && broken=`ls /mnt/.init.d/broken` > >################################################################################ ># # ># Now print out the information we've gathered. We do this by going through # ># the hash of 'runlevels' information, and for each String key/Array value # ># pair, print the runlevel; then for each service in that runlevel, print the # ># service name and its status. # ># # >################################################################################ ># Define a helper method for printing the status of a service; '[ xxx ]' >print_msg () { > printf "${BLUE}[ $1%-7s ${BLUE}]${NORMAL}\n" $2 >} > >#if --all wasnt specified, dont print everything >[ -z "${ALL}" ] && runlevelidxs="${runlevel}" > >for level in ${runlevelidxs} ; do > printf "Runlevel: ${HILITE}${level}${NORMAL}\n" > for service in ${runlevels[${!level}]} ; do > printf " %-${COLS}s" "${service}" > if [ $(in_list "${started}" "${service}") -eq 1 ] ; then > print_msg "${GOOD}" "started" > else > if [ -n "${failed}" ] && [ $(in_list "${failed}" "${service}") -eq 1 ] ; then > print_msg "${BAD}", "failed" > elif [ -n "${broken}" ] && [ $(in_list "${broken}" "${server}") -eq 1 ] ; then > print_msg "${BAD}", "broken" > else > print_msg "${WARN}" "off" > fi > fi > done > [ -n "${UNUSED}" ] && exit 0 >done
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 4222
:
1828
|
1829
|
1843
|
1855
|
2738
|
6847
|
8349
|
8350