2019-05-17 00:56:02 +03:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
# This file is the entrypoint for the backend container.
|
2022-05-06 00:30:20 +03:00
|
|
|
# It takes care of making sure to wait for the mysql and rabbitmq containers to be ready
|
2019-05-17 00:56:02 +03:00
|
|
|
|
|
|
|
# Make non-zero exit codes & other errors fatal.
|
|
|
|
set -euo pipefail
|
|
|
|
|
2022-05-06 00:30:20 +03:00
|
|
|
function check_service () {
|
|
|
|
name=$1
|
|
|
|
host=$2
|
|
|
|
port=$3
|
|
|
|
while ! nc -z "$host" "$port" &> /dev/null; do
|
|
|
|
echo "-----> Waiting for $name server to be ready"
|
|
|
|
sleep 1;
|
|
|
|
done
|
|
|
|
echo "-----> $name service is available"
|
|
|
|
}
|
|
|
|
|
2019-05-17 00:56:02 +03:00
|
|
|
# Keep these in sync with DATABASE_URL.
|
2023-07-13 12:02:38 +03:00
|
|
|
echo "Checking database status at $DATABASE_URL"
|
|
|
|
if [[ ${DATABASE_URL:0:8} == "mysql://" ]]; then
|
|
|
|
check_service "MySQL" "mysql" 3306;
|
|
|
|
fi
|
|
|
|
if [[ ${DATABASE_URL:0:7} == "psql://" ]]; then
|
|
|
|
check_service "PostgreSQL" "postgres" 5432;
|
|
|
|
fi
|
2019-05-17 00:56:02 +03:00
|
|
|
|
2022-05-06 00:30:20 +03:00
|
|
|
# Keep these in sync with CELERY_BROKER_URL.
|
|
|
|
check_service "RabbitMQ" "rabbitmq" 5672
|
2020-01-22 22:28:18 +03:00
|
|
|
|
2019-05-17 00:56:02 +03:00
|
|
|
exec "$@"
|