forked from mtusi2026/mtusi2026lab2
Implement lab2 messenger API with PostgreSQL Redis and Docker
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
@echo off
|
||||
"C:\Program Files\Git\bin\bash.exe" "%~dp0restart.sh"
|
||||
@@ -0,0 +1,43 @@
|
||||
|
||||
#!/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."
|
||||
Reference in New Issue
Block a user