-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev-stop.ps1
More file actions
66 lines (57 loc) · 2.12 KB
/
Copy pathdev-stop.ps1
File metadata and controls
66 lines (57 loc) · 2.12 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#Requires -Version 5.1
param(
[int]$Port = 8080,
[switch]$KeepDbData # ha megadod, nem törli a docker volume-ot
)
$ErrorActionPreference = "SilentlyContinue"
$LOG = "[DEV]"
Set-Location -LiteralPath $PSScriptRoot
Write-Host "$LOG Stopping app & deps..."
function TryStop-ProcId([int]$procId, [string]$label = ""){
if($procId -le 0){ return }
$p = Get-Process -Id $procId -ErrorAction SilentlyContinue
if($p){
$name = $p.ProcessName
Write-Host "$LOG Kill PID $procId ($name)$label"
& taskkill /PID $procId /T /F *> $null
Stop-Process -Id $procId -Force -ErrorAction SilentlyContinue
}
}
# PID fájlokból leállítás (gradle/cmd/java folyamatfa)
$runDir = Join-Path $PSScriptRoot ".run"
$pidFiles = @(
Join-Path $runDir "bootrun.pid", # dev-start által létrehozott
Join-Path $runDir "bootrun.dev.pid" # ha esetleg így nevezted
) | Where-Object { Test-Path $_ }
foreach($f in $pidFiles){
$pidText = (Get-Content $f -ErrorAction SilentlyContinue | Select-Object -First 1).Trim()
[int]$procId = 0
if([int]::TryParse($pidText, [ref]$procId)){
TryStop-ProcId $procId " from $([IO.Path]::GetFileName($f))"
}
Remove-Item $f -Force -ErrorAction SilentlyContinue
}
# Porttisztítás (8080 a default dev port)
Write-Host "$LOG Port cleanup: $Port"
Get-NetTCPConnection -LocalPort $Port -State Listen -ErrorAction SilentlyContinue |
Select-Object -ExpandProperty OwningProcess -Unique |
ForEach-Object { TryStop-ProcId $_ " (port $Port)" }
# Várunk max 10 mp-et, hogy felszabaduljon a port
$deadline = (Get-Date).AddSeconds(10)
while((Get-NetTCPConnection -LocalPort $Port -State Listen -ErrorAction SilentlyContinue) -and (Get-Date) -lt $deadline){
Start-Sleep -Seconds 1
}
# Docker compose down (dev környezet)
if(Test-Path (Join-Path $PSScriptRoot "docker-compose.yml")){
if($KeepDbData){
Write-Host "$LOG docker compose down (volume MEGMARAD)"
docker compose down *> $null
}else{
Write-Host "$LOG docker compose down -v (volume TÖRLŐDIK)"
docker compose down -v *> $null
}
}else{
Write-Host "$LOG docker-compose.yml not found (skipping)"
}
Write-Host "$LOG stopped."
exit 0