diff --git a/scripts/deploy-raven-muninn-binary.ps1 b/scripts/deploy-raven-muninn-binary.ps1 index 00e2f93..f2c8524 100644 --- a/scripts/deploy-raven-muninn-binary.ps1 +++ b/scripts/deploy-raven-muninn-binary.ps1 @@ -244,7 +244,7 @@ New-Item -ItemType Directory -Force -Path (Split-Path -Parent `$target) | Out-Nu Get-CimInstance Win32_Process | Where-Object { `$_.Name -ieq "muninn.exe" } | ForEach-Object { - & taskkill.exe /PID `$_.ProcessId /T /F | Out-Null + & cmd.exe /c ("taskkill /PID {0} /T /F >nul 2>&1" -f `$_.ProcessId) | Out-Null } if (Test-Path -LiteralPath `$target) { diff --git a/scripts/health-muninn.ps1 b/scripts/health-muninn.ps1 index 01246bb..6e4decb 100644 --- a/scripts/health-muninn.ps1 +++ b/scripts/health-muninn.ps1 @@ -172,9 +172,25 @@ foreach (`$expectation in `$taskExpectations) { throw "`$(`$expectation.Vbs) does not reference a PowerShell launcher" } } -`$process = Get-CimInstance Win32_Process | - Where-Object { `$_.Name -ieq "muninn.exe" -and `$_.CommandLine -like "*serve*" } | - Select-Object -First 1 +`$servePidPath = Join-Path "$LogRoot" "muninn-serve.pid" +`$servePid = `$null +if (Test-Path -LiteralPath `$servePidPath) { + `$servePidText = (Get-Content -LiteralPath `$servePidPath -Raw).Trim() + if (`$servePidText -match '^\d+$') { + `$servePid = [int] `$servePidText + } +} +`$process = `$null +if (`$null -ne `$servePid) { + `$process = Get-CimInstance Win32_Process -Filter ("ProcessId = {0}" -f `$servePid) -ErrorAction SilentlyContinue | + Where-Object { `$_.Name -ieq "muninn.exe" -and `$_.CommandLine -like "*serve*" } | + Select-Object -First 1 +} +if (`$null -eq `$process) { + `$process = Get-CimInstance Win32_Process | + Where-Object { `$_.Name -ieq "muninn.exe" -and `$_.CommandLine -like "*serve*" } | + Select-Object -First 1 +} if (`$null -eq `$process) { throw "Muninn serve process is not running" } @@ -209,10 +225,12 @@ if (-not (Test-Path -LiteralPath "$StorePath")) { if (`$storeAgeSeconds -gt $MaxStoreAgeSeconds) { throw "Muninn telemetry store is stale (`$([math]::Round(`$storeAgeSeconds))s old)" } -`$servePidPath = Join-Path "$LogRoot" "muninn-serve.pid" if (-not (Test-Path -LiteralPath `$servePidPath)) { throw "Muninn serve PID file is missing at `$servePidPath" } +if (`$null -ne `$servePid -and `$process.ProcessId -ne `$servePid) { + throw "Muninn serve PID file references `$servePid but live Muninn serve process is `$(`$process.ProcessId)" +} "@ Invoke-RavenUploadedPowerShell -RavenHost $RavenHost -RemoteScriptContent $remoteScript -TempPrefix "odin-raven-muninn-health" diff --git a/scripts/restart-muninn.ps1 b/scripts/restart-muninn.ps1 index 05bf908..237ec6b 100644 --- a/scripts/restart-muninn.ps1 +++ b/scripts/restart-muninn.ps1 @@ -541,8 +541,7 @@ $servePsContent = New-HiddenNativeLauncherPowerShellContent ` -StdoutPath (Join-Path $LogRoot "muninn-serve.out.log") ` -StderrPath (Join-Path $LogRoot "muninn-serve.err.log") ` -PidPath (Join-Path $LogRoot "muninn-serve.pid") ` - -DynamicArgumentsScript $serveDynamicArgumentsScript ` - -WaitForExit + -DynamicArgumentsScript $serveDynamicArgumentsScript $activatePsContent = New-HiddenNativeLauncherPowerShellContent ` -StorePath $ActivateStorePath ` @@ -578,7 +577,7 @@ try { $localVideoProofCmd = Join-Path $uploadRoot "muninn-raven-video-to-starfire-obs.cmd" Set-AsciiFile -Path $localServePs -Content $servePsContent - Set-AsciiFile -Path $localServeVbs -Content (New-HiddenPowerShellVbsLauncherContent -PsPath $servePsPath -WaitForExit) + Set-AsciiFile -Path $localServeVbs -Content (New-HiddenPowerShellVbsLauncherContent -PsPath $servePsPath) Set-AsciiFile -Path $localServeCmd -Content (New-WscriptCmdLauncherContent -WorkingDirectory $muninnDir -VbsPath $serveVbsPath) Set-AsciiFile -Path $localActivatePs -Content $activatePsContent Set-AsciiFile -Path $localActivateVbs -Content (New-HiddenPowerShellVbsLauncherContent -PsPath $activatePsPath) @@ -616,7 +615,7 @@ foreach (`$path in @( Get-CimInstance Win32_Process | Where-Object { `$_.Name -like "muninn*.exe" } | ForEach-Object { - & taskkill.exe /PID `$_.ProcessId /T /F | Out-Null + & cmd.exe /c ("taskkill /PID {0} /T /F >nul 2>&1" -f `$_.ProcessId) | Out-Null } New-Item -ItemType Directory -Force -Path "$LogRoot" | Out-Null