deploy(prod): stage patches from the first PROD run (nssm probe on PS 5.1 = PATCH 4; seed keeps the value file on failure)

Claude-Session: https://claude.ai/code/session_01GT67AD5mc2BnaaAfY3hqqQ
This commit is contained in:
Joseph Doherty
2026-11-20 15:39:42 -05:00
parent 7ea31e160a
commit 68710e5025
2 changed files with 10 additions and 2 deletions
@@ -51,8 +51,13 @@ try {
if (-not $match) { try { $j = $got | ConvertFrom-Json; $match = ($j.value -ceq $want) } catch {} }
"$Target -> $where kek=$($env:Secrets__MasterKey__FilePath) kek-sha256=$((Get-FileHash $env:Secrets__MasterKey__FilePath).Hash.Substring(0,8)) set rc=$rc out=$(($out | Out-String).Trim()) readback-match=$match"
if ($rc -ne 0 -or -not $match) { $fail++ }
} catch {
$fail++; "SEED ERROR: $($_.Exception.Message)"
} finally {
Remove-Item $ValueFile, "$ValueFile.nl" -Force -ErrorAction SilentlyContinue; "value file removed: $(-not (Test-Path $ValueFile))"
# 2026-11-20: delete the value file only on success, so a failed seed can be retried without re-staging it.
Remove-Item "$ValueFile.nl" -Force -ErrorAction SilentlyContinue
if ($fail -eq 0) { Remove-Item $ValueFile -Force -ErrorAction SilentlyContinue; "value file removed: $(-not (Test-Path $ValueFile))" }
else { "value file KEPT for retry (ACL Administrators+SYSTEM): $ValueFile" }
foreach ($n in $names) { Remove-Item "Env:$n" -ErrorAction SilentlyContinue }
}
"SEED DONE failures=$fail"; exit $fail
@@ -65,7 +65,10 @@ function Step([string]$Description, [scriptblock]$Action) {
}
function Invoke-Nssm {
param([string[]]$NssmArgs, [switch]$AllowFail)
$raw = & $NssmPath @NssmArgs 2>&1; $code = $LASTEXITCODE
# PROD-STAGE PATCH 4 (2026-11-20): under EAP=Stop, PS 5.1 turns native stderr redirected by 2>&1 into a terminating
# NativeCommandError, so `nssm status` on a not-yet-installed service aborted even with -AllowFail. Run it under Continue.
$eap = $ErrorActionPreference; $ErrorActionPreference = 'Continue'
try { $raw = & $NssmPath @NssmArgs 2>&1; $code = $LASTEXITCODE } finally { $ErrorActionPreference = $eap }
$text = (($raw | ForEach-Object { "$_" }) -join "`n") -replace "`0", ''
if ($code -ne 0 -and -not $AllowFail) { Fail "nssm $($NssmArgs[0..1] -join ' ') failed (exit $code): $text" }
[pscustomobject]@{ Code = $code; Text = $text.Trim() }