stop_local_static.ps1 763 B

123456789101112131415161718192021
  1. $root = Split-Path -Parent $PSScriptRoot
  2. $pidDir = Join-Path $root "local_static\pids"
  3. foreach ($Port in @(80, 8000)) {
  4. $pidFile = Join-Path $pidDir "http_$Port.pid"
  5. if (-not (Test-Path $pidFile)) {
  6. Write-Host "[skip] port $Port no pid file"
  7. continue
  8. }
  9. $oldPid = [int](Get-Content $pidFile -ErrorAction SilentlyContinue)
  10. if ($oldPid -gt 0) {
  11. $proc = Get-Process -Id $oldPid -ErrorAction SilentlyContinue
  12. if ($proc) {
  13. Stop-Process -Id $oldPid -Force -ErrorAction SilentlyContinue
  14. Write-Host "[stop] port $Port pid $oldPid"
  15. } else {
  16. Write-Host "[skip] port $Port pid $oldPid not running"
  17. }
  18. }
  19. Remove-Item $pidFile -Force -ErrorAction SilentlyContinue
  20. }