# #116 QA site-pair drill helper. Rendered per call: ACTION. Service ScadaBridge-Site only. $ErrorActionPreference = 'Stop' $Action = '__ACTION__' $svc = 'ScadaBridge-Site' function Say($m) { "[{0:HH:mm:ss.fff}] {1} {2}" -f (Get-Date), $env:COMPUTERNAME, $m } function Rec { Say ("qfailure: " + ((& sc.exe qfailure $svc | Out-String) -replace '\s+',' ').Trim()); Say ("qfailureflag: " + ((& sc.exe qfailureflag $svc | Out-String) -replace '\s+',' ').Trim()) } $pidNow = (Get-CimInstance Win32_Service -Filter "Name='$svc'").ProcessId switch ($Action) { 'status' { Say "$svc state $((Get-Service $svc).Status) pid $pidNow"; Rec } 'kill' { if (-not $pidNow -or $pidNow -eq 0) { throw "no running pid for $svc" } $p = Get-Process -Id $pidNow; if ($p.ProcessName -ne 'ZB.MOM.WW.ScadaBridge.Host') { throw "pid $pidNow is $($p.ProcessName)" } Say "KILL $svc pid $pidNow"; Stop-Process -Id $pidNow -Force; Say "killed" } 'disable' { & sc.exe failure $svc reset= 86400 actions= none/0/none/0/none/0 | Out-Null; if ($LASTEXITCODE -ne 0) { throw "sc failure disable" } $q = (& sc.exe qfailure $svc | Out-String); if ($q -match 'RESTART') { throw "restart action still present" }; Rec } 'kill-held' { $q = (& sc.exe qfailure $svc | Out-String); if ($q -match 'RESTART') { throw "refusing: restart action present" } $p = Get-Process -Id $pidNow; if ($p.ProcessName -ne 'ZB.MOM.WW.ScadaBridge.Host') { throw "pid $pidNow is $($p.ProcessName)" } Say "KILL-HELD $svc pid $pidNow"; Stop-Process -Id $pidNow -Force; Say "killed (no auto-restart)" } 'restore' { & sc.exe failure $svc reset= 86400 actions= restart/5000/restart/5000/restart/10000 | Out-Null; if ($LASTEXITCODE -ne 0) { throw "sc failure restore" } & sc.exe failureflag $svc 1 | Out-Null; Rec } 'start' { Say "starting $svc"; Start-Service $svc; (Get-Service $svc).WaitForStatus('Running','00:01:00'); Say "running pid $((Get-CimInstance Win32_Service -Filter "Name='$svc'").ProcessId)" } default { throw "bad action" } } exit 0