feat: Log setup error in case of failed curl command
This commit is contained in:
parent
f7204daaee
commit
f93dfe007e
|
@ -33,14 +33,36 @@ roles_files=(
|
||||||
|
|
||||||
echo "-------- $(date) --------"
|
echo "-------- $(date) --------"
|
||||||
|
|
||||||
state_file="$(dirname ${BASH_SOURCE[0]})/state/.done"
|
state_file="$(dirname "${BASH_SOURCE[0]}")/state/.done"
|
||||||
if [[ -e "$state_file" ]]; then
|
if [[ -e "$state_file" ]]; then
|
||||||
log "State file exists at '${state_file}', skipping setup"
|
log "State file exists at '${state_file}', skipping setup"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
log 'Waiting for availability of Elasticsearch'
|
log 'Waiting for availability of Elasticsearch. This can take several minutes.'
|
||||||
wait_for_elasticsearch
|
|
||||||
|
declare -i exit_code=0
|
||||||
|
wait_for_elasticsearch || exit_code=$?
|
||||||
|
|
||||||
|
if ((exit_code)); then
|
||||||
|
case $exit_code in
|
||||||
|
6)
|
||||||
|
suberr 'Could not resolve host. Is Elasticsearch running?'
|
||||||
|
;;
|
||||||
|
7)
|
||||||
|
suberr 'Failed to connect to host. Is Elasticsearch healthy?'
|
||||||
|
;;
|
||||||
|
28)
|
||||||
|
suberr 'Timeout connecting to host. Is Elasticsearch healthy?'
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
suberr "Connection to Elasticsearch failed. Exit code: ${exit_code}"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
exit $exit_code
|
||||||
|
fi
|
||||||
|
|
||||||
sublog 'Elasticsearch is running'
|
sublog 'Elasticsearch is running'
|
||||||
|
|
||||||
for role in "${!roles_files[@]}"; do
|
for role in "${!roles_files[@]}"; do
|
||||||
|
|
|
@ -15,6 +15,11 @@ function err {
|
||||||
echo "[x] $1" >&2
|
echo "[x] $1" >&2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Log an error at a sub-level.
|
||||||
|
function suberr {
|
||||||
|
echo " ⠍ $1" >&2
|
||||||
|
}
|
||||||
|
|
||||||
# Poll the 'elasticsearch' service until it responds with HTTP code 200.
|
# Poll the 'elasticsearch' service until it responds with HTTP code 200.
|
||||||
function wait_for_elasticsearch {
|
function wait_for_elasticsearch {
|
||||||
local elasticsearch_host="${ELASTICSEARCH_HOST:-elasticsearch}"
|
local elasticsearch_host="${ELASTICSEARCH_HOST:-elasticsearch}"
|
||||||
|
@ -30,7 +35,13 @@ function wait_for_elasticsearch {
|
||||||
|
|
||||||
# retry for max 300s (60*5s)
|
# retry for max 300s (60*5s)
|
||||||
for _ in $(seq 1 60); do
|
for _ in $(seq 1 60); do
|
||||||
output="$(curl "${args[@]}" || true)"
|
local -i exit_code=0
|
||||||
|
output="$(curl "${args[@]}")" || exit_code=$?
|
||||||
|
|
||||||
|
if ((exit_code)); then
|
||||||
|
result=$exit_code
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ "${output: -3}" -eq 200 ]]; then
|
if [[ "${output: -3}" -eq 200 ]]; then
|
||||||
result=0
|
result=0
|
||||||
break
|
break
|
||||||
|
@ -39,7 +50,7 @@ function wait_for_elasticsearch {
|
||||||
sleep 5
|
sleep 5
|
||||||
done
|
done
|
||||||
|
|
||||||
if ((result)); then
|
if ((result)) && [[ "${output: -3}" -ne 000 ]]; then
|
||||||
echo -e "\n${output::-3}"
|
echo -e "\n${output::-3}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue