Реализовать лабораторную 3

This commit is contained in:
Krep4334
2026-11-13 18:22:52 +03:00
parent 0ab3a341aa
commit 2a4242695f
23 changed files with 1121 additions and 40 deletions
+3
View File
@@ -0,0 +1,3 @@
@echo off
cd /d "%~dp0.."
docker compose restart db cache api-a api-b lb
+4
View File
@@ -0,0 +1,4 @@
#!/bin/sh
set -eu
cd "$(dirname "$0")/.."
docker compose restart db cache api-a api-b lb
+28
View File
@@ -0,0 +1,28 @@
from pathlib import Path
import secrets
root = Path(__file__).resolve().parents[1]
directory = root / "secrets"
directory.mkdir(mode=0o700, exist_ok=True)
def ensure(name, value):
path = directory / name
try:
with path.open("x", encoding="utf-8") as file:
file.write(value + "\n")
except FileExistsError:
pass
return path.read_text(encoding="utf-8").strip()
password = ensure("db_password", secrets.token_hex(24))
ensure("database_url", f"postgresql://messenger:{password}@db:5432/messenger")
ensure("cache_url", "redis://cache:6379/0")
ensure("cursor_key", secrets.token_hex(32))
try:
with (root / ".env").open("xb") as file:
file.write((root / ".env.example").read_bytes())
except FileExistsError:
pass
+7
View File
@@ -0,0 +1,7 @@
@echo off
cd /d "%~dp0.."
if "%TARGET_INSTANCE_ID%"=="api-a" goto stop
if "%TARGET_INSTANCE_ID%"=="api-b" goto stop
exit /b 2
:stop
docker compose stop --timeout 5 %TARGET_INSTANCE_ID%
+7
View File
@@ -0,0 +1,7 @@
#!/bin/sh
set -eu
cd "$(dirname "$0")/.."
case "${TARGET_INSTANCE_ID:-}" in
api-a|api-b) docker compose stop --timeout 5 "$TARGET_INSTANCE_ID" ;;
*) exit 2 ;;
esac