]> git.pld-linux.org Git - projects/rc-scripts.git/commitdiff
improve fedora compatibility:
authorElan Ruusamäe <glen@pld-linux.org>
Wed, 3 Apr 2013 08:51:25 +0000 (08:51 +0000)
committerElan Ruusamäe <glen@pld-linux.org>
Wed, 3 Apr 2013 08:51:25 +0000 (08:51 +0000)
add:
- daemon --pidfile=FOO
- killproc -d DELAY

use usleep 50000 instead of 100000, computers are bit faster now :)

svn-id: @12643

lib/functions

index e7debacc2e3c719890f7613efbc955720a9dc5b6..7b03a81cc8758f7d27e46142bd1534eded4e688a 100644 (file)
@@ -597,6 +597,10 @@ daemon() {
                        shift
                        waittime="$1"
                        ;;
+               --pidfile=?*)
+                       pidfile="${1#--pidfile=}"
+                       case "$pidfile" in /*);; *) pidfile="/var/run/$pidfile";; esac
+                       ;;
                --pidfile)
                        shift
                        pidfile="$1"
@@ -716,15 +720,19 @@ daemon() {
 
 # A function to stop a program.
 killproc() {
-       local notset killlevel base pid pidfile result
+       local notset killlevel base pid pidfile result delay=3 try
        # Test syntax.
        if [ $# = 0 ]; then
-               msg_usage " killproc [--pidfile PIDFILE] {program} [-SIGNAME]"
+               msg_usage " killproc [--pidfile|-p PIDFILE] [-d DELAY] {program} [-SIGNAME]"
                return 2
        fi
 
        while [ "$1" != "${1##-}" ]; do
                case $1 in
+               -d)
+                       delay="$2"
+                       shift 2
+                       ;;
                --pidfile|-p)
                        pidfile="$2"
                        case "$pidfile" in /*);; *) pidfile="/var/run/$pidfile";; esac
@@ -756,7 +764,7 @@ killproc() {
        if is_no "$RC_LOGGING" && [ "$pidfile" ]; then
                local sig=${killlevel:--TERM} retry
                # retry only if signal is not specified,
-               # as otherwise impossible to send HUP if process pid stays in pidfile.
+               # as otherwise impossible to send HUP if process pid stays in pidfile.
                if [ "${killlevel+set}" = "set" ]; then
                        # if we send HUP it's ok if process does not die
                        retry="--oknodo"
@@ -790,14 +798,19 @@ killproc() {
                        if checkpid $pid 2>&1; then
                                # TERM first, then KILL if not dead
                                kill -TERM $pid
-                               usleep 100000
-                               if checkpid $pid && sleep 1 &&
-                                       checkpid $pid && sleep 3 &&
-                                       checkpid $pid; then
+                               usleep 50000
+
+                               try=0
+                               while [ $try -lt $delay ]; do
+                                       checkpid $pid || break
+                                       sleep 1
+                                       try=$((try+1))
+                               done
+                               if checkpid $pid; then
                                        # XXX: SIGKILL is sent already on 4th second!
                                        # HARMFUL for example to mysqld (which is already workarounded)
                                        kill -KILL $pid
-                                       usleep 100000
+                                       usleep 50000
                                fi
                        fi
                        checkpid $pid
This page took 0.85174 seconds and 4 git commands to generate.