forked from mtusi2026/mtusi2026lab2
44 lines
996 B
Bash
44 lines
996 B
Bash
|
|
#!/bin/sh
|
|
set -eu
|
|
|
|
echo "Restarting API, PostgreSQL and Redis without deleting volumes..."
|
|
|
|
docker compose --env-file .env restart postgres redis api
|
|
|
|
echo "Waiting for services to become healthy..."
|
|
|
|
for service in postgres redis api; do
|
|
echo "Checking $service..."
|
|
|
|
ready=0
|
|
attempt=0
|
|
|
|
while [ "$attempt" -lt 60 ]; do
|
|
container_id=$(docker compose --env-file .env ps -q "$service")
|
|
|
|
if [ -n "$container_id" ]; then
|
|
status=$(docker inspect \
|
|
--format '{{if .State.Health}}{{.State.Health.Status}}{{else}}{{.State.Status}}{{end}}' \
|
|
"$container_id")
|
|
|
|
if [ "$status" = "healthy" ]; then
|
|
ready=1
|
|
break
|
|
fi
|
|
fi
|
|
|
|
attempt=$((attempt + 1))
|
|
sleep 2
|
|
done
|
|
|
|
if [ "$ready" -ne 1 ]; then
|
|
echo "ERROR: $service did not become healthy"
|
|
exit 1
|
|
fi
|
|
|
|
echo "$service is healthy"
|
|
done
|
|
|
|
echo "All services restarted successfully."
|