SVN: rc-scripts/trunk/lib/functions
glen
glen at pld-linux.org
Wed Apr 3 10:51:25 CEST 2013
Author: glen
Date: Wed Apr 3 10:51:25 2013
New Revision: 12643
Modified:
rc-scripts/trunk/lib/functions
Log:
improve fedora compatibility:
add:
- daemon --pidfile=FOO
- killproc -d DELAY
use usleep 50000 instead of 100000, computers are bit faster now :)
Modified: rc-scripts/trunk/lib/functions
==============================================================================
--- rc-scripts/trunk/lib/functions (original)
+++ rc-scripts/trunk/lib/functions Wed Apr 3 10:51:25 2013
@@ -597,6 +597,10 @@
shift
waittime="$1"
;;
+ --pidfile=?*)
+ pidfile="${1#--pidfile=}"
+ case "$pidfile" in /*);; *) pidfile="/var/run/$pidfile";; esac
+ ;;
--pidfile)
shift
pidfile="$1"
@@ -716,15 +720,19 @@
# 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 @@
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 @@
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
More information about the pld-cvs-commit
mailing list