Выполнение 4 лабораторной на оценку 3
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user