ЛР3: балансировка API и отказоустойчивость

This commit is contained in:
2026-11-04 17:17:44 +03:00
parent 0ab3a341aa
commit 9633b6e5c0
32 changed files with 1174 additions and 38 deletions
+6
View File
@@ -0,0 +1,6 @@
@echo off
setlocal
cd /d "%~dp0.."
rem Preserve PostgreSQL named volume, tokens and secrets.
docker compose --env-file .env restart -t 5 db api1 api2 lb
exit /b %ERRORLEVEL%
+6
View File
@@ -0,0 +1,6 @@
#!/bin/sh
set -eu
cd "$(dirname "$0")/.."
# Keep PostgreSQL named volume and the generated DB credentials unchanged.
# Restart shared DB and both API replicas; restart proxy to refresh backends.
docker compose --env-file .env restart -t 5 db api1 api2 lb
+5
View File
@@ -0,0 +1,5 @@
@echo off
setlocal
cd /d "%~dp0.."
docker compose --env-file .env start api1 api2
exit /b %ERRORLEVEL%
+4
View File
@@ -0,0 +1,4 @@
#!/bin/sh
set -eu
cd "$(dirname "$0")/.."
docker compose --env-file .env start api1 api2
+13
View File
@@ -0,0 +1,13 @@
#!/bin/sh
set -eu
cd "$(dirname "$0")/.."
if [ ! -e .env ]; then cp .env.example .env; fi
mkdir -p secrets
if [ ! -e secrets/db_password ]; then
python3 -c 'import secrets;print(secrets.token_urlsafe(36))' > secrets/db_password
fi
if [ ! -e secrets/database_url ]; then
python3 -c 'from pathlib import Path;from urllib.parse import quote; p=Path("secrets/db_password").read_text().strip();print("postgresql://messenger:"+quote(p,safe="")+"@db:5432/messenger")' > secrets/database_url
fi
chmod 600 secrets/db_password secrets/database_url .env
printf 'Local secrets prepared (values not displayed).\n'
+10
View File
@@ -0,0 +1,10 @@
@echo off
setlocal
cd /d "%~dp0.."
if /I "%TARGET_INSTANCE_ID%"=="api1" goto stop
if /I "%TARGET_INSTANCE_ID%"=="api2" goto stop
echo Invalid TARGET_INSTANCE_ID; refusing to stop an arbitrary service 1>&2
exit /b 2
:stop
docker compose --env-file .env stop -t 2 %TARGET_INSTANCE_ID%
exit /b %ERRORLEVEL%
+7
View File
@@ -0,0 +1,7 @@
#!/bin/sh
set -eu
cd "$(dirname "$0")/.."
case "${TARGET_INSTANCE_ID:-}" in
api1|api2) exec docker compose --env-file .env stop -t 2 "$TARGET_INSTANCE_ID" ;;
*) echo 'Unknown TARGET_INSTANCE_ID; refusing to stop an arbitrary service' >&2; exit 2 ;;
esac