[Groonga-commit] groonga/groonga at 1f68bab [master] groonga-httpd: implement wait_until_XXX without timeout command

Back to archive index

Kouhei Sutou null+****@clear*****
Thu Aug 22 11:43:22 JST 2013


Kouhei Sutou	2013-08-22 11:43:22 +0900 (Thu, 22 Aug 2013)

  New Revision: 1f68bab47db1efe224990703ea797d56379ea694
  https://github.com/groonga/groonga/commit/1f68bab47db1efe224990703ea797d56379ea694

  Message:
    groonga-httpd: implement wait_until_XXX without timeout command
    
    Because timeout command is not portable. For example, CentOS 5 doesn't
    install it by default.

  Modified files:
    data/scripts/groonga-httpd-restart

  Modified: data/scripts/groonga-httpd-restart (+14 -11)
===================================================================
--- data/scripts/groonga-httpd-restart    2013-08-21 11:36:04 +0900 (a8301bd)
+++ data/scripts/groonga-httpd-restart    2013-08-22 11:43:22 +0900 (5e45494)
@@ -19,12 +19,17 @@ elif [ -f /etc/init.d/functions ]; then
     fi
 fi
 
-wait_until_file_is_created () {
-    timeout $STATUS_TIMEOUT tail -F $1 --quiet 2> /dev/null | read 2> /dev/null
-}
-
-wait_until_process_is_finished () {
-    timeout $STATUS_TIMEOUT tail -F /dev/null --pid=$1
+wait_until () {
+    local rest=$STATUS_TIMEOUT
+    local duration=1
+    while [ $rest -ge 0 ]; do
+        if "$@"; then
+            return 0
+        fi
+        rest=$(($rest - $duration))
+        sleep $duration
+    done
+    return 1
 }
 
 if [ "$1" = "try-restart" ]; then
@@ -35,8 +40,7 @@ fi
 
 killproc -p $PIDFILE ${GROONGA_HTTPD} -USR2
 
-wait_until_file_is_created $OLD_PIDFILE
-if [ ! -f "$OLD_PIDFILE" ]; then
+if ! wait_until [ -f $OLD_PIDFILE ]; then
     echo "Failed to start new groonga-httpd master."
     exit 1
 fi
@@ -46,8 +50,7 @@ OLD_PID=`cat $OLD_PIDFILE`
 # Switch worker process.
 kill -WINCH `cat $OLD_PIDFILE`
 
-wait_until_file_is_created $PIDFILE
-if [ ! -f "$PIDFILE" ]; then
+if ! wait_until [ -f "$PIDFILE" ]; then
     echo "Failed to switch worker process."
     exit 2
 fi
@@ -55,7 +58,7 @@ PID=`cat $PIDFILE`
 
 OLD_WORKER_PROCESS=`pgrep -P $OLD_PID | grep -v $PID`
 for pid in $OLD_WORKER_PROCESS; do
-    wait_until_process_is_finished $pid
+    wait_until ps --pid=$pid > /dev/null
 done
 OLD_WORKER_PROCESS=`pgrep -P $OLD_PID | grep -v $PID`
 if [ -n "$OLD_WORKER_PROCESS" ]; then
-------------- next part --------------
HTML����������������������������...
Descargar 



More information about the Groonga-commit mailing list
Back to archive index