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

23 lines
685 B
PowerShell

$ErrorActionPreference = "Stop"
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$pidFile = Join-Path $scriptDir "metrics-stream.pid"
if (-not (Test-Path $pidFile)) {
Write-Host "Metrics stream 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 stream stopped. PID: $($process.Id)"
} else {
Write-Host "Metrics stream process was already gone."
}
}
Remove-Item -LiteralPath $pidFile -Force -ErrorAction SilentlyContinue