Add LandSAR cluster worker stop launcher
This commit is contained in:
@@ -86,6 +86,9 @@ if ($WorkerId) {
|
||||
|
||||
$logDir = Join-Path $RepoRoot "logs\landsar_cluster_worker"
|
||||
New-Item -ItemType Directory -Force -Path $logDir | Out-Null
|
||||
$runtimeDir = Join-Path $RepoRoot "runtime\landsar_cluster_worker"
|
||||
New-Item -ItemType Directory -Force -Path $runtimeDir | Out-Null
|
||||
$pidFile = Join-Path $runtimeDir "worker.pid"
|
||||
$timestamp = Get-Date -Format "yyyyMMdd_HHmmss"
|
||||
$stdoutLog = Join-Path $logDir "worker_$timestamp.log"
|
||||
$stderrLog = Join-Path $logDir "worker_$timestamp.err.log"
|
||||
@@ -100,6 +103,12 @@ Write-Host "Mode: $(if ($Background) { 'background' } else { 'foreground' })
|
||||
Set-Location $RepoRoot
|
||||
|
||||
if ($Background) {
|
||||
if (Test-Path -LiteralPath $pidFile) {
|
||||
$existingPid = (Get-Content -LiteralPath $pidFile -ErrorAction SilentlyContinue | Select-Object -First 1).Trim()
|
||||
if ($existingPid -and (Get-Process -Id ([int]$existingPid) -ErrorAction SilentlyContinue)) {
|
||||
throw "LandSAR cluster worker already appears to be running. PID=$existingPid. Use scripts\stop_landsar_cluster_worker.ps1 first."
|
||||
}
|
||||
}
|
||||
$process = Start-Process `
|
||||
-FilePath $python `
|
||||
-ArgumentList @($workerScript) `
|
||||
@@ -108,7 +117,9 @@ if ($Background) {
|
||||
-RedirectStandardError $stderrLog `
|
||||
-WindowStyle Hidden `
|
||||
-PassThru
|
||||
Set-Content -LiteralPath $pidFile -Value $process.Id -Encoding ASCII
|
||||
Write-Host "Started background worker. PID=$($process.Id)"
|
||||
Write-Host "PID file: $pidFile"
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
@echo off
|
||||
setlocal
|
||||
cd /d "%~dp0\.."
|
||||
powershell -NoProfile -ExecutionPolicy Bypass -File "%~dp0stop_landsar_cluster_worker.ps1" -All
|
||||
pause
|
||||
@@ -0,0 +1,53 @@
|
||||
param(
|
||||
[string]$RepoRoot = (Resolve-Path (Join-Path $PSScriptRoot "..")).Path,
|
||||
[switch]$All
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
$RepoRoot = (Resolve-Path -LiteralPath $RepoRoot).Path
|
||||
$runtimeDir = Join-Path $RepoRoot "runtime\landsar_cluster_worker"
|
||||
$pidFile = Join-Path $runtimeDir "worker.pid"
|
||||
|
||||
$targetPids = New-Object System.Collections.Generic.List[int]
|
||||
if (Test-Path -LiteralPath $pidFile) {
|
||||
$rawPid = (Get-Content -LiteralPath $pidFile -ErrorAction SilentlyContinue | Select-Object -First 1).Trim()
|
||||
if ($rawPid) {
|
||||
[void]$targetPids.Add([int]$rawPid)
|
||||
}
|
||||
}
|
||||
|
||||
if ($All -or $targetPids.Count -eq 0) {
|
||||
$workers = Get-CimInstance Win32_Process |
|
||||
Where-Object {
|
||||
$_.Name -eq "python.exe" -and
|
||||
$_.CommandLine -like "*run_landsar_cluster_worker.py*"
|
||||
}
|
||||
foreach ($worker in $workers) {
|
||||
if ($targetPids -notcontains [int]$worker.ProcessId) {
|
||||
[void]$targetPids.Add([int]$worker.ProcessId)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($targetPids.Count -eq 0) {
|
||||
Write-Host "No LandSAR cluster worker process found."
|
||||
if (Test-Path -LiteralPath $pidFile) {
|
||||
Remove-Item -LiteralPath $pidFile -Force
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
foreach ($targetPid in $targetPids) {
|
||||
$process = Get-Process -Id $targetPid -ErrorAction SilentlyContinue
|
||||
if (-not $process) {
|
||||
Write-Host "PID $targetPid is not running."
|
||||
continue
|
||||
}
|
||||
Stop-Process -Id $targetPid -Force
|
||||
Write-Host "Stopped LandSAR cluster worker PID=$targetPid"
|
||||
}
|
||||
|
||||
if (Test-Path -LiteralPath $pidFile) {
|
||||
Remove-Item -LiteralPath $pidFile -Force
|
||||
}
|
||||
Reference in New Issue
Block a user