mirror of
https://github.com/bunny-lab-io/Borealis.git
synced 2025-10-26 17:21:58 -06:00
Kill lingering Python processes during agent update
This commit is contained in:
39
Update.ps1
39
Update.ps1
@@ -145,6 +145,44 @@ function Start-AgentScheduledTasks {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function Stop-AgentPythonProcesses {
|
||||||
|
param(
|
||||||
|
[string[]]$ProcessNames = @('python', 'pythonw')
|
||||||
|
)
|
||||||
|
|
||||||
|
foreach ($name in ($ProcessNames | Where-Object { -not [string]::IsNullOrWhiteSpace($_) } | Select-Object -Unique)) {
|
||||||
|
$name = $name.Trim()
|
||||||
|
if (-not $name) { continue }
|
||||||
|
|
||||||
|
$processes = @()
|
||||||
|
try {
|
||||||
|
$processes = Get-Process -Name $name -ErrorAction Stop
|
||||||
|
} catch {
|
||||||
|
$processes = @()
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($proc in $processes) {
|
||||||
|
$pid = $null
|
||||||
|
$procName = $null
|
||||||
|
try {
|
||||||
|
$pid = $proc.Id
|
||||||
|
$procName = $proc.ProcessName
|
||||||
|
} catch {}
|
||||||
|
|
||||||
|
if ($pid -eq $null) { continue }
|
||||||
|
|
||||||
|
if (-not $procName) { $procName = $name }
|
||||||
|
|
||||||
|
try {
|
||||||
|
Write-Host "Stopping process: $procName (PID $pid)" -ForegroundColor Yellow
|
||||||
|
Stop-Process -Id $pid -Force -ErrorAction Stop
|
||||||
|
} catch {
|
||||||
|
Write-Host "Unable to stop process: $procName (PID $pid). $_" -ForegroundColor DarkYellow
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function Get-BorealisServerUrl {
|
function Get-BorealisServerUrl {
|
||||||
param(
|
param(
|
||||||
[string]$AgentRoot
|
[string]$AgentRoot
|
||||||
@@ -704,6 +742,7 @@ function Invoke-BorealisAgentUpdate {
|
|||||||
$staging = Join-Path $scriptDir 'Update_Staging'
|
$staging = Join-Path $scriptDir 'Update_Staging'
|
||||||
|
|
||||||
$managedTasks = Stop-AgentScheduledTasks -TaskNames @('Borealis Agent','Borealis Agent (UserHelper)')
|
$managedTasks = Stop-AgentScheduledTasks -TaskNames @('Borealis Agent','Borealis Agent (UserHelper)')
|
||||||
|
Run-Step "Updating: Terminate Running Python Processes" { Stop-AgentPythonProcesses }
|
||||||
|
|
||||||
$updateSucceeded = $false
|
$updateSucceeded = $false
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user