forked from mtusi2026/mtusi2026lab3
Сессия и ключ идемпотентности общие для реплик, миграция выполняется один раз, остановка одной реплики не теряет подтверждённые сообщения.
26 lines
928 B
PowerShell
26 lines
928 B
PowerShell
$ErrorActionPreference = 'Stop'
|
|
if (-not $env:TARGET_INSTANCE_ID) {
|
|
Write-Error 'TARGET_INSTANCE_ID is required'
|
|
exit 1
|
|
}
|
|
Set-Location (Split-Path $PSScriptRoot -Parent)
|
|
$ids = @(docker compose --env-file .env ps -q api)
|
|
if (-not $ids) {
|
|
Write-Error 'no running api containers'
|
|
exit 1
|
|
}
|
|
foreach ($raw in $ids) {
|
|
$cid = "$raw".Trim()
|
|
if (-not $cid) { continue }
|
|
$hostName = "$((docker inspect -f '{{.Config.Hostname}}' $cid))".Trim()
|
|
$full = "$((docker inspect -f '{{.Id}}' $cid))".Trim()
|
|
$name = "$((docker inspect -f '{{.Name}}' $cid))".Trim().TrimStart('/')
|
|
$short = $full.Substring(0, [Math]::Min(12, $full.Length))
|
|
if ($hostName -eq $env:TARGET_INSTANCE_ID -or $short -eq $env:TARGET_INSTANCE_ID -or $name -eq $env:TARGET_INSTANCE_ID) {
|
|
docker stop -t 6 $cid | Out-Null
|
|
exit $LASTEXITCODE
|
|
}
|
|
}
|
|
Write-Error 'no running api container matches the instance'
|
|
exit 1
|