Реализовать лабораторную 3
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
@echo off
|
||||
cd /d "%~dp0.."
|
||||
docker compose restart db cache api-a api-b lb
|
||||
Executable
+4
@@ -0,0 +1,4 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
cd "$(dirname "$0")/.."
|
||||
docker compose restart db cache api-a api-b lb
|
||||
@@ -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
|
||||
@@ -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%
|
||||
Executable
+7
@@ -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
|
||||
Reference in New Issue
Block a user