]> git.pld-linux.org Git - projects/rc-scripts.git/commitdiff
- formatting
authorankry <ankry@pld-linux.org>
Thu, 15 May 2003 22:39:08 +0000 (22:39 +0000)
committerankry <ankry@pld-linux.org>
Thu, 15 May 2003 22:39:08 +0000 (22:39 +0000)
- fixed second argument of "status"

svn-id: @1079

rc.d/init.d/functions

index c1376561c3cfe08df59f7d44d1232fd78a4fe56f..8eb16b00e6b7a586022947703ccc26e3c4967608 100644 (file)
@@ -1,13 +1,13 @@
 # functions    This file contains functions to be used by most or all
 #              shell scripts in the /etc/init.d directory.
 #
-# $Id: functions,v 1.75 2003/05/15 21:37:46 ankry Exp $
+# $Id: functions,v 1.76 2003/05/15 22:39:08 ankry Exp $
 #
 # Author:      Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>
-# Hacked by:    Greg Galloway and Marc Ewing
+# Hacked by:   Greg Galloway and Marc Ewing
 # Modified for PLD by:
 #              Marek Obuchowicz <elephant@pld.org.pl>
-#              Arkadiusz Mi¶kiewicz <misiek@pld.org.pl> 
+#              Arkadiusz Mi¶kiewicz <misiek@pld.org.pl>
 #              Micha³ Kochanowicz <mkochano@pld.org.pl>
 
 # First set up a default search path.
@@ -22,42 +22,42 @@ INIT_COL=67
 [ -z "$COLUMNS" ] && COLUMNS=80
 
 # Colors workaround
-termput() 
+termput()
 {
        if [ ! -d /usr/share/terminfo ] || \
-            [ ! -x /usr/bin/tput -a ! -x /bin/tput ]; then
+          [ ! -x /usr/bin/tput -a ! -x /bin/tput ]; then
                case "$1" in
                  hpa)
-                       echo -ne "\033[$(($2+1))G"
+                       echo -ne "\033[$(($2+1))G"
                        ;;
                  cuu*)
-                       echo -ne "\033[${2}A"
+                       echo -ne "\033[${2}A"
                        ;;
                  el)
-                       echo -ne "\033[0K"
+                       echo -ne "\033[0K"
                        ;;
                  setaf)
-                       is_yes "$COLOR_INIT" && echo -ne "\033[0;3${2}m"
-                       ;;
+                       is_yes "$COLOR_INIT" && echo -ne "\033[0;3${2}m"
+                       ;;
                  op)
-                       termput setaf 9
+                       termput setaf 9
                        ;;
-                 esac
+               esac
        else
                # check if we are on proper terminal
                tput longname > /dev/null 2>&1 || return
 
-               case "$1" in
+               case "$1" in
                  hpa | cuu* | el)
-                       tput "$@"
+                       tput "$@"
                        ;;
                  setaf)
-                       is_yes "$COLOR_INIT" && tput "$@"
+                       is_yes "$COLOR_INIT" && tput "$@"
                        ;;
                  op)
-                       tput setaf 9
+                       tput setaf 9
                        ;;
-                esac
+               esac
        fi
 }
 
@@ -69,7 +69,7 @@ printf_()
        shift ;
        if [ $# -gt 0 ]; then
                m="$1";
-               shift;
+               shift;
                while [ $# -gt 0 ]; do
                        m="$m\",\"$1" ;
                        shift ;
@@ -77,7 +77,7 @@ printf_()
        fi
        awk "BEGIN {printf \"$text\", \"$m\"; }"
 }
-                           
+
 # National language support function
 nls()
 {
@@ -88,15 +88,15 @@ nls()
        # don't use -o instead || here - this will break ksh --misiek
        while [ "$1" != "${1##-}" ] || [ "$1" != "${1##+}" ]; do
                case "$1" in
-                       --nls-domain)
-                               shift
-                               NLS_DOMAIN="$1"
-                               shift
-                               ;;
-                       -n)
-                               msg_echo=''
-                               shift
-                               ;;
+                 --nls-domain)
+                       shift
+                       NLS_DOMAIN="$1"
+                       shift
+                       ;;
+                 -n)
+                       msg_echo=''
+                       shift
+                       ;;
                esac
        done
        message="$1"
@@ -107,14 +107,14 @@ nls()
                echo -en "$msg_echo"
                return
        fi
-                       
+
        if [ -x /bin/gettext -o -x /usr/bin/gettext ]; then
                text=$(TEXTDOMAINDIR="/etc/sysconfig/locale" gettext -e --domain="${NLS_DOMAIN:-rc-scripts}" "$message")
                printf_ "$text" "$@"
        else
                printf_ "$message" "$@"
        fi
-       
+
        echo -en "$msg_echo"
        NLS_DOMAIN="$old_nls_domain"
 }
@@ -155,8 +155,8 @@ msg_usage()
 }
 
 # Some functions to handle PLD-style messages
-show() 
-{      
+show()
+{
        typeset text
        text=$(nls "$@")
        echo -n "$text"
@@ -175,12 +175,12 @@ progress()
        echo -n "$(termput setaf 6)[$(termput setaf "$COLOR") $(nls --nls-domain rc-scripts "$1") $(termput setaf 6)]$(termput op)"
 }
 
-busy() 
+busy()
 {
        progress "BUSY" 5
 }
 
-ok() 
+ok()
 {
        progress "DONE"
        echo
@@ -192,21 +192,21 @@ started()
        echo
 }
 
-fail() 
+fail()
 {
        progress "FAIL" 1
        echo
        return 1
 }
 
-died() 
+died()
 {
        progress "DIED" 1
        echo
        return 1
 }
 
-deltext() 
+deltext()
 {
        termput hpa $INIT_COL
 }
@@ -214,11 +214,11 @@ deltext()
 # Check if $pid (could be plural) are running
 checkpid()
 {
-    while [ "$1" ]; do
-       [ -d "/proc/$1" ] && return 0
-       shift
-    done
-    return 1
+       while [ "$1" ]; do
+               [ -d "/proc/$1" ] && return 0
+               shift
+       done
+       return 1
 }
 
 # Usage run_cmd Message command_to_run
@@ -228,10 +228,10 @@ run_cmd()
        typeset -i force_err=0
        typeset -i exit_code=0
        case "$1" in
-               -a)
-                       force_err=1
-                       shift
-                       ;;
+         -a)
+               force_err=1
+               shift
+               ;;
        esac
        message=$1
        show "$message"; busy
@@ -249,7 +249,7 @@ run_cmd()
 }
 
 # A function to start a program (now it's usefull on read-only filesystem too)
-daemon() 
+daemon()
 {
        typeset errors="" prog=""
        typeset -i exit_code=0
@@ -257,21 +257,22 @@ daemon()
        # Test syntax. Don't use -o instead || here - this will broke ksh --misiek
        while [ "$1" != "${1##-}" ] || [ "$1" != "${1##+}" ]; do
                case $1 in
-               '')     msg_usage " daemon [--user user] [+/-nicelevel] {program}"
-                       return 1
+                 '')
+                       msg_usage " daemon [--user user] [+/-nicelevel] {program}"
+                       return 2
                        ;;
-               --check)
+                 --check)
                        # for compatibility with redhat/mandrake
                        nls "warning: --check option is ignored!"
                        shift
                        shift
                        ;;
-               --user)
+                 --user)
                        shift
                        [ "$1" != "root" ] && prog="/bin/su $1 -c \""
                        shift
                        ;;
-               -*|+*) SERVICE_RUN_NICE_LEVEL=$1
+                 -*|+*) SERVICE_RUN_NICE_LEVEL=$1
                        shift;;
                esac
        done
@@ -313,7 +314,7 @@ daemon()
 }
 
 # A function to stop a program.
-killproc() 
+killproc()
 {
        typeset notset killlevel base pid result
        # Test syntax.
@@ -323,7 +324,7 @@ killproc()
        fi
 
        busy
-       
+
        typeset -i notset=0
        # check for second arg to be kill level
        if [ -n "$2" ] ; then
@@ -398,72 +399,81 @@ killproc()
 }
 
 # A function to find the pid of a program.
-pidofproc() 
+pidofproc()
 {
-    typeset pid base
-    base=$(basename "$1")
+       typeset pid base
+       base=$(basename "$1")
 
-    # Test syntax.
-    if [ $# = 0 ] ; then
-       msg_usage " pidofproc {program}"
-       return 1
-    fi
-    
-    # First try "/var/run/*.pid" files
-    if [ -f /var/run/${base}.pid ] ; then
-       typeset line p pid
-       pid=
-       read line < /var/run/${base}.pid
-       for p in $line; do
-           [ -z "$(echo "$p" | awk ' { gsub(/[0-9]/,""); print $0; } ' )" ] && pid="$pid $p"
-       done
-       if [ -n "$pid" ]; then
-           echo $pid
-           return 0
+       # Test syntax.
+       if [ $# = 0 ] ; then
+               msg_usage " pidofproc {program}"
+               return 2
+       fi
+
+       # First try "/var/run/*.pid" files
+       if [ -f /var/run/${base}.pid ] ; then
+               typeset line p pid
+               pid=
+               read line < /var/run/${base}.pid
+               for p in $line; do
+                       [ -z "$(echo "$p" | awk '{gsub(/[0-9]/,""); print $0;}')" ] && pid="$pid $p"
+               done
+               if [ -n "$pid" ]; then
+                       echo $pid
+                       return 0
+               fi
        fi
-    fi
-    
+
        # Next try "pidof"
-    pidof -o $$ -o $PPID -o %PPID -x "$1" || \
-       pidof -o $$ -o $PPID -o %PPID -x "${base}"
+       pidof -o $$ -o $PPID -o %PPID -x "$1"
 }
 
-status() 
+status()
 {
-    typeset base pid
-    base=$(basename "$1")
-
-    # Test syntax.
-    if [ $# = 0 ] ; then
-       msg_usage " status {subsys} [{daemon}]"
-       return 1
-    fi
+       typeset base pid subsys daemon
+       subsys=$1
+       daemon=${2:-$subsys}
+       base=$(basename $daemon)
 
-    # First try "pidof"
-    pid=$(pidof -o $$ -o $PPID -o %PPID -x $1 || \
-       pidof -o $$ -o $PPID -o %PPID -x ${base})
+       # Test syntax.
+       if [ $# = 0 ] ; then
+               msg_usage " status {subsys} [{daemon}]"
+               return 2
+       fi
 
-    if [ "$pid" != "" ]; then
-       nls "%s (pid %s) is running..." "$base" "$pid"
-       return 0
-    fi
+       # First try "pidof"
+       pid=$(pidof -o $$ -o $PPID -o %PPID -x $daemon)
 
-    # Next try "/var/run/*.pid" files
-    if [ -f /var/run/${base}.pid ]; then
-       read pid < /var/run/${base}.pid
        if [ "$pid" != "" ]; then
-           nls "%s dead but pid file exists" "$base"
-           return 1
+               nls "%s (pid %s) is running..." "$daemon" "$pid"
+               return 0
+#      else
+#              pid=`ps ax | awk 'BEGIN { prog=ARGV[1]; ARGC=1 }
+#                   { if ((prog == $5) || (("(" prog ")") == $5) ||
+#                        (("[" prog "]") == $5) ||
+#                        ((prog ":") == $5)) { print $1 ; exit 0 } }' $1`
+#              if [ "$pid" != "" ]; then
+#                      nls "%s (pid %s) is running..." "$daemon" "$pid"
+#                      return 0
+#              fi
+       fi
+
+       # Next try "/var/run/*.pid" files
+       if [ -f /var/run/${base}.pid ]; then
+               read pid < /var/run/${base}.pid
+               if [ "$pid" != "" ]; then
+                       nls "%s dead but pid file exists" "$subsys"
+                       return 1
+               fi
+       fi
+
+       # See if /var/lock/subsys/$subsys exists
+       if [ -f /var/lock/subsys/$subsys ]; then
+               nls "%s dead but subsys locked" "$subsys"
+               return 2
        fi
-    fi
-
-    # See if /var/lock/subsys/$subsys exists
-    if [ -f /var/lock/subsys/$subsys ]; then
-       nls "%s dead but subsys locked" "$base"
-       return 2
-    fi
-    nls "%s is stopped" "$base"
-    return 3
+       nls "%s is stopped" "$subsys"
+       return 3
 }
 
 # Confirm whether we really want to run this service
@@ -472,25 +482,25 @@ confirm() {
        nls -n "Start service %s (Y)es/(N)o/(C)ontinue? [Y] " "$1"
        read answer
        case $answer in
-               y|Y|t|T|j|J|"")
-                       return 0
+         y|Y|t|T|j|J|"")
+               return 0
                ;;
-               c|C|k|K|w|W)
-                       return 2
+         c|C|k|K|w|W)
+               return 2
                ;;
-               n|N)
-                       return 1
+         n|N)
+               return 1
                ;;
-               *)
-                       confirm $1
-                       return $?
+         *)
+               confirm $1
+               return $?
                ;;
        esac
 }
 
 is_yes()
 {
-       # Test syntax   
+       # Test syntax
        if [ $# = 0 ] ; then
                msg_usage " is_yes {value}"
                return 2
@@ -498,13 +508,13 @@ is_yes()
 
        # Check value
        case "$1" in
-               yes|Yes|YES|true|True|TRUE|on|On|ON|Y|y|1)
-                       # true returns zero
-                       return 0
+         yes|Yes|YES|true|True|TRUE|on|On|ON|Y|y|1)
+               # true returns zero
+               return 0
                ;;
-               *)
-                       # false returns one
-                       return 1
+         *)
+               # false returns one
+               return 1
                ;;
        esac
 }
@@ -518,13 +528,13 @@ is_no()
        fi
 
        case "$1" in
-               no|No|NO|false|False|FALSE|off|Off|OFF|N|n|0)
-                       # true returns zero
-                       return 0
-                       ;;
-               *)
-                       # false returns one
-                       return 1
+         no|No|NO|false|False|FALSE|off|Off|OFF|N|n|0)
+               # true returns zero
+               return 0
+               ;;
+         *)
+               # false returns one
+               return 1
                ;;
        esac
 }
@@ -549,21 +559,21 @@ _modprobe()
        parsed=no
        while is_no "$parsed" ; do
                case "$1" in
-                       "single")
-                               single=yes
-                               shift
-                               ;;
-                       "die")
-                               die=yes
-                               shift
-                               ;;
-                       -*)
-                               args="$args $1"
-                               shift
-                               ;;
-                       *)
-                               parsed=yes
-                               ;;
+                 "single")
+                       single=yes
+                       shift
+                       ;;
+                 "die")
+                       die=yes
+                       shift
+                       ;;
+                 -*)
+                       args="$args $1"
+                       shift
+                       ;;
+                 *)
+                       parsed=yes
+                       ;;
                esac
        done
        if is_yes "${single}" ; then
@@ -607,7 +617,7 @@ action () { STRING=$1; shift; run_cmd "$STRING" "$*"; }
 success () { return 0; }
 failure () { return 1; }
 
-# TO BE REMOVED SOON. --misiek
+# TO BE REMOVED IN AC. --ankry
 msg_Network_Down () { msg_network_down "$*"; }
 msg_Already_Running () { msg_already_running "$*"; }
 msg_Not_Running () { msg_not_running "$*"; }
This page took 0.324003 seconds and 4 git commands to generate.