es_isready 484 Bytes
#!/bin/sh
set -ex

elasticsearch_timeout=${elasticsearch_timeout:-3}

check_es() {
	status="$(curl -o /dev/null -w "%{http_code}" --max-time ${elasticsearch_timeout} -XGET -g -s -k -u "${elasticsearch_user}:${elasticsearch_password}" "${elasticsearch_url}")"
	if [ "z$status" = z200 ]; then
		return 0
	fi
	return 1
}

while ! check_es; do
	echo "Waiting for Elasticsearch" 1>&2
	sleep 1
	count=5
	while [ $count -gt 0 ] && ! check_es; do
		count=$(($count - 1))
		sleep 1
	done
done