From 552a004d82a7bca25987549df08680493b96d194 Mon Sep 17 00:00:00 2001 From: Klemens Muthmann Date: Thu, 13 Jun 2024 11:38:23 +0200 Subject: [PATCH 1/2] Update entrypoint to wait for keycloak comming up --- collector/entrypoint.sh | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/collector/entrypoint.sh b/collector/entrypoint.sh index 25b8b01..31d18ff 100644 --- a/collector/entrypoint.sh +++ b/collector/entrypoint.sh @@ -33,7 +33,8 @@ main() { loadApiParameters loadCollectorParameters loadConfig - waitForDependency "mongo" 27017 + waitForDependency "mongo:27017" + waitForDependency "$CYFACE_OAUTH_SITE" startApi } @@ -193,9 +194,15 @@ 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 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 @@ -205,15 +212,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 } From ca695e1a02864d167e2efd9476c898e0da77c7bb Mon Sep 17 00:00:00 2001 From: Klemens Muthmann Date: Thu, 13 Jun 2024 11:41:50 +0200 Subject: [PATCH 2/2] Update documentation --- collector/entrypoint.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/collector/entrypoint.sh b/collector/entrypoint.sh index 31d18ff..6d8509e 100644 --- a/collector/entrypoint.sh +++ b/collector/entrypoint.sh @@ -191,8 +191,7 @@ 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 URL="$1"