Install-MxGatewayService.ps1 aborts on a fresh box under Windows PowerShell 5.1 (nssm status probe) #234

Closed
opened 2026-11-20 15:40:06 -05:00 by dohertj2 · 1 comment
Owner

First PROD install 2026-11-20 (wonder-app-vp03): the dry run aborted with ERROR: Can't open service! / Install-MxGatewayService exited 1. With $ErrorActionPreference=Stop, PS 5.1 turns nssm's expected stderr from the "does the service exist?" probe (scripts/deploy/Install-MxGatewayService.ps1 ~line 65) into a terminating error, so a first install can never pass. The staged PROD copy carries PROD-STAGE PATCH 4 (run that one native call with ErrorAction Continue and check the exit code) — scadaproj 68710e5, docs/deploy/2026-11-19-prod-stage/mxgw/. Also owed: the other three PROD-STAGE patches (-WorkerExeName, File KEK, connection-string masking) and the Upgrade script START_PENDING fix. Needed before the PAR boxes get mxgw.

First PROD install 2026-11-20 (wonder-app-vp03): the dry run aborted with `ERROR: Can't open service!` / `Install-MxGatewayService exited 1`. With `$ErrorActionPreference=Stop`, PS 5.1 turns nssm's expected stderr from the "does the service exist?" probe (scripts/deploy/Install-MxGatewayService.ps1 ~line 65) into a terminating error, so a first install can never pass. The staged PROD copy carries PROD-STAGE PATCH 4 (run that one native call with ErrorAction Continue and check the exit code) — scadaproj `68710e5`, docs/deploy/2026-11-19-prod-stage/mxgw/. Also owed: the other three PROD-STAGE patches (-WorkerExeName, File KEK, connection-string masking) and the Upgrade script START_PENDING fix. Needed before the PAR boxes get mxgw.
Author
Owner

Fixed on branch fix/234-install-script-ps51 (c1776e9e). Not merged to main and not pushed yet.

  • PATCH 4 (this abort): Invoke-Nssm runs the native call under ErrorActionPreference=Continue (restored in finally), and the exit code decides the outcome.
  • PATCH 1: new -WorkerExeName parameter (default ZB.MOM.WW.MxGateway.Worker.exe; the wonder boxes pass MxGateway.Worker.exe).
  • PATCH 2: file KEK accepted (Secrets__MasterKey__Source=File plus an absolute Secrets__MasterKey__FilePath) as an alternative to ZB_SECRETS_MASTER_KEY.
  • PATCH 3: CONNECTIONSTRING added to the env mask.
  • Upgrade START_PENDING: nssm start is called with -AllowFail, and the existing RUNNING wait decides success.
  • Same hazard elsewhere: the Upgrade script's Invoke-Nssm, Protect-Directory (icacls) and Export-ServiceKey (reg.exe) got the same wrapper.
  • Runbook: docs/runbooks/DeployUpgradeNssmService.md updated.

Verification:

  • Both scripts parse with 0 errors under pwsh and under Windows PowerShell 5.1.19041 on windev.
  • Test-UpgradeMxGatewayService.ps1 passes 140/140.
  • On 5.1 the hazard reproduces: the unguarded call throws and the guarded call returns exit 1.

Not done: a full first install on a fresh box. Do that on the next new box. Closing.

Fixed on branch `fix/234-install-script-ps51` (`c1776e9e`). Not merged to `main` and not pushed yet. - **PATCH 4 (this abort):** `Invoke-Nssm` runs the native call under `ErrorActionPreference=Continue` (restored in `finally`), and the exit code decides the outcome. - **PATCH 1:** new `-WorkerExeName` parameter (default `ZB.MOM.WW.MxGateway.Worker.exe`; the wonder boxes pass `MxGateway.Worker.exe`). - **PATCH 2:** file KEK accepted (`Secrets__MasterKey__Source=File` plus an absolute `Secrets__MasterKey__FilePath`) as an alternative to `ZB_SECRETS_MASTER_KEY`. - **PATCH 3:** `CONNECTIONSTRING` added to the env mask. - **Upgrade START_PENDING:** `nssm start` is called with `-AllowFail`, and the existing RUNNING wait decides success. - **Same hazard elsewhere:** the Upgrade script's `Invoke-Nssm`, `Protect-Directory` (icacls) and `Export-ServiceKey` (reg.exe) got the same wrapper. - **Runbook:** `docs/runbooks/DeployUpgradeNssmService.md` updated. **Verification:** - Both scripts parse with 0 errors under pwsh and under Windows PowerShell 5.1.19041 on windev. - `Test-UpgradeMxGatewayService.ps1` passes 140/140. - On 5.1 the hazard reproduces: the unguarded call throws and the guarded call returns exit 1. **Not done:** a full first install on a fresh box. Do that on the next new box. Closing.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: dohertj2/mxaccessgw#234