fi
); then
- if [ -n "$waitname" -a -n "$waittime" ]; then
- # Save basename.
- base=${waitname##*/}
- # Find pid.
- pid=$(pidofproc "$waitname" "$pidfile")
- [ -z "$pid" ] && pid=$(pidofproc "$base" "$pidfile")
- i=0
- while [ "$i" -lt "$waittime" ]; do
- i=$((i + 1))
- checkpid $pid && break
- sleep 1
- done
+ # wait for process (or pidfile) to be created
+ if [ "$waittime" -gt 0 ]; then
+ # waitname can be empty, as if pidfile is in use, it is not relevant
+ waitproc "$waittime" "$waitname" "$pidfile"
fi
log_success "$1 startup"
ok
return $exit_code
}
+# wait (in seconds) for process (or pidfile) to be created
+# example: waitproc 30 httpd /var/run/httpd.pid
+waitproc() {
+ local waittime=$1 procname=$2 pidfile=$3
+ local i=0 pid
+ local now=$(date +%s)
+ local maxtime=$(($now + $waittime))
+
+ if [ -z "$procname" -a -z "$pidfile" ]; then
+ msg_usage "waitproc: procname or pidfile must be specified"
+ return 2
+ fi
+
+ while [ "$(date +%s)" -lt "$maxtime" ]; do
+ pid=$(pidofproc "$procname" "$pidfile")
+ [ -n "$pid" ] && break
+
+ # start-stop-daemon uses same delay
+ usleep 20000
+ i=$(( i + 1 ))
+ done
+}
+
# A function to stop a program.
killproc() {
local notset killlevel base pid pidfile result delay=3 try