Files
mtusi2026lab4/scripts/restart.sh
T

23 lines
821 B
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/sh
# Перезапуск API и ВСЕХ хранилищ (PostgreSQL, Valkey, S3) с сохранением volumes (никаких down -v).
# В конце ждёт, пока S3 реально отдаёт данные: контейнер healthy раньше, чем volume-сервер готов читать.
set -eu
cd "$(dirname "$0")/.."
C="docker compose --env-file .env"
$C stop api
$C restart postgres valkey s3
$C start api
i=0
while [ "$i" -lt 60 ]; do
if $C exec -T api python -c "
from src import storage, config
r = storage.client().list_objects_v2(Bucket=config.S3_BUCKET, Prefix='attachments/', MaxKeys=1)
for o in r.get('Contents', []):
storage.get_object(o['Key']).read(1)
" >/dev/null 2>&1; then
exit 0
fi
i=$((i + 1)); sleep 1
done
echo "S3 data path is not ready" >&2
exit 1