home *** CD-ROM | disk | FTP | other *** search
/ chilidog.highland.cc.ks.us / chilidog.highland.cc.ks.us.zip / chilidog.highland.cc.ks.us / backup / bradford.20120521.etc.tar.gz / bradford.20120521.etc.tar / etc / rc.status < prev    next >
Text File  |  2005-08-19  |  8KB  |  314 lines

  1. # /etc/rc.status
  2. # Definition of boot script return messages
  3. #
  4. #   The bootscripts should use the variables rc_done and rc_failed to
  5. #   report whether they failed or succeeded.  See /etc/init.d/skeleton for
  6. #   an example how the shell functions rc_status and rc_reset are used.
  7. #
  8. #   These functions make use of the variables rc_done and rc_failed;
  9. #   rc_done_up and rc_failed_up are the same as rc_done and rc_failed
  10. #   but contain a terminal code to move up one line before the output
  11. #   of the actual string. (This is particularly useful when the script
  12. #    starts a daemon which produces user output with a newline character)
  13. #
  14. #   The variable rc_reset is used by the master resource control script
  15. #   /etc/init.d/rc to turn off all attributes and switch to the standard
  16. #   character set.
  17. #
  18. #    \033          ascii ESCape
  19. #    \033[<NUM>G   move to column <NUM> (linux console, xterm, not vt100)
  20. #    \033[<NUM>C   move <NUM> columns forward but only upto last column
  21. #    \033[<NUM>D   move <NUM> columns backward but only upto first column
  22. #    \033[<NUM>A   move <NUM> rows up
  23. #    \033[<NUM>B   move <NUM> rows down
  24. #    \033[1m       switch on bold
  25. #    \033[31m      switch on red
  26. #    \033[32m      switch on green
  27. #    \033[33m      switch on yellow
  28. #    \033[m        switch off color/bold
  29. #    \017          exit alternate mode (xterm, vt100, linux console)
  30. #    \033[10m      exit alternate mode (linux console)
  31. #    \015          carriage return (without newline)
  32. #
  33.  
  34. # Do _not_ be fooled by non POSIX locale
  35. LC_ALL=POSIX
  36. export LC_ALL
  37.  
  38. # Seek for terminal size and, if needed, set default size
  39. if test -z "$LINES" -o -z "$COLUMNS" ; then
  40.     eval `exec 3<&1; stty size <&3 2>/dev/null | (read L C; \
  41.       echo LINES=${L:-24} COLUMNS=${C:-80})`
  42. fi
  43. test $LINES   -eq 0 && LINES=24
  44. test $COLUMNS -eq 0 && COLUMNS=80
  45. export LINES COLUMNS
  46.  
  47. # Make sure we have /sbin and /usr/sbin in PATH
  48. case ":$PATH:" in 
  49.     *:/sbin:*)
  50.     ;;
  51.     *)
  52.     PATH=/sbin:/usr/sbin:/usr/local/sbin:$PATH
  53.     export PATH
  54.     ;;
  55. esac
  56.  
  57. if test -t 1 -a "$TERM" != "raw" -a "$TERM" != "dumb" && stty size <&1 > /dev/null 2>&1 ; then
  58.      esc=`echo -en "\033"`
  59.         extd="${esc}[1m"
  60.         warn="${esc}[1;31m"
  61.         done="${esc}[1;32m"
  62.         attn="${esc}[1;33m"
  63.         norm=`echo -en "${esc}[m\017"`
  64.         stat=`echo -en "\015${esc}[${COLUMNS}C${esc}[10D"`
  65.  
  66.      rc_done="${stat}${done}done${norm}"
  67.   rc_running="${stat}${done}running${norm}"
  68.    rc_failed="${stat}${warn}failed${norm}"
  69.    rc_missed="${stat}${warn}missing${norm}"
  70.   rc_skipped="${stat}${attn}skipped${norm}"
  71.      rc_dead="${stat}${warn}dead${norm}"
  72.    rc_unused="${stat}${extd}unused${norm}"
  73.   rc_unknown="${stat}${attn}unknown${norm}"
  74.   rc_done_up="${esc}[1A${rc_done}"
  75. rc_failed_up="${esc}[1A${rc_failed}"
  76.     rc_reset="${norm}${esc}[?25h"
  77.      rc_save="${esc}7${esc}[?25l"
  78.   rc_restore="${esc}8${esc}[?25h"
  79.     function rc_cuu () { test $1 -eq 0 && return; echo -en "\033[${1}A"; }
  80.     function rc_cud () { test $1 -eq 0 && return; echo -en "\033[${1}B"; }
  81.     function rc_timer_on () {
  82.     # Draw seconds of running timout to column.
  83.     # Two arguments: timeout in seconds and offset
  84.     local n=$1
  85.     local c=$2
  86.     (trap "exit 0" TERM
  87.      while test $((n--)) -gt 0; do
  88.         sleep 1;
  89.         if test $n -gt 9 ; then
  90.         echo -en "\015${esc}[${c}C(${n}s) "
  91.         else
  92.         echo -en "\015${esc}[${c}C( ${n}s) "
  93.         fi
  94.     done) & _rc_timer_pid=$!
  95.     }
  96.     function rc_timer_off () {
  97.     if test -n "$_rc_timer_pid" ; then
  98.         kill -TERM $_rc_timer_pid > /dev/null 2>&1
  99.     fi
  100.     unset _rc_timer_pid
  101.     }
  102. else
  103.      esc=""
  104.         extd=""
  105.         warn=""
  106.         done=""
  107.         attn=""
  108.         norm=""
  109.         stat=""
  110.  
  111.      rc_done="..done"
  112.   rc_running="..running"
  113.    rc_failed="..failed"
  114.    rc_missed="..missing"
  115.   rc_skipped="..skipped"
  116.      rc_dead="..dead"
  117.    rc_unused="..unused"
  118.   rc_unknown="..unknown"
  119.   rc_done_up="${rc_done}"
  120. rc_failed_up="${rc_failed}"
  121.     rc_reset=""
  122.      rc_save=""
  123.   rc_restore=""
  124.     function rc_cuu () { return; }
  125.     function rc_cud () { return; }
  126.     function rc_timer_on  () { return; }
  127.     function rc_timer_off () { return; }
  128. fi
  129.  
  130. _rc_service=${0##*/[SK][0-9][0-9]}
  131. _rc_status=0
  132. _rc_status_all=0
  133. _rc_todo=$1
  134. function rc_check ()
  135. {
  136.     _rc_status_ret=$?
  137.     test $_rc_status_ret -eq 0 || _rc_status=$_rc_status_ret
  138.     test $_rc_status     -eq 0 || _rc_status_all=$_rc_status
  139.     return $_rc_check_ret
  140. }
  141. function rc_reset ()
  142. {
  143.     _rc_status=0
  144.     _rc_status_all=0
  145.     rc_check
  146.     return 0
  147. }
  148.  
  149. if   test "$_rc_todo" = "status" ; then
  150. function rc_status ()
  151. {
  152.     rc_check
  153.     _rc_status_ret=$_rc_status
  154.     local i
  155.     for i ; do
  156.     case "$i" in
  157.     -v|-v[1-9]|-v[1-9][0-9])
  158.         local vrt=""
  159.         local out=1
  160.         local opt="en"
  161.  
  162.         test -n "${i#-v}" && vrt="$vrt${esc}[${i#-v}A" || opt="e"
  163.         case "$_rc_status" in
  164.         0)    vrt="$vrt$rc_running";        ;; # service running
  165.         1)    vrt="$vrt$rc_dead"   ; out=2    ;; # service dead (but has pid file)
  166.         2)    vrt="$vrt$rc_dead"   ; out=2    ;; # service dead (but has lock file)
  167.         3)    vrt="$vrt$rc_unused" ;        ;; # service not running
  168.         4)    vrt="$vrt$rc_unknown";        ;; # status is unknown
  169.         esac
  170.         echo -$opt "$rc_save$vrt$rc_restore" 1>&$out
  171.  
  172.         # reset _rc_status to 0 after verbose case
  173.         _rc_status=0 ;;
  174.     -r) rc_reset ;;
  175.     -s) echo -e "$rc_skipped" ; rc_failed 3 ;;
  176.     -u) echo -e "$rc_unused"  ; rc_failed 3 ;;
  177.     *)  echo "rc_status: Usage: [-v[<num>] [-r]|-s|-u]" 1>&2 ; return 0 ;;
  178.     esac
  179.     done
  180.     return $_rc_status_ret
  181. }
  182. elif test -n "$_rc_todo" ; then
  183. function rc_status ()
  184. {
  185.     rc_check
  186.     test "$_rc_status" -gt 7 && rc_failed 1
  187.     _rc_status_ret=$_rc_status
  188.     case "$_rc_todo" in
  189.     stop)
  190.     # program is not running which
  191.     # is success if we stop service
  192.     test "$_rc_status" -eq 7 && rc_failed 0 ;;
  193.     esac
  194.     local i
  195.     for i ; do
  196.     case "$i" in
  197.     -v|-v[1-9]|-v[1-9][0-9])
  198.         local vrt=""
  199.         local out=1
  200.         local opt="en"
  201.  
  202.         test -n "${i#-v}" && vrt="$vrt${esc}[${i#-v}A" || opt="e"
  203.         case "$_rc_status" in
  204.         0)    vrt="$vrt$rc_done"   ;        ;; # success
  205.         1)    vrt="$vrt$rc_failed" ; out=2    ;; # generic or unspecified error
  206.         2)    vrt="$vrt$rc_failed" ; out=2    ;; # invalid or excess args
  207.         3)    vrt="$vrt$rc_missed" ; out=2    ;; # unimplemented feature
  208.         4)    vrt="$vrt$rc_failed" ; out=2    ;; # insufficient privilege
  209.         5)    vrt="$vrt$rc_skipped"; out=2    ;; # program is not installed
  210.         6)    vrt="$vrt$rc_unused" ; out=2    ;; # program is not configured
  211.         7)    vrt="$vrt$rc_failed" ; out=2    ;; # program is not running
  212.         *)    vrt="$vrt$rc_failed" ; out=2    ;; # unknown (maybe used in future)
  213.         esac
  214.         echo -$opt "$rc_save$vrt$rc_restore" 1>&$out
  215.  
  216.         # reset _rc_status to 0 after verbose case
  217.         _rc_status=0 ;;
  218.     -r) rc_reset ;;
  219.     -s) echo -e "$rc_skipped" 1>&2 ; rc_failed 5 ;;
  220.     -u) echo -e "$rc_unused"  1>&2 ; rc_failed 6 ;;
  221.     *)  echo "rc_status: Usage: [-v[<num>] [-r]|-s|-u]" 1>&2 ; return 0 ;;
  222.     esac
  223.     done
  224.     return $_rc_status_ret
  225. }
  226. else
  227. function rc_status ()
  228. {
  229.     rc_check
  230.     _rc_status_ret=$_rc_status
  231.     local i
  232.     for i ; do
  233.     case "$i" in
  234.     -v|-v[1-9]|-v[1-9][0-9])
  235.         local vrt=""
  236.         local out=1
  237.         local opt="en"
  238.  
  239.         test -n "${i#-v}" && vrt="$vrt${esc}[${i#-v}A" || opt="e"
  240.         case "$_rc_status" in
  241.         0)    vrt="$vrt$rc_done"  ;        ;; # success
  242.         *)    vrt="$vrt$rc_failed"; out=2    ;; # failed
  243.         esac
  244.         echo -$opt "$rc_save$vrt$rc_restore" 1>&$out
  245.  
  246.         # reset _rc_status to 0 after verbose case
  247.         _rc_status=0 ;;
  248.     -r) rc_reset ;;
  249.     -s) echo -e "$rc_skipped"  ; return 0 ;;
  250.     -u) echo -e "$rc_unused"   ; return 0 ;;
  251.     *)  echo "rc_status: Usage: [-v[<num>] [-r]|-s|-u]" 1>&2 ; return 0 ;;
  252.     esac
  253.     done
  254.     return $_rc_status_ret
  255. }
  256. fi
  257.  
  258. function rc_failed ()
  259. {
  260.     rc_reset
  261.     case "$1" in
  262.     [0-7]) _rc_status=$1 ;;
  263.     "")    _rc_status=1
  264.     esac
  265.     rc_check
  266.     return $_rc_status
  267. }
  268.  
  269. function rc_exit ()
  270. {
  271.     exit $_rc_status_all
  272. }
  273.  
  274. function rc_confirm()
  275. {
  276.     local timeout="30"
  277.     local answer=""
  278.     local ret=0
  279.  
  280.     case "$1" in
  281.     -t) timeout=$2; shift 2 ;;
  282.     esac
  283.     local message="$@, (Y)es/(N)o/(C)ontinue? [y] "
  284.     : ${REDIRECT:=/dev/tty}
  285.  
  286.     while true ; do
  287.     read -t ${timeout} -n 1 -p "${message}" answer < $REDIRECT > $REDIRECT 2>&1
  288.     case "$answer" in
  289.     [yY]|"") ret=0; break ;;
  290.     [nN])     ret=1; break ;;
  291.     [cC])     ret=2; break ;;
  292.     *)     echo; continue
  293.     esac
  294.     done
  295.     echo
  296.     return $ret
  297. }
  298.  
  299. function rc_active ()
  300. {
  301.     local x
  302.     for x in /etc/init.d/*.d/S[0-9][0-9]${1} ; do
  303.     test -e $x || break
  304.     return 0
  305.     done
  306.     return 1
  307. }
  308.  
  309. function rc_splash()
  310. {
  311.     return 0
  312. }
  313.  
  314.