improve stop script with better error handling
This commit is contained in:
@@ -3,7 +3,6 @@ chcp 65001 >nul
|
|||||||
setlocal
|
setlocal
|
||||||
cd /d %~dp0
|
cd /d %~dp0
|
||||||
|
|
||||||
REM Stop processes using PowerShell
|
powershell -ExecutionPolicy Bypass -File stop.ps1
|
||||||
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 }"
|
|
||||||
|
|
||||||
timeout /t 2
|
pause
|
||||||
|
|||||||
46
script/stop.ps1
Normal file
46
script/stop.ps1
Normal file
@@ -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 ""
|
||||||
Reference in New Issue
Block a user