From c55793bae5a8bee955d2f3bd0441ee7a7646f791 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A5=80=E6=A2=A6?= <3501646051@qq.com> Date: Tue, 27 Jan 2026 21:50:46 +0800 Subject: [PATCH] improve stop script with better error handling --- script/stop.bat | 5 ++--- script/stop.ps1 | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 script/stop.ps1 diff --git a/script/stop.bat b/script/stop.bat index 114920f..1b17e52 100644 --- a/script/stop.bat +++ b/script/stop.bat @@ -3,7 +3,6 @@ chcp 65001 >nul setlocal cd /d %~dp0 -REM Stop processes using PowerShell -powershell -ExecutionPolicy Bypass -Command "& { Write-Host 'Stopping processes on 8923 and 6173...' -ForegroundColor Cyan; $ports = @(8923, 6173); foreach ($port in $ports) { $p = Get-NetTCPConnection -LocalPort $port -ErrorAction SilentlyContinue; if ($p) { Stop-Process -Id $p.OwningProcess -Force; Write-Host \"Stopped port $port\" } }; Write-Host 'Done.' -ForegroundColor Green }" +powershell -ExecutionPolicy Bypass -File stop.ps1 -timeout /t 2 +pause diff --git a/script/stop.ps1 b/script/stop.ps1 new file mode 100644 index 0000000..2409c0c --- /dev/null +++ b/script/stop.ps1 @@ -0,0 +1,46 @@ +# ProxyPool Stop Script +$rootPath = Split-Path $PSScriptRoot -Parent + +Write-Host "=== Stopping ProxyPool Services ===" -ForegroundColor Cyan +Write-Host "" + +Write-Host "[1/2] Stopping processes on ports 8923 and 6173..." -ForegroundColor Cyan +$ports = @(8923, 6173) +$stoppedCount = 0 + +foreach ($port in $ports) { + try { + $conn = Get-NetTCPConnection -LocalPort $port -ErrorAction SilentlyContinue + if ($conn) { + $processId = $conn.OwningProcess + + try { + $process = Get-Process -Id $processId -ErrorAction SilentlyContinue + if ($process) { + $processName = $process.ProcessName + Stop-Process -Id $processId -Force -ErrorAction SilentlyContinue + + Write-Host " Stopped port $port (PID: $processId, Process: $processName)" -ForegroundColor Gray + $stoppedCount++ + } + } catch { + Write-Host " Warning: Could not stop process on port $port (PID: $processId)" -ForegroundColor Yellow + } + } else { + Write-Host " Port $port: No process found" -ForegroundColor DarkGray + } + } catch { + Write-Host " Error checking port $port: $($_.Exception.Message)" -ForegroundColor Red + } +} + +Write-Host " Stopped $stoppedCount process(es)" -ForegroundColor Green +Write-Host "" + +Write-Host "[2/2] Waiting for processes to fully stop..." -ForegroundColor Cyan +Start-Sleep -Seconds 2 + +Write-Host "" +Write-Host "=== Done ===" -ForegroundColor Cyan +Write-Host "All services have been stopped." -ForegroundColor Green +Write-Host ""