$ErrorActionPreference = 'Stop' if ($env:TARGET_INSTANCE_ID -notin @('api1', 'api2')) { throw 'Invalid target' } $target = $env:TARGET_INSTANCE_ID $id = docker compose --env-file .env ps -a -q $target if ($LASTEXITCODE -ne 0 -or !$id) { throw 'Target container missing' } $running = docker inspect --format '{{.State.Running}}' $id if ($LASTEXITCODE -ne 0 -or $running -ne 'false') { throw 'Target must actually be stopped' } foreach ($service in @('db', 'lb', 'api1', 'api2')) { if ($service -eq $target) { continue } $id = docker compose --env-file .env ps -q $service if ($LASTEXITCODE -ne 0 -or !$id) { throw "$service must be running" } $running = docker inspect --format '{{.State.Running}}' $id if ($LASTEXITCODE -ne 0 -or $running -ne 'true') { throw "$service stopped unexpectedly" } } Write-Output "PASS: $target really stopped; the other API, LB and database stayed running" docker compose --env-file .env up -d --wait --wait-timeout 60 $target if ($LASTEXITCODE -ne 0) { throw 'Restore failed' } python -X utf8 scripts/wait_replicas.py if ($LASTEXITCODE -ne 0) { throw 'LB recovery failed' }