deploy(prod): stage site-app co-located on app-vp03/vp04 (Akka 8082, site gRPC 8086, health 8084) + seed -AllowRunning for site PSKs

Claude-Session: https://claude.ai/code/session_01GT67AD5mc2BnaaAfY3hqqQ
This commit is contained in:
Joseph Doherty
2026-11-20 17:33:35 -05:00
parent 76aa728312
commit e472db67d5
4 changed files with 273 additions and 2 deletions
@@ -9,7 +9,9 @@ param(
[Parameter(Mandatory)][ValidateSet('MxAccessGw','ScadaBridge-Central')][string]$Target,
[Parameter(Mandatory)][string]$ValueFile,
[ValidatePattern('^[A-Za-z0-9._-]+$')][string]$SecretName = 'nam-ldap-svc-password',
[string]$Description = 'NAM LDAP lookup account (svc_igntadmin, PROD interim D-P5)'
[string]$Description = 'NAM LDAP lookup account (svc_igntadmin, PROD interim D-P5)',
# 2026-11-20: a site PSK may be added to the SHARED central SQL store while the central runs (it resolves PSKs on demand).
[switch]$AllowRunning
)
$ErrorActionPreference = 'Stop'
$cli = 'E:\ApiInstall\_tools\secret-0.6.6\ZB.MOM.WW.Secrets.Cli.exe'
@@ -27,7 +29,8 @@ $names = 'Secrets__SqlitePath','Secrets__MasterKey__Source','Secrets__MasterKey_
$fail = 0
try {
if ($Target -eq 'ScadaBridge-Central' -and $env:COMPUTERNAME -ne 'WONDER-APP-VP03') { throw 'the shared central store is seeded once, from vp03' }
$svc = Get-Service $Target; if ($svc.Status -ne 'Stopped') { throw "$Target is $($svc.Status); seed before the first start" }
if ($AllowRunning -and ($Target -ne 'ScadaBridge-Central' -or $name -notlike 'SB-GRPC-PSK-*')) { throw '-AllowRunning is only for SB-GRPC-PSK-* into the central store' }
$svc = Get-Service $Target; if ($svc.Status -ne 'Stopped' -and -not $AllowRunning) { throw "$Target is $($svc.Status); seed before the first start" }
$want = [IO.File]::ReadAllText($ValueFile).TrimEnd("`r", "`n")
if (-not $want) { throw 'value file is empty' }
"value file read, length $($want.Length)"
@@ -0,0 +1,90 @@
{
"ScadaBridge": {
"Node": {
"Role": "Site",
"NodeName": "node-a",
"NodeHostname": "10.220.153.205",
"SiteId": "site-app",
"RemotingPort": 8082,
"GrpcPort": 8086,
"MetricsPort": 8084
},
"Cluster": {
"SeedNodes": [
"akka.tcp://scadabridge@10.220.153.205:8082",
"akka.tcp://scadabridge@10.220.153.210:8082"
],
"SplitBrainResolverStrategy": "leader-auto-down",
"StableAfter": "00:00:15",
"HeartbeatInterval": "00:00:02",
"FailureDetectionThreshold": "00:00:10",
"MinNrOfMembers": 1,
"BootstrapGuard": {
"Enabled": true
}
},
"_comment_Cluster": "PROD site pair on wonder-par-vp03 (10.201.75.86) / par-vp04 (10.201.75.87), a separate Akka cluster from the centrals. SeedNodes[0] MUST be this node.",
"Database": {
"SiteDbPath": "E:\\ApiInstall\\ScadaBridge\\site\\data\\site.db"
},
"DataConnection": {
"ReconnectInterval": "00:00:05",
"TagResolutionRetryInterval": "00:00:10",
"WriteTimeout": "00:00:30"
},
"StoreAndForward": {
"SqliteDbPath": "E:\\ApiInstall\\ScadaBridge\\site\\data\\store-and-forward.db"
},
"Communication": {
"CentralGrpcEndpoints": [
"http://10.220.153.205:8083",
"http://10.220.153.210:8083"
],
"_comment": "Both centrals on their default CentralGrpcPort 8083, same list and order on both site nodes. This crosses the 10.201.75.x -> 10.220.153.x boundary (plan §4 firewall rows). GrpcPsk comes from the service env ScadaBridge__Communication__GrpcPsk; central holds the same value as secret SB-GRPC-PSK-<SiteId>.",
"DeploymentTimeout": "00:02:00",
"LifecycleTimeout": "00:00:30",
"QueryTimeout": "00:00:30",
"TransportHeartbeatInterval": "00:00:05",
"TransportFailureThreshold": "00:00:15"
},
"HealthMonitoring": {
"ReportInterval": "00:00:30",
"OfflineTimeout": "00:01:00"
},
"SiteEventLog": {
"DatabasePath": "E:\\ApiInstall\\ScadaBridge\\site\\data\\site_events.db",
"RetentionDays": 30,
"MaxStorageMb": 1024,
"PurgeScheduleCron": "0 2 * * *"
},
"Notification": {},
"Logging": {
"MinimumLevel": "Information"
}
},
"Serilog": {
"WriteTo": [
{},
{
"Args": {
"path": "E:\\ApiInstall\\ScadaBridge\\site\\logs\\scadabridge-site-.log"
}
}
]
},
"LocalDb": {
"Path": "E:\\ApiInstall\\ScadaBridge\\site\\data\\site-localdb.db",
"Replication": {
"PeerAddress": "http://10.220.153.210:8086",
"MaxBatchSize": 16,
"MaxOplogRows": 250000,
"MaxOplogAge": "2.00:00:00"
}
},
"AuditLog": {
"SiteWriter": {
"DatabasePath": "E:\\ApiInstall\\ScadaBridge\\site\\data\\auditlog.db"
}
},
"_comment_colocated": "2026-11-20: site-app co-located with ScadaBridge-Central on this box (QA pattern, ports swapped): central keeps Akka 8081 / central gRPC 8083 / UI 8085; this site uses Akka 8082, site gRPC 8086, health 8084. Paths under E:\\ApiInstall\\ScadaBridge\\site\\ (central uses ...\\central\\). Shares app\\ binaries and scadabridge.kek with the central."
}
@@ -0,0 +1,89 @@
{
"ScadaBridge": {
"Node": {
"Role": "Site",
"NodeName": "node-a",
"NodeHostname": "10.220.153.210",
"SiteId": "site-app",
"RemotingPort": 8082,
"GrpcPort": 8086,
"MetricsPort": 8084
},
"Cluster": {
"SeedNodes": [
"akka.tcp://scadabridge@10.220.153.210:8082",
"akka.tcp://scadabridge@10.220.153.205:8082"
],
"SplitBrainResolverStrategy": "leader-auto-down",
"StableAfter": "00:00:15",
"HeartbeatInterval": "00:00:02",
"FailureDetectionThreshold": "00:00:10",
"MinNrOfMembers": 1,
"BootstrapGuard": {
"Enabled": true
}
},
"_comment_Cluster": "PROD site pair on wonder-par-vp03 (10.201.75.86) / par-vp04 (10.201.75.87), a separate Akka cluster from the centrals. SeedNodes[0] MUST be this node.",
"Database": {
"SiteDbPath": "E:\\ApiInstall\\ScadaBridge\\site\\data\\site.db"
},
"DataConnection": {
"ReconnectInterval": "00:00:05",
"TagResolutionRetryInterval": "00:00:10",
"WriteTimeout": "00:00:30"
},
"StoreAndForward": {
"SqliteDbPath": "E:\\ApiInstall\\ScadaBridge\\site\\data\\store-and-forward.db"
},
"Communication": {
"CentralGrpcEndpoints": [
"http://10.220.153.205:8083",
"http://10.220.153.210:8083"
],
"_comment": "Both centrals on their default CentralGrpcPort 8083, same list and order on both site nodes. This crosses the 10.201.75.x -> 10.220.153.x boundary (plan §4 firewall rows). GrpcPsk comes from the service env ScadaBridge__Communication__GrpcPsk; central holds the same value as secret SB-GRPC-PSK-<SiteId>.",
"DeploymentTimeout": "00:02:00",
"LifecycleTimeout": "00:00:30",
"QueryTimeout": "00:00:30",
"TransportHeartbeatInterval": "00:00:05",
"TransportFailureThreshold": "00:00:15"
},
"HealthMonitoring": {
"ReportInterval": "00:00:30",
"OfflineTimeout": "00:01:00"
},
"SiteEventLog": {
"DatabasePath": "E:\\ApiInstall\\ScadaBridge\\site\\data\\site_events.db",
"RetentionDays": 30,
"MaxStorageMb": 1024,
"PurgeScheduleCron": "0 2 * * *"
},
"Notification": {},
"Logging": {
"MinimumLevel": "Information"
}
},
"Serilog": {
"WriteTo": [
{},
{
"Args": {
"path": "E:\\ApiInstall\\ScadaBridge\\site\\logs\\scadabridge-site-.log"
}
}
]
},
"LocalDb": {
"Path": "E:\\ApiInstall\\ScadaBridge\\site\\data\\site-localdb.db",
"Replication": {
"MaxBatchSize": 16,
"MaxOplogRows": 250000,
"MaxOplogAge": "2.00:00:00"
}
},
"AuditLog": {
"SiteWriter": {
"DatabasePath": "E:\\ApiInstall\\ScadaBridge\\site\\data\\auditlog.db"
}
},
"_comment_colocated": "2026-11-20: site-app co-located with ScadaBridge-Central on this box (QA pattern, ports swapped): central keeps Akka 8081 / central gRPC 8083 / UI 8085; this site uses Akka 8082, site gRPC 8086, health 8084. Paths under E:\\ApiInstall\\ScadaBridge\\site\\ (central uses ...\\central\\). Shares app\\ binaries and scadabridge.kek with the central."
}
@@ -0,0 +1,89 @@
# PROD ScadaBridge SITE node co-located with the running ScadaBridge-Central on wonder-app-vp03 / vp04 (site-app, 2026-11-20).
# Owner: "prod should have a site too, configure it for mxaccessgw on central nodes" (QA pattern: site + central on one box).
# Run ON the box. Never starts the service and never touches ScadaBridge-Central:
# - reuses the central's E:\ApiInstall\ScadaBridge\app (refuses unless its Host ProductVersion is 2e0ce81e);
# - adds app\appsettings.Site.json (the Host loads appsettings.<SCADABRIDGE_CONFIG>.json, so the central, whose
# SCADABRIDGE_CONFIG=Central, never reads it);
# - creates E:\ApiInstall\ScadaBridge\site\{data,logs} and the ScadaBridge-Site service (LocalSystem, auto, env REG_MULTI_SZ,
# recovery 5s/5s/10s, failureflag 1) using the EXISTING scadabridge.kek (the same KEK as every other node).
# -Mode dry : all checks + print the service definition (env names only). Creates nothing.
# -Mode real : the above. -ValuesDir holds ScadaBridge__Communication__GrpcPsk.txt + LocalDb__Replication__ApiKey.txt.
# Ports: central Akka 8081 / central gRPC 8083 / UI 8085; this site Akka 8082 / site gRPC 8086 / health 8084.
param(
[Parameter(Mandatory)][ValidateSet('dry','real')][string]$Mode,
[Parameter(Mandatory)][string]$ValuesDir
)
$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue'
$stage = $PSScriptRoot
$root = 'E:\ApiInstall\ScadaBridge'
$app = "$root\app"
$exe = "$app\ZB.MOM.WW.ScadaBridge.Host.exe"
$kek = 'C:\ProgramData\ZB\kek\scadabridge.kek'
$svc = 'ScadaBridge-Site'
$want = '1.0.0+2e0ce81ea04ac5e85ddb654cf33068594ba5c3c4'
function Say($m) { "[{0:HH:mm:ss}] {1}" -f (Get-Date), $m }
function Fail($m) { throw "ABORT: $m" }
$map = @{ 'WONDER-APP-VP03' = 'vp03'; 'WONDER-APP-VP04' = 'vp04' }
$b = $map[$env:COMPUTERNAME.ToUpperInvariant()]
if (-not $b) { Fail "co-located site-app goes on wonder-app-vp03/vp04 only, not $env:COMPUTERNAME" }
Say "install-sb-site-colocated mode=$Mode box=$env:COMPUTERNAME"
# 1. the central's install must be there and be the PROD build
if (-not (Test-Path $exe)) { Fail "$exe missing - install the central first" }
$pv = (Get-Item $exe).VersionInfo.ProductVersion
if ($pv -ne $want) { Fail "Host ProductVersion $pv != $want" }
Say "app ok: Host $pv"
$c = Get-Service ScadaBridge-Central -ErrorAction SilentlyContinue
Say "ScadaBridge-Central: $(if ($c) { $c.Status } else { 'ABSENT' }) (not touched)"
if (-not (Test-Path $kek) -or (Get-Item $kek).Length -ne 32) { Fail "$kek missing or not 32 bytes" }
Say "KEK sha256 $((Get-FileHash $kek).Hash.Substring(0,8)) (must be FA4511BE, as on every node)"
# 2. this node's config
$cfg = Join-Path $stage "appsettings.Site.json.prod-$b"
$cfgText = [IO.File]::ReadAllText($cfg)
if ($cfgText -match '__Q\d+_[A-Z_]+__') { Fail "unresolved placeholder $($Matches[0])" }
if ($cfgText -match '_(DEV|QA)"') { Fail 'a _DEV/_QA name in a PROD config' }
$j = $cfgText | ConvertFrom-Json
if ($j.ScadaBridge.Node.SiteId -ne 'site-app' -or $j.ScadaBridge.Node.GrpcPort -ne 8086) { Fail 'config is not the site-app / 8086 config' }
Say "config $(Split-Path $cfg -Leaf) ok (SiteId $($j.ScadaBridge.Node.SiteId), Akka $($j.ScadaBridge.Node.RemotingPort), gRPC $($j.ScadaBridge.Node.GrpcPort), health $($j.ScadaBridge.Node.MetricsPort))"
# 3. ports + service
$busy = Get-NetTCPConnection -State Listen -ErrorAction SilentlyContinue | Where-Object { $_.LocalPort -in 8082, 8084, 8086 }
if ($busy) { Fail "port(s) in use: $(($busy | ForEach-Object { $_.LocalPort }) -join ',')" }
if (Get-Service $svc -ErrorAction SilentlyContinue) { Fail "service $svc already exists" }
if (Test-Path "$root\site") { Fail "$root\site already exists" }
Say 'ports 8082 8084 8086 free; no site service or folder yet'
# 4. env (same key set as the PAR sites: sb-site.env)
$envList = New-Object System.Collections.Generic.List[string]
foreach ($l in Get-Content (Join-Path $stage 'sb-site.env')) {
if ($l -match '^\s*(#|$)') { continue }
$k, $v = $l -split '=', 2
if ($v -eq '@file') {
$f = Join-Path $ValuesDir "$k.txt"
if (-not (Test-Path -LiteralPath $f)) { Fail "missing value file for $k" }
$v = [IO.File]::ReadAllText($f).TrimEnd("`r", "`n")
if (-not $v) { Fail "empty value file for $k" }
}
$envList.Add("$k=$v")
}
Say "env entries: $($envList.Count) ($((($envList | ForEach-Object { ($_ -split '=')[0] }) -join ', ')))"
if ($Mode -eq 'dry') {
Say "[DRYRUN] copy $(Split-Path $cfg -Leaf) -> $app\appsettings.Site.json; mkdir $root\site\{data,logs}"
Say "[DRYRUN] sc.exe create $svc binPath= `"$exe`" start= auto obj= LocalSystem DisplayName= `"ScadaBridge Site Node`""
Say "[DRYRUN] Environment REG_MULTI_SZ $($envList.Count) entries; sc.exe failure 5000/5000/10000 reset 86400; failureflag 1"
Say 'DONE mode=dry'; return
}
Copy-Item $cfg "$app\appsettings.Site.json" -Force
New-Item -ItemType Directory -Force "$root\site\data", "$root\site\logs" | Out-Null
& sc.exe create $svc binPath= "`"$exe`"" start= auto obj= LocalSystem DisplayName= 'ScadaBridge Site Node' | Out-Null
if ($LASTEXITCODE -ne 0) { Fail "sc create exited $LASTEXITCODE" }
Set-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Services\$svc" -Name Environment -Type MultiString -Value $envList.ToArray()
& sc.exe failure $svc reset= 86400 actions= restart/5000/restart/5000/restart/10000 | Out-Null
& sc.exe failureflag $svc 1 | Out-Null
$n = @((Get-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Services\$svc").Environment).Count
if ($n -ne $envList.Count) { Fail "env read-back $n entries, expected $($envList.Count)" }
Say "service $svc created STOPPED, env $n entries. Next: Site entity site-app + SB-GRPC-PSK-site-app in the central store, then start both nodes together."
Say 'DONE mode=real'