Add LandSAR cluster worker stop launcher
This commit is contained in:
@@ -57,6 +57,11 @@
|
||||
- 支持前台运行和 `-Background` 后台运行
|
||||
- `scripts/start_landsar_cluster_worker.bat`
|
||||
- 远端双击启动入口,内部调用 PowerShell 启动器
|
||||
- `scripts/stop_landsar_cluster_worker.ps1`
|
||||
- 停止后台 worker,默认使用 `runtime\landsar_cluster_worker\worker.pid`
|
||||
- 加 `-All` 可清理所有命令行包含 `run_landsar_cluster_worker.py` 的 Python worker
|
||||
- `scripts/stop_landsar_cluster_worker.bat`
|
||||
- 远端双击停止入口,内部调用 PowerShell 停止脚本
|
||||
|
||||
主服务器网络准入脚本:
|
||||
|
||||
@@ -227,12 +232,36 @@ D:\Code\Insar_management_system_v2\scripts\start_landsar_cluster_worker.bat
|
||||
.\scripts\start_landsar_cluster_worker.ps1 -Background
|
||||
```
|
||||
|
||||
后台停止:
|
||||
|
||||
```powershell
|
||||
.\scripts\stop_landsar_cluster_worker.ps1
|
||||
```
|
||||
|
||||
如果需要强制清理全部 LandSAR cluster worker:
|
||||
|
||||
```powershell
|
||||
.\scripts\stop_landsar_cluster_worker.ps1 -All
|
||||
```
|
||||
|
||||
需要双击停止时,运行:
|
||||
|
||||
```text
|
||||
D:\Code\Insar_management_system_v2\scripts\stop_landsar_cluster_worker.bat
|
||||
```
|
||||
|
||||
启动日志在:
|
||||
|
||||
```text
|
||||
D:\Code\Insar_management_system_v2\logs\landsar_cluster_worker
|
||||
```
|
||||
|
||||
后台 worker PID 文件在:
|
||||
|
||||
```text
|
||||
D:\Code\Insar_management_system_v2\runtime\landsar_cluster_worker\worker.pid
|
||||
```
|
||||
|
||||
## 远端连通性检查
|
||||
|
||||
在 `192.168.1.6` 上检查能否连主服务器数据库:
|
||||
|
||||
@@ -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