Upgrade-MxGatewayService.ps1: process guards miss MxGateway.Server.exe/MxGateway.Worker.exe on the wonder boxes, dashboard.pfx not carried over #230
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Found while deploying #229 to DEV
wonder-app-vd03, 2026-11-12. I readscripts/deploy/Upgrade-MxGatewayService.ps1against the box, and it is not safe to run there as written. That deploy used adapted on-box scripts instead (docs/deploy/2026-11-12-vd03-76a71bc8-worker-time-fixes.md).1. The process guards never match on the wonder boxes.
$script:ServerProc/$script:WorkerProcareZB.MOM.WW.MxGateway.Server/ZB.MOM.WW.MxGateway.Worker.Get-GatewayProcessesfilters on exactly those names.E:\ApiInstall\MxGateway\Server\MxGateway.Server.exe(NSSMApplication), with the Worker atWorker\MxGateway.Worker.exe(MxGateway__Worker__ExecutablePath). So the process names areMxGateway.Server/MxGateway.Worker.Assert-NoGatewayProcessbefore every start (the OrphanWorkerTerminator trap), and the STOP_PENDING kill all pass vacuously or do nothing.Applicationand fromMxGateway__Worker__ExecutablePath.2. The staged Worker check needs the wrong file name. Preflight requires
<WorkerSource>\ZB.MOM.WW.MxGateway.Worker.exe, but the live layout (and the env path) usesMxGateway.Worker.exe. Fix: checkSplit-Path -Leaf $ctx.WorkerExe.3. Files other than
appsettings*.jsonare lost.Swap-Directorycarries onlyappsettings.jsonandappsettings.Development.jsonforward. vd03'sServer\also holdsdashboard.pfx. Fix: adddashboard.pfx, or carry forward every top-level file that is in the live directory but not in the staged one, and list them.4. Note for the runbook (section 4): runtime pack. A self-contained Server published on windev (SDK 10.0.204) ships runtime 10.0.8, but vd03 ran 10.0.14, so it would have downgraded the runtime. The Mac SDK 10.0.403 gives 10.0.14. Preflight could compare
mscordaccore_amd64_amd64_<ver>.dllbetween the live and staged directories and refuse a downgrade.Each of these needs a
-DryRuntest against a fake vd03 layout (legacy exe names,dashboard.pfx).Fixed on
mainin4890a3d1(fix(deploy): Upgrade-MxGatewayService.ps1 safe on the wonder layout, guards fail closed).What changed (
scripts/deploy/Upgrade-MxGatewayService.ps1)Applicationand ofMxGateway__Worker__ExecutablePath), plus both known schemes,ZB.MOM.WW.MxGateway.*andMxGateway.*. Processes are also matched by exact path throughWin32_Process, which gives path and parent PID.Applicationpath, and it must be a child of the NSSM service host PID. Otherwise the script aborts ("the process guards cannot see this gateway, so they would pass vacuously; refusing").appsettings*.jsonand certificates/keys (*.pfx,*.p12,*.pem,*.key,*.crt,*.cer, so vd03'sdashboard.pfx) always keep the live copy. Every other live-only top-level file that isn't a binary is carried too. Carried files are hash-verified and keep any explicit ACLs. Live-only binaries stay in the.bak, live-only subdirectories are listed as a warning, and preflight prints the carry plan.mscordaccore_amd64_amd64_<ver>.dllis older than the live one, the script refuses.-AllowRuntimeDowngradeoverrides this.AppEnvironmentExtraand fingerprinted: entry names, a 12-hex SHA-256 prefix per value, and a whole-block hash. The fingerprint is compared after the stop, after the swap, before and after the start, and after the stability window. Any added, removed, changed or reordered entry aborts and triggers the automatic rollback. Values are never printed, and sensitive values are redacted from all output and the notes file.ZB_SECRETS_MASTER_KEY, which would also have blocked vd03 (Secrets__MasterKey__Source=File). A file key is now accepted if it is outside the swap, and it is backed up. A key that isn't in the env block at all (windev) is a warning..dbfiles may sit under Server/Worker._deploy-backup-<stamp>is restricted to SYSTEM + Administrators before anything is written, and nothing is written ificaclsfails. It holds the raw env block, the service.regexport and the fingerprint..bak-<stamp>and #229's.bak.<yyyyMMddTHHmmss>sets. It refuses a Server backup without a Worker backup of the same stamp, and checks the env block against the saved fingerprint.-DryRun/-WhatIfprint every mutating step.-WhatIfwas broken on Windows PowerShell 5.1:Get-FileHashreturns nothing under$WhatIfPreference, so the plan aborted. The windev run caught this and it is fixed.Install-MxGatewayService.ps1: its process guard now matches both schemes.Tests
scripts/deploy/tests/. The repo has no Pester, so these are a plain harness plus a mutation runner.Test-UpgradeMxGatewayService.ps1: 140 assertions, all passing on pwsh/macOS and on Windows PowerShell 5.1 (windev). It runs against a fake box in both layouts: vd03 (MxGateway.*.exe,dashboard.pfx, file master key) and windev (ZB.MOM.WW.*, dated Server dir).nssm, the process table, the registry env block, health and the clock are faked. Directories are really renamed and copied..dbin Server.dashboard.pfxandappsettings*.jsonbyte-identical, binaries not carried, backups present, no secret in any output, notes or fingerprint file..bak.20261112T211945set, and refusal of a mixed-stamp rollback.Invoke-UpgradeMutations.ps1: all 12 mutations killed. These include the original #230 defects (ZB-only names; onlyappsettings*.jsoncarried), the fail-closed guard removed, the env check made a no-op or names-only, redaction removed, STOP_PENDING killing by any name, downgrade and mixed rollback allowed, and.bak.sets not found.windev dry run against the real install (
ssh windev,powershell -NoProfile -File, Windows PowerShell 5.1)-DryRun(and-WhatIf) with-ServerSource/-WorkerSourcepointing at a scratch copy of the live447070a5build,-ExpectedSha 447070a5: EXIT 0.Negative control on the same box: a copy with the image names and path match removed found
noneand aborted withservice is RUNNING but no gateway Server process was found ... refusing.(EXIT 1).The real run also caught a second bug the fakes had hidden: an empty
Win32_Serviceresult came back as$nulland read as "check unavailable". It is fixed and now covered by a test.windev afterwards:
MxAccessGwSERVICE_RUNNING, same gateway PID 9148,:5130/health/ready200. No backup dirs, lock file or store copies were created.The runbook (
docs/runbooks/DeployUpgradeNssmService.md) is updated: script behaviour, test status, both naming schemes in traps 1 and 8 and in section 6, the runtime-pack note in section 4, and the confirmed vd03/windev layouts in section 9. The vd03 record now points QA at the fixed script.Not covered: no real (non-dry) upgrade has run on a box yet. The first one should be QA (#229), starting with
-DryRunon each box.