forked from mtusi2026/mtusi2026lab6
24 lines
733 B
PowerShell
24 lines
733 B
PowerShell
$ErrorActionPreference = "Stop"
|
|
if (-not $env:TARGET_INSTANCE_ID) {
|
|
Write-Error "TARGET_INSTANCE_ID is required"
|
|
exit 1
|
|
}
|
|
Set-Location (Join-Path $PSScriptRoot "..")
|
|
$ids = docker compose --env-file .env ps -q api
|
|
$found = $false
|
|
foreach ($id in $ids) {
|
|
if (-not $id) { continue }
|
|
$iid = ""
|
|
try { $iid = (docker exec $id cat /tmp/instance-id).Trim() } catch { $iid = "" }
|
|
$hostName = (docker inspect -f "{{.Config.Hostname}}" $id).Trim()
|
|
if ($iid -eq $env:TARGET_INSTANCE_ID -or $hostName -eq $env:TARGET_INSTANCE_ID) {
|
|
docker stop -t 5 $id | Out-Null
|
|
$found = $true
|
|
break
|
|
}
|
|
}
|
|
if (-not $found) {
|
|
Write-Error "no running API replica matched TARGET_INSTANCE_ID"
|
|
exit 1
|
|
}
|