-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStopDemo.ps1
More file actions
39 lines (32 loc) · 1.41 KB
/
Copy pathStopDemo.ps1
File metadata and controls
39 lines (32 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# StopDemo.ps1
# Stops the Demo service by reading from its PID file
$PidFile = Join-Path $PSScriptRoot ".Demo-pid.txt"
Write-Host "Stopping Demo service..."
function Stop-ServiceByPidFile($serviceName, $pidFile) {
if (-not (Test-Path $pidFile)) {
Write-Host "No PID file found for $serviceName"
return
}
Write-Host "Stopping $serviceName..."
Get-Content $pidFile | Where-Object { $_ -match '^\d+$' } | Select-Object -Unique | ForEach-Object {
try {
if ($IsWindows) {
Start-Process -FilePath "taskkill.exe" -ArgumentList "/PID $_ /T /F" -NoNewWindow -Wait
} else {
$p = Get-Process -Id ([int]$_) -ErrorAction SilentlyContinue
if ($p) { $p.CloseMainWindow() | Out-Null; Start-Sleep -Milliseconds 200 }
Stop-Process -Id ([int]$_) -Force -ErrorAction SilentlyContinue
}
} catch {}
}
Remove-Item $pidFile -ErrorAction SilentlyContinue
}
# Stop Demo service
Stop-ServiceByPidFile "Demo" $PidFile
# Fallback: kill any lingering dotnet watch processes for Demo
try {
Get-CimInstance Win32_Process -Filter "Name='dotnet.exe'" |
Where-Object { $_.CommandLine -match 'watch\s+run' -and $_.CommandLine -match 'Soenneker.Quark.Suite\.Demo' } |
ForEach-Object { Invoke-CimMethod -InputObject $_ -MethodName Terminate | Out-Null }
} catch {}
Write-Host "Demo service stopped."