forked from mtusi2026/mtusi2026lab2
38 lines
1016 B
Bash
Executable File
38 lines
1016 B
Bash
Executable File
#!/bin/sh
|
|
set -eu
|
|
|
|
cd "$(dirname "$0")/.."
|
|
|
|
compose() {
|
|
docker compose --env-file .env "$@"
|
|
}
|
|
|
|
printf '%s\n' '[restart] Stopping API...'
|
|
compose stop api
|
|
|
|
printf '%s\n' '[restart] Stopping Redis...'
|
|
compose stop redis
|
|
|
|
printf '%s\n' '[restart] Stopping PostgreSQL...'
|
|
compose stop postgres
|
|
|
|
printf '%s\n' '[restart] Starting PostgreSQL and Redis; waiting for healthchecks...'
|
|
compose up -d --no-deps --wait --wait-timeout 60 postgres redis
|
|
|
|
printf '%s\n' '[restart] Starting API...'
|
|
compose up -d --no-deps api
|
|
|
|
printf '%s\n' '[restart] Waiting for API readiness...'
|
|
i=0
|
|
while [ "$i" -lt 60 ]; do
|
|
if compose exec -T api python -c 'import urllib.request; urllib.request.urlopen("http://127.0.0.1:8080/health/ready", timeout=2)' >/dev/null 2>&1; then
|
|
printf '%s\n' '[restart] OK: all runtime services restarted; API ready.'
|
|
exit 0
|
|
fi
|
|
i=$((i + 1))
|
|
sleep 1
|
|
done
|
|
|
|
printf '%s\n' '[restart] FAILED: API did not become ready within 60 seconds; inspect docker compose ps/logs.' >&2
|
|
exit 1
|