Go to:
Gentoo Home
Documentation
Forums
Lists
Bugs
Planet
Store
Wiki
Get Gentoo!
Gentoo's Bugzilla – Attachment 1828 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]
A script to provide summary information about the system RC status
rc-status (text/plain), 8.58 KB, created by
Sean E Russell
on 2002-06-26 23:06:10 UTC
(
hide
)
Description:
A script to provide summary information about the system RC status
Filename:
MIME Type:
Creator:
Sean E Russell
Created:
2002-06-26 23:06:10 UTC
Size:
8.58 KB
patch
obsolete
>#!/usr/bin/ruby >################################################################################ ># # ># Author: Sean E. Russell <ser@germane-software.com> # ># Version: 1.0 # ># Date: Jun 26, 2002 # ># # ># 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`.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]) >opts.each do |opt,arg| > case opt > when "--all" > ALL = true > when "--depend" > DEPEND = true > when '--unused' > ALL = true > UNUSED = true > when '--nocolors' > NOCOLORS = true > when '--list' > puts Dir.entries( '/etc/runlevels' ).delete_if(&filter).join("\n") > exit 0 > when '--help' > puts "USAGE: #$0 [--nocolors] [--all | --list | --unused | <runlevel>]" > puts " --all -a Show services at all run levels" > puts " --list -l Show list of run levels" > puts " --unused -u Show services not assigned to any run level" > puts " --nocolors -n Turn off colors" > puts " <runlevel> Show services assigned to <runlevel>" > puts "If no arguments are supplied, shows services for current run level." > exit 0 > end >end > > >################################################################################ ># # ># Define a bunch of terminal colors. If the user chose --nocolors, we simply # ># define the colors to be the empty string # ># # >################################################################################ >if defined? NOCOLORS > 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" >end > > >################################################################################ ># # ># Find the current runlever being queried. This is either something supplied # ># on the command line, or pulled from softlevel # ># # >################################################################################ >if ARGV.size > 0 > runlevel = ARGV[0] >else > runlevel = File.new( '/mnt/.init.d/softlevel').readline.strip >end > > >################################################################################ ># # ># 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. # ># # >################################################################################ >runlevels = {} # A hash ># For each directory in /etc/runlevels, do ... >Dir.entries( '/etc/runlevels' ).each do |level| > unless level =~ /^\..*/ # Filter out .* > if defined? ALL or level == runlevel > leveldir = File.join( '/etc/runlevels', level ) > runlevels[ level ] = Dir.entries( leveldir ).delete_if(&filter) > end > end >end ># 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. >if defined? ALL > unassigned = Dir.entries( '/etc/init.d' ).delete_if {|f| f =~ /(^\.)|(\.sh$)/} > # Filter out the unassigned > runlevels.each { | level, services | unassigned -= services } > # Load all init.d services > runlevels[ 'UNASSIGNED' ] = unassigned >end > > >################################################################################ ># # ># Now collect information about the status of the various services; whether # ># they're started, broken, or failed. Put all of this into arrays. # ># # >################################################################################ ># Read from /mnt/.init.d/started a list of currently running services >started = Dir.entries( '/mnt/.init.d/started' ).delete_if(&filter) ># Read from /mnt/.init.d/failed and /mnt/.init.d/broken a list of broken ># services. >failed = Dir.entries( '/mnt/.init.d/failed' ).delete_if(&filter) >broken = Dir.entries( '/mnt/.init.d/broken' ).delete_if(&filter) > > >################################################################################ ># # ># 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 ]' >def print_msg level, msg > printf "#{BLUE}[ #{level}%-7s #{BLUE}]#{NORMAL}\n", msg >end > ># Display the runlevel and services chart >runlevels.each do | level, services | > # level is-a String, services is-a Hash of Strings being the service names > next if defined? UNUSED and level != 'UNASSIGNED' > puts "Runlevel: #{HILITE}#{level}#{NORMAL}" > services.each do | service | > printf " %-#{COLS}s", service > if started.include? service > print_msg GOOD, 'started' > else > if failed.include? service > print_msg BAD, 'failed' > elsif broken.include? service > print_msg BAD, 'broken' > else > print_msg WARN, 'off' > end > end > end >end
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