Skip to content

Instantly share code, notes, and snippets.

@thomasdarimont
Created February 23, 2018 09:21
Show Gist options
  • Select an option

  • Save thomasdarimont/32e5cc8cc8eb0df2d2479b0b5573088a to your computer and use it in GitHub Desktop.

Select an option

Save thomasdarimont/32e5cc8cc8eb0df2d2479b0b5573088a to your computer and use it in GitHub Desktop.
Wait for HTTP Service to become available with timeout (bash)
timeout 40s /bin/bash -c "while ! httping -qc1 http://somehost:8080/app ; do sleep 1 ; done; echo OK" || echo TIMEOUT

If the service cannot be reached within 40s then TIMEOUT will be printed otherwise OK.

@geoand
Copy link
Copy Markdown

geoand commented Feb 23, 2018

Very cool!

If one instead wants to use curl to check the HTTP status code, then the git could be adapted to:

timeout 40s bash -c 'while [[ $(curl -s -o /dev/null -w %{http_code} http://somehost:8080/app) != 200 ]]; do sleep 1; done; echo OK' || echo TIMEOUT

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment