Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 31 additions & 6 deletions scripts/install_foxx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,38 @@ fi

url="${local_DATABASE_API_SCHEME}://${local_DATAFED_DATABASE_HOST}:${local_DATABASE_PORT}/_api/database/user"
# Do not output to /dev/null we need the output
code=$(LD_LIBRARY_PATH="${DATAFED_DEPENDENCIES_INSTALL_PATH}:$LD_LIBRARY_PATH" curl ${local_CURL_SSL_ARG} -s -o /dev/null -w "%{http_code}" --user "$basic_auth" "$url")

if [[ "$code" != "200" ]]; then
echo "ERROR - Attempting to connect to database at $url"
echo " HTTP code is: $code"
exit 1
fi
max_retries=3
retry_delay=5

for attempt in $(seq 1 $max_retries); do
set +e
code=$(LD_LIBRARY_PATH="${DATAFED_DEPENDENCIES_INSTALL_PATH}:$LD_LIBRARY_PATH" \
curl ${local_CURL_SSL_ARG} -s -o /dev/null -w "%{http_code}" \
--user "$basic_auth" "$url")
error_code=$?
set -e

if [[ "$error_code" -eq 0 && "$code" -eq 200 ]]; then
Comment on lines +168 to +176
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Restoring 'set -e' after each attempt may not be necessary.

Toggling 'set -e' may cause errors to be missed between commands. Limit 'set +e' to the curl invocation or use a subshell for retries to avoid unintended side effects.

Suggested change
for attempt in $(seq 1 $max_retries); do
set +e
code=$(LD_LIBRARY_PATH="${DATAFED_DEPENDENCIES_INSTALL_PATH}:$LD_LIBRARY_PATH" \
curl ${local_CURL_SSL_ARG} -s -o /dev/null -w "%{http_code}" \
--user "$basic_auth" "$url")
error_code=$?
set -e
if [[ "$error_code" -eq 0 && "$code" -eq 200 ]]; then
for attempt in $(seq 1 $max_retries); do
# Run curl in a subshell with 'set +e' to avoid affecting global error handling
error_code_and_code=$(
set +e
code=$(LD_LIBRARY_PATH="${DATAFED_DEPENDENCIES_INSTALL_PATH}:$LD_LIBRARY_PATH" \
curl ${local_CURL_SSL_ARG} -s -o /dev/null -w "%{http_code}" \
--user "$basic_auth" "$url")
error_code=$?
echo "$error_code $code"
)
error_code=$(echo "$error_code_and_code" | awk '{print $1}')
code=$(echo "$error_code_and_code" | awk '{print $2}')
if [[ "$error_code" -eq 0 && "$code" -eq 200 ]]; then

echo "INFO - Attempting to connect to database at $url"
echo " HTTP code is: $code"
echo " Succeeded"
break
fi

if [[ "$attempt" -lt "$max_retries" ]]; then
echo "WARNING - Attempting to connect to database at $url"
echo " HTTP code is: $code"
echo " Failed"
echo " Retrying in ${retry_delay}s..."
sleep "$retry_delay"
else
echo "ERROR - Attempting to connect to database at $url"
echo " HTTP code is: $code"
echo " Failed after $max_retries"
exit 1
fi
done

url2="${local_DATABASE_API_SCHEME}://${local_DATAFED_DATABASE_HOST}:${local_DATABASE_PORT}/_api/database"
# We are now going to initialize the DataFed database in Arango, but only if sdms database does
Expand Down