Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update entrypoint to wait for keycloak comming up #42

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
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
24 changes: 15 additions & 9 deletions collector/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ main() {
loadApiParameters
loadCollectorParameters
loadConfig
waitForDependency "mongo" 27017
waitForDependency "mongo:27017"
waitForDependency "$CYFACE_OAUTH_SITE"
startApi
}

Expand Down Expand Up @@ -190,12 +191,17 @@ loadConfig() {
}"
}

# Parameter 1: Name of the Docker Container of the dependency to wait for
# Parameter 2: Internal Docker port of the dependency to wait for
# Parameter 1: URL to the service to wait for
waitForDependency() {
local service="$1"
local port="$2"
echo && echo "Waiting for $service:$port to start..."
local URL="$1"

URL="https://auth.cyface.de:8443/realms/{tenant}"
HOST_PORT=$(awk -F/ '{print $3}' <<<"$URL")
HOST_PORT_ARRAY=($(echo "$HOST_PORT" | tr ":" "\n"))
local host=${HOST_PORT_ARRAY[0]}
local port=${HOST_PORT_ARRAY[1]}

echo && echo "Waiting for $host:$port to start..."

local attempts=0
local max_attempts=10
Expand All @@ -205,15 +211,15 @@ waitForDependency() {
((attempts++))
echo "Attempt $attempts"

if nc -z "$service" "$port" > /dev/null 2>&1; then
echo "$service is up!"
if nc -z "$host" "$port" > /dev/null 2>&1; then
echo "$host is up!"
return 0
else
sleep "$sleep_duration"
fi
done

echo "Unable to find $service:$port after $max_attempts attempts! API will not start."
echo "Unable to find $host:$port after $max_attempts attempts! API will not start."
exit 1
}

Expand Down
Loading