# Windows PowerShell version of scripts/restart.sh (persistence hook): restart LB, ALL API replicas, # PostgreSQL and Redis keeping volumes. State before/after -> evidence\restart-hook.txt $ErrorActionPreference = 'Continue' $root = Split-Path -Parent $PSScriptRoot Set-Location $root $envFile = if ($env:ENV_FILE) { $env:ENV_FILE } else { '.env' } $log = Join-Path $root 'evidence\restart-hook.txt' function Dc { & docker compose --env-file $envFile @args 2>$null | Out-Null; if ($LASTEXITCODE -ne 0) { throw ('docker compose ' + ($args -join ' ') + ' failed') } } function Get-State { foreach ($cid in (& docker compose --env-file $envFile ps -a -q)) { & docker inspect -f '{{index .Config.Labels "com.docker.compose.service"}} {{.Name}} status={{.State.Status}} started={{.State.StartedAt}} pid={{.State.Pid}}' $cid } & docker volume ls --format 'volume {{.Name}}' | Where-Object { $_ -match 'pgdata' } } try { Add-Content -Path $log -Encoding UTF8 -Value ('== ' + (Get-Date).ToUniversalTime().ToString('yyyy-MM-ddTHH:mm:ssZ') + ' before restart') Add-Content -Path $log -Encoding UTF8 -Value (Get-State) $ttl = @(& docker compose --env-file $envFile ps -q api-ttl 2>$null).Count -gt 0 Dc stop lb api if ($ttl) { Dc stop api-ttl } Dc restart postgres redis Dc start api if ($ttl) { Dc start api-ttl } Dc start lb Add-Content -Path $log -Encoding UTF8 -Value ('== ' + (Get-Date).ToUniversalTime().ToString('yyyy-MM-ddTHH:mm:ssZ') + ' after restart') Add-Content -Path $log -Encoding UTF8 -Value (Get-State) exit 0 } catch { [Console]::Error.WriteLine($_.Exception.Message) exit 1 }