[Groonga-commit] groonga/groonga [master] rpm deb: change the way to check the existence of pid file/worker process

Back to archive index

HAYASHI Kentaro null+****@clear*****
Fri Sep 7 16:44:15 JST 2012


HAYASHI Kentaro	2012-09-07 16:44:15 +0900 (Fri, 07 Sep 2012)

  New Revision: 97817a0d4b67d1ccc1308beee5421bdd6211995f
  https://github.com/groonga/groonga/commit/97817a0d4b67d1ccc1308beee5421bdd6211995f

  Log:
    rpm deb: change the way to check the existence of pid file/worker process

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

  Modified: data/scripts/groonga-httpd-restart (+17 -3)
===================================================================
--- data/scripts/groonga-httpd-restart    2012-09-07 15:35:22 +0900 (08edaf9)
+++ data/scripts/groonga-httpd-restart    2012-09-07 16:44:15 +0900 (3bfb3ae)
@@ -12,9 +12,17 @@ elif [ -f /etc/init.d/functions ]; then
     . /etc/init.d/functions
 fi
 
+until_file_is_created () {
+	timeout $TIMEOUT tail -F $1 --quiet 2> /dev/null | read 2> /dev/null
+}
+
+until_process_is_finished () {
+	timeout $TIMEOUT tail -F /dev/null --pid=$1
+}
+
 killproc -p $PIDFILE ${GROONGA_HTTPD} -USR2
 
-[ ! -f "$OLD_PIDFILE" ] && sleep $TIMEOUT
+until_file_is_created $OLD_PIDFILE
 if [ ! -f "$OLD_PIDFILE" ]; then
 	echo "Failed to start new groonga-httpd master."
 	exit 1
@@ -25,11 +33,17 @@ OLD_PID=`cat $OLD_PIDFILE`
 # Switch worker process.
 kill -WINCH `cat $OLD_PIDFILE`
 
-[ ! -f "$PIDFILE" ] && sleep $TIMEOUT
+until_file_is_created $PIDFILE
+if [ ! -f "$PIDFILE" ]; then
+	echo "Failed to switch worker process."
+	exit 2
+fi
 PID=`cat $PIDFILE`
 
 OLD_WORKER_PROCESS=`pgrep -P $OLD_PID | grep -v $PID`
-[ -n "$OLD_WORKER_PROCESS" ] && sleep $TIMEOUT
+for pid in $OLD_WORKER_PROCESS; do
+    until_process_is_finished $pid
+done
 OLD_WORKER_PROCESS=`pgrep -P $OLD_PID | grep -v $PID`
 if [ -n "$OLD_WORKER_PROCESS" ]; then
 	echo "Failed to stop old groonga-httpd worker process."
-------------- next part --------------
HTML����������������������������...
下载 



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