ESP32/tools/pc-metrics/stop-http-metrics.ps1
2026-06-23 20:38:23 +08:00

23 lines
698 B
PowerShell

$ErrorActionPreference = "Stop"
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$pidFile = Join-Path $scriptDir "metrics-http.pid"
if (-not (Test-Path $pidFile)) {
Write-Host "Metrics HTTP server is not running."
exit 0
}
$pidValue = Get-Content $pidFile -ErrorAction SilentlyContinue
if ($pidValue) {
$process = Get-Process -Id ([int]$pidValue) -ErrorAction SilentlyContinue
if ($process) {
Stop-Process -Id $process.Id -Force
Write-Host "Metrics HTTP server stopped. PID: $($process.Id)"
} else {
Write-Host "Metrics HTTP server process was already gone."
}
}
Remove-Item -LiteralPath $pidFile -Force -ErrorAction SilentlyContinue