#!/bin/bash

if [ -x "$(command -v 'wait-for-it')" ];then
    if [ ! -z "${POSTGRES_HOSTPORT}" ];then
        echo "Waiting for postgres at ${POSTGRES_HOSTPORT}..."
        wait-for-it -t 60 "${POSTGRES_HOSTPORT}" && echo "postgres is up"
    fi

    if [ ! -z "${RABBITMQ_HOSTPORT}" ];then
        echo "Waiting for rabbitmq at ${RABBITMQ_HOSTPORT}..."
        wait-for-it -t 60 "${RABBITMQ_HOSTPORT}" && echo "rabbitmq is up"
    fi

    if [ ! -z "${KEYCLOAK_HOSTPORT}" ];then
        echo "Waiting for keycloak at ${KEYCLOAK_HOSTPORT}..."
        wait-for-it -t 60 "${KEYCLOAK_HOSTPORT}" && echo "keycloak is up"
    fi
fi
