export SQL_PASSWORD=${PGSQL_PASSWORD}
export SCRIPT_DIRECTORY=postgres
+MAX_RETRY=5
+RETRY_INTERVAL=10
+
for schema in ${SQL_DB}; do
echo "Initializing $schema..."
- /opt/app/policy/bin/prepare_upgrade.sh ${schema}
+ rc=1
+ for i in $(seq 1 ${MAX_RETRY}); do
+ /opt/app/policy/bin/prepare_upgrade.sh ${schema}
- /opt/app/policy/bin/db-migrator-pg -s ${schema} -o report
+ /opt/app/policy/bin/db-migrator-pg -s ${schema} -o report
- /opt/app/policy/bin/db-migrator-pg -s ${schema} -o upgrade
- rc=$?
+ /opt/app/policy/bin/db-migrator-pg -s ${schema} -o upgrade
+ rc=$?
- /opt/app/policy/bin/db-migrator-pg -s ${schema} -o report
+ /opt/app/policy/bin/db-migrator-pg -s ${schema} -o report
+ if [ "$rc" = 0 ]; then
+ break
+ fi
+ echo "Schema $schema initialization failed (attempt ${i}/${MAX_RETRY}), retrying in ${RETRY_INTERVAL}s..."
+ sleep ${RETRY_INTERVAL}
+ done
if [ "$rc" != 0 ]; then
break
fi
if [ -n "$component" ]; then
if [ "$grafana" = true ]; then
docker compose up -d "${component}" postgres grafana --wait
+ COMPOSE_RC=$?
echo "Prometheus server: http://localhost:${PROMETHEUS_PORT}"
echo "Grafana server: http://localhost:${GRAFANA_PORT}"
else
docker compose up -d "${component}" postgres --wait
+ COMPOSE_RC=$?
fi
else
export PROJECT=policy-api # policy-api has groups.json complete with all 3 pdps
docker compose up -d --wait
+ COMPOSE_RC=$?
+fi
+
+if [ "${COMPOSE_RC}" -ne 0 ]; then
+ echo "ERROR: One or more containers failed to start (exit code: ${COMPOSE_RC}). Aborting."
+ exit ${COMPOSE_RC}
fi
cd "${WORKSPACE}"