#!/command/with-contenv /bin/bash
# shellcheck shell=bash

SCRIPT_ROOT=/etc/s6-overlay/scripts
source "$SCRIPT_ROOT/base.sh"
# The config should be ready before starting
if [ -f "$GPUSTACK_POSTGRES_CONFIG" ]; then
    source "$GPUSTACK_POSTGRES_CONFIG"
fi
source "$SCRIPT_ROOT/default-variables.sh"

echo "[INFO] Checking Postgres readiness."
if gosu postgres pg_isready -p "$EMBEDDED_DATABASE_PORT" -q; then
    echo "[INFO] Postgres is ready."
    exit 0
else
    echo "[ERROR] Postgres is not ready."
    exit 1
fi
