Browse code

Merge "Make wait_for_service more robust by checking HTTP response"

Jenkins authored on 2016/06/28 06:43:58
Showing 1 changed files
... ...
@@ -381,12 +381,24 @@ CURL_GET="${CURL_GET:-curl -g}"
381 381
 
382 382
 # Wait for an HTTP server to start answering requests
383 383
 # wait_for_service timeout url
384
+#
385
+# If the service we want is behind a proxy, the proxy may be available
386
+# before the service. Compliant proxies will return a 503 in this case
387
+# Loop until we get something else.
388
+# Also check for the case where there is no proxy and the service just
389
+# hasn't started yet. curl returns 7 for Failed to connect to host.
384 390
 function wait_for_service {
385 391
     local timeout=$1
386 392
     local url=$2
393
+    local rval=0
387 394
     time_start "wait_for_service"
388
-    timeout $timeout sh -c "while ! $CURL_GET -k --noproxy '*' -s $url >/dev/null; do sleep 1; done"
395
+    timeout $timeout bash -x <<EOF || rval=$?
396
+        while [[ \$( ${CURL_GET} -k --noproxy '*' -s -o /dev/null -w '%{http_code}' ${url} ) == 503 || \$? -eq 7 ]]; do
397
+            sleep 1
398
+        done
399
+EOF
389 400
     time_stop "wait_for_service"
401
+    return $rval
390 402
 }
391 403
 
392 404