aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBill Nottingham <notting@redhat.com>2001-01-30 22:01:02 +0000
committerBill Nottingham <notting@redhat.com>2001-01-30 22:01:02 +0000
commit04eaa435505a3cb383ca218c8e67ed6e0306c807 (patch)
tree39448c7fd708acc7751d9e6375b5f29b74c32450
parent1c244e7f6723d46d5ddd01bfd14bae1a5b933370 (diff)
downloadinitscripts-04eaa435505a3cb383ca218c8e67ed6e0306c807.tar
initscripts-04eaa435505a3cb383ca218c8e67ed6e0306c807.tar.gz
initscripts-04eaa435505a3cb383ca218c8e67ed6e0306c807.tar.bz2
initscripts-04eaa435505a3cb383ca218c8e67ed6e0306c807.tar.xz
initscripts-04eaa435505a3cb383ca218c8e67ed6e0306c807.zip
various cleanups (#10761, from mjt@tls.msk.ru)r5-59
-rwxr-xr-xrc.d/init.d/functions126
1 files changed, 65 insertions, 61 deletions
diff --git a/rc.d/init.d/functions b/rc.d/init.d/functions
index 24e99948..548b7f0c 100755
--- a/rc.d/init.d/functions
+++ b/rc.d/init.d/functions
@@ -72,42 +72,48 @@ checkpid() {
# A function to start a program.
daemon() {
# Test syntax.
- gotbase=
- user=
+ local gotbase=
+ local base= user= nice= bg= pid
nicelevel=0
- while [ "$1" != "${1##-}" -o "$1" != "${1##+}" ]; do
+ while [ "$1" != "${1##[-+]}" ]; do
case $1 in
'') echo $"$0: Usage: daemon [+/-nicelevel] {program}"
return 1;;
--check)
- shift
- base=$1
+ base=$2
gotbase="yes"
+ shift 2
+ ;;
+ --check=?*)
+ base=${1#--user=}
shift
;;
--user)
- shift
- daemon_user=$1
+ user=$2
+ shift 2
+ ;;
+ --user=?*)
+ user=${1#--user=}
+ shift
+ ;;
+ --bg|--background)
+ bg=''&''
shift
;;
- -*|+*) nicelevel=$1
+ [-+][0-9]*)
+ nice="nice -n $1"
shift
;;
- *) nicelevel=0
- ;;
+ *) echo $"$0: Usage: daemon [+/-nicelevel] {program}"
+ return 1;;
esac
done
# Save basename.
- [ -z $gotbase ] && base=`basename $1`
+ [ -z $gotbase ] && base=${1##*/}
# See if it's already running. Look *only* at the pid file.
- pidlist=`pidfileofproc $1`
-
- pid=
- for apid in $pidlist ; do
- [ -d /proc/$apid ] && pid="$pid $apid"
- done
+ pidlist=`pidfileofproc $base`
[ -n "$pid" ] && return
@@ -119,11 +125,12 @@ daemon() {
[ "$BOOTUP" = "verbose" ] && echo -n " $base"
# And start it up.
- if [ -z "$daemon_user" ]; then
- nice -n $nicelevel initlog $INITLOG_ARGS -c "$*" && success $"$base startup" || failure $"$base startup"
+ if [ -z "$user" ]; then
+ $nice initlog $INITLOG_ARGS -c "$*$bg"
else
- nice -n $nicelevel initlog $INITLOG_ARGS -c "su $daemon_user -c \"$*\"" && success $"$base startup" || failure $"$base startup"
+ $nice initlog $INITLOG_ARGS -c "su $user -c \"$*$bg\"" && success $"$base startup" || failure $"$base startup"
fi
+ [ $? = 0 ] && success $"$base startup" || failure $"$base startup"
}
# A function to stop a program.
@@ -145,36 +152,27 @@ killproc() {
fi
# Save basename.
- base=`basename $1`
+ base=${1##*/}
# Find pid.
- pidlist=`pidofproc $1`
-
- pid=
- for apid in $pidlist ; do
- [ -d /proc/$apid ] && pid="$pid $apid"
- done
+ pid=`pidofproc $base`
# Kill it.
- if [ "$pid" != "" ] ; then
+ if [ -n "$pid" ] ; then
[ $BOOTUP = "verbose" ] && echo -n "$base "
if [ "$notset" = "1" ] ; then
if checkpid $pid 2>&1; then
# TERM first, then KILL if not dead
kill -TERM $pid
usleep 100000
- if checkpid $pid >/dev/null 2>&1 ; then
- sleep 1
- if checkpid $pid >/dev/null 2>&1 ; then
- sleep 3
- if checkpid $pid >/dev/null 2>&1 ; then
- kill -KILL $pid
- usleep 100000
- fi
- fi
+ if checkpid $pid && sleep 1 &&
+ checkpid $pid && sleep 3 &&
+ checkpid $pid ; then
+ kill -KILL $pid
+ usleep 100000
fi
fi
- checkpid $pid >/dev/null 2>&1
+ checkpid $pid
RC=$?
[ $RC -eq 0 ] && failure $"$base shutdown" || success $"$base shutdown"
RC=$((! $RC))
@@ -199,7 +197,8 @@ killproc() {
# A function to find the pid of a program. Looks *only* at the pidfile
pidfileofproc() {
- base=`basename $1`
+ local base=${1##*/}
+ local pid
# Test syntax.
if [ $# = 0 ] ; then
@@ -209,8 +208,11 @@ pidfileofproc() {
# First try "/var/run/*.pid" files
if [ -f /var/run/${base}.pid ] ; then
- pid=`cat /var/run/${base}.pid | { read foo ; echo $foo ; }`
- if [ "$pid" != "" ] ; then
+ read pid < /var/run/${base}.pid
+ for p in $line ; do
+ [ -z "$p##[0-9]}" -a -d /proc/$p ] && pid="$pid $p"
+ done
+ if [ -n "$pid" ] ; then
echo $pid
return 0
fi
@@ -219,7 +221,7 @@ pidfileofproc() {
# A function to find the pid of a program.
pidofproc() {
- base=`basename $1`
+ base=${1##*/}
# Test syntax.
if [ $# = 0 ] ; then
@@ -229,23 +231,24 @@ pidofproc() {
# First try "/var/run/*.pid" files
if [ -f /var/run/${base}.pid ] ; then
- pid=`cat /var/run/${base}.pid | { read foo ; echo $foo ; }`
- if [ "$pid" != "" ] ; then
+ local line p pid=
+ read line < /var/run/${base}.pid
+ for p in $line ; do
+ [ -z "$p##[0-9]}" -a -d /proc/$p ] && pid="$pid $p"
+ done
+ if [ -n "$pid" ] ; then
echo $pid
return 0
fi
fi
# Next try "pidof"
- pid=`pidof -o $$ -o $PPID -o %PPID -x ${base}`
- if [ "$pid" != "" ] ; then
- echo $pid
- return 0
- fi
+ pidof -o $$ -o $PPID -o %PPID -x ${base}
}
status() {
- base=`basename $1`
+ local base=${1##*/}
+ local pid
# Test syntax.
if [ $# = 0 ] ; then
@@ -262,7 +265,7 @@ status() {
# Next try "/var/run/*.pid" files
if [ -f /var/run/${base}.pid ] ; then
- pid=`cat /var/run/${base}.pid | { read foo ; echo $foo ; }`
+ read pid < /var/run/${base}.pid
if [ "$pid" != "" ] ; then
echo $"${base} dead but pid file exists"
return 1
@@ -377,14 +380,15 @@ confirm() {
local NO=$"nN"
local CONT=$"cC"
- echo -n $"Start service $1 (Y)es/(N)o/(C)ontinue? [Y] "
- read answer
- if strstr "$YES" "$answer" || [ "$answer" = "" ] ; then
- return 0
- elif strstr "$CONT" "$answer" ; then
- return 2
- elif strstr "$NO" "$answer" ; then
- return 1
- fi
- confirm $*
+ while : ; do
+ echo -n $"Start service $1 (Y)es/(N)o/(C)ontinue? [Y] "
+ read answer
+ if strstr "$YES" "$answer" || [ "$answer" = "" ] ; then
+ return 0
+ elif strstr "$CONT" "$answer" ; then
+ return 2
+ elif strstr "$NO" "$answer" ; then
+ return 1
+ fi
+ done
}