Files
mtusi2026lab3/scripts/restart.ps1
T

22 lines
1.1 KiB
PowerShell

$ErrorActionPreference = 'Stop'
Set-Location (Join-Path $PSScriptRoot '..')
function Get-ContainerState($phase) {
foreach ($service in @('db', 'redis', 'api1', 'api2', 'lb')) {
$containers = docker compose --env-file .env ps -q $service
if ($LASTEXITCODE -ne 0) { throw "Cannot list $service containers" }
foreach ($container in $containers) {
$name = docker inspect --format '{{.Name}}' $container
$started = docker inspect --format '{{.State.StartedAt}}' $container
"$phase service=$service container=$name started_at=$started"
}
}
}
$before = @(Get-ContainerState 'before')
docker compose --env-file .env restart db redis api1 api2 lb | Out-Null
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
$after = @(Get-ContainerState 'after')
$stamp = Get-Date -Format 'yyyy-MM-dd HH:mm:ss K'
Add-Content -Path (Join-Path $PSScriptRoot '..\evidence\persistence-actions.txt') -Value "[$stamp]"
Add-Content -Path (Join-Path $PSScriptRoot '..\evidence\persistence-actions.txt') -Value $before
Add-Content -Path (Join-Path $PSScriptRoot '..\evidence\persistence-actions.txt') -Value $after