base of lab 4

This commit is contained in:
2026-11-10 17:12:13 +03:00
parent 276dbdad8a
commit 1ec85a2402
78 changed files with 6133 additions and 0 deletions
+48
View File
@@ -0,0 +1,48 @@
#!/bin/sh
set -eu
cd "$(dirname "$0")/.."
mkdir -p .local-logs
exec > .local-logs/restart.log 2>&1
set -x
date -u
echo "Stopping API and load balancer"
docker compose stop -t 10 api lb
echo "Restarting persistent services"
docker compose restart -t 10 postgres redis minio
echo "Waiting for persistent services"
docker compose up -d \
--no-build \
--pull never \
--no-deps \
--no-recreate \
--wait \
--wait-timeout 25 \
postgres redis minio
echo "Starting API"
docker compose up -d \
--no-build \
--pull never \
--no-deps \
--no-recreate \
--wait \
--wait-timeout 45 \
api
echo "Starting load balancer without dependencies"
docker compose up -d \
--no-build \
--pull never \
--no-deps \
--no-recreate \
lb
echo "Restart completed"
date -u
+46
View File
@@ -0,0 +1,46 @@
#!/bin/sh
set -eu
cd "$(dirname "$0")/.."
: "${TARGET_INSTANCE_ID:?Не задан TARGET_INSTANCE_ID}"
compose() {
docker compose --env-file .env -f compose.yml "$@"
}
containers=$(compose ps --status running -q api)
target=""
count=0
for container in $containers; do
count=$((count + 1))
instance_id=$(docker inspect \
--format '{{.Config.Hostname}}' "$container")
if [ "$instance_id" = "$TARGET_INSTANCE_ID" ]; then
if [ -n "$target" ]; then
printf '%s\n' 'Ошибка: найдено несколько подходящих реплик.' >&2
exit 1
fi
target="$container"
fi
done
if [ "$count" -lt 2 ]; then
printf '%s\n' 'Ошибка: должны работать минимум две API-реплики.' >&2
exit 1
fi
if [ -z "$target" ]; then
printf '%s\n' 'Ошибка: указанная API-реплика не найдена.' >&2
exit 1
fi
docker kill --signal=KILL "$target" >/dev/null
printf '%s\n' "Остановлена API-реплика: $TARGET_INSTANCE_ID"