Выполнение 3 лабораторной на оценку 3
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
@echo off
|
||||
setlocal
|
||||
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%~dp0restart.ps1"
|
||||
exit /b %errorlevel%
|
||||
@@ -0,0 +1,21 @@
|
||||
$ErrorActionPreference = 'Stop'
|
||||
Set-Location (Join-Path $PSScriptRoot '..')
|
||||
function Get-ContainerState($phase) {
|
||||
foreach ($service in @('db', 'redis', 'api1', 'api2', '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 api1 api2 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
|
||||
@@ -0,0 +1,4 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
cd "$(dirname "$0")/.."
|
||||
docker compose --env-file .env restart db redis api1 api2 lb
|
||||
@@ -0,0 +1,4 @@
|
||||
@echo off
|
||||
setlocal
|
||||
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%~dp0stop-one.ps1"
|
||||
exit /b %errorlevel%
|
||||
@@ -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
|
||||
@@ -0,0 +1,15 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
target=${TARGET_INSTANCE_ID:?TARGET_INSTANCE_ID is required}
|
||||
cd "$(dirname "$0")/.."
|
||||
for service in api1 api2; do
|
||||
for container in $(docker compose --env-file .env ps -q "$service"); do
|
||||
instance=$(docker exec "$container" python -c 'import urllib.request; r=urllib.request.urlopen("http://127.0.0.1:8080/health/live",timeout=2); print(r.headers["X-Instance-Id"])' 2>/dev/null || true)
|
||||
if [ "$instance" = "$target" ]; then
|
||||
docker stop --time 5 "$container" >/dev/null
|
||||
exit 0
|
||||
fi
|
||||
done
|
||||
done
|
||||
echo "No running API container matched TARGET_INSTANCE_ID" >&2
|
||||
exit 1
|
||||
Reference in New Issue
Block a user