ЛР3: балансировка API и отказоустойчивость
This commit is contained in:
@@ -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%
|
||||
@@ -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
|
||||
@@ -0,0 +1,5 @@
|
||||
@echo off
|
||||
setlocal
|
||||
cd /d "%~dp0.."
|
||||
docker compose --env-file .env start api1 api2
|
||||
exit /b %ERRORLEVEL%
|
||||
@@ -0,0 +1,4 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
cd "$(dirname "$0")/.."
|
||||
docker compose --env-file .env start api1 api2
|
||||
@@ -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'
|
||||
@@ -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%
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user