Skip to content

Instantly share code, notes, and snippets.

@ramhoj
Created March 30, 2021 06:39
Show Gist options
  • Save ramhoj/2190cf3ce4af2cdbbb30f88a879ddce7 to your computer and use it in GitHub Desktop.
Save ramhoj/2190cf3ce4af2cdbbb30f88a879ddce7 to your computer and use it in GitHub Desktop.
wait_for_elasticsearch.sh
#!/usr/bin/env bash
# Credit: https://stackoverflow.com/a/59795634/1686364
host="localhost:9200"
response=""
attempt=0
until [ "$response" = "200" ]; do
if [ $attempt -ge 25 ]; then
echo "FAILED. Elasticsearch not responding after $attempt tries."
exit 1
fi
echo "Contacting Elasticsearch on ${host}. Try number ${attempt}"
response=$(curl --write-out %{http_code} --silent --output /dev/null "$host")
sleep 1
attempt=$[$attempt+1]
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment