ЛР6 - БВТ2302 - Зюлина - на 3

This commit is contained in:
2026-11-23 19:12:15 +03:00
parent 470d9d6f1e
commit 6fdb550abc
41 changed files with 2233 additions and 20 deletions
+4
View File
@@ -0,0 +1,4 @@
@echo off
setlocal
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%~dp0restart.ps1"
exit /b %errorlevel%
+21
View File
@@ -0,0 +1,21 @@
$ErrorActionPreference = 'Stop'
Set-Location (Join-Path $PSScriptRoot '..')
function Get-ContainerState($phase) {
foreach ($service in @('db', 'redis', 'redis-broker', 'minio', 'api1', 'api2', 'worker', 'lb')) {
$containers = docker compose --env-file .env ps -q $service
if ($LASTEXITCODE -ne 0) { throw "Cannot list $service containers" }
foreach ($container in $containers) {
$name = docker inspect --format '{{.Name}}' $container
$started = docker inspect --format '{{.State.StartedAt}}' $container
"$phase service=$service container=$name started_at=$started"
}
}
}
$before = @(Get-ContainerState 'before')
docker compose --env-file .env restart db redis redis-broker minio api1 api2 worker lb | Out-Null
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
$after = @(Get-ContainerState 'after')
$stamp = Get-Date -Format 'yyyy-MM-dd HH:mm:ss K'
Add-Content -Path (Join-Path $PSScriptRoot '..\evidence\persistence-actions.txt') -Value "[$stamp]"
Add-Content -Path (Join-Path $PSScriptRoot '..\evidence\persistence-actions.txt') -Value $before
Add-Content -Path (Join-Path $PSScriptRoot '..\evidence\persistence-actions.txt') -Value $after
+4
View File
@@ -0,0 +1,4 @@
@echo off
setlocal
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%~dp0stop-one.ps1"
exit /b %errorlevel%
+22
View File
@@ -0,0 +1,22 @@
$ErrorActionPreference = 'Stop'
Set-Location (Join-Path $PSScriptRoot '..')
$target = $env:TARGET_INSTANCE_ID
if ([string]::IsNullOrWhiteSpace($target)) { exit 2 }
foreach ($service in @('api1', 'api2')) {
$containers = docker compose --env-file .env ps -q $service
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
foreach ($container in $containers) {
try {
$instance = docker exec $container python -c "import urllib.request; print(urllib.request.urlopen('http://127.0.0.1:8080/health/live', timeout=2).headers['X-Instance-Id'])" 2>$null
if ($LASTEXITCODE -eq 0 -and $instance.Trim() -eq $target) {
$name = docker inspect --format '{{.Name}}' $container
$stamp = Get-Date -Format 'yyyy-MM-dd HH:mm:ss K'
Add-Content -Path (Join-Path $PSScriptRoot '..\evidence\failover-actions.txt') -Value "$stamp target=$target service=$service container=$name"
docker stop --time 5 $container | Out-Null
exit $LASTEXITCODE
}
} catch { }
}
}
Write-Error 'No running API container matched TARGET_INSTANCE_ID'
exit 1