-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev.ps1
More file actions
149 lines (134 loc) · 5.98 KB
/
Copy pathdev.ps1
File metadata and controls
149 lines (134 loc) · 5.98 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
$ErrorActionPreference = "Continue"
# ====================================================================
# Gio Phim Backend Dev Bootstrap
# 1. Nginx (HLS / public assets - optional)
# 2. Port 8080 (don dep PID cu)
# 3. Ollama (start + warm-up model)
# 4. Spring Boot (profile=local, Xmx=2g)
# ====================================================================
$ollamaModel = "qcwind/qwen3-8b-instruct-Q4-K-M:latest"
$ollamaBase = "http://localhost:11434"
$nginxDir = "C:\Users\hoaug\nginx"
$nginxExe = Join-Path $nginxDir "nginx.exe"
$springPort = 8080
Write-Host ""
Write-Host "=== Gio Phim Backend Dev Bootstrap ===" -ForegroundColor Cyan
Write-Host ""
# ----------------------------------------------------------------
# 1. NGINX (optional)
# ----------------------------------------------------------------
$nginxAvailable = Test-Path $nginxExe
if ($nginxAvailable) {
& $nginxExe -p "$nginxDir/" -c "conf/nginx.conf" -t 2>$null | Out-Null
if ($LASTEXITCODE -ne 0) {
Write-Host "[Nginx] config test FAILED - check $nginxDir\logs\error.log" -ForegroundColor Red
exit 1
}
$nginxRunning = Get-Process -Name "nginx" -ErrorAction SilentlyContinue
if ($nginxRunning) {
Write-Host "[Nginx] dang chay - reload config (graceful)..." -ForegroundColor Yellow
& $nginxExe -p "$nginxDir/" -c "conf/nginx.conf" -s reload 2>$null | Out-Null
if ($LASTEXITCODE -ne 0) {
Write-Host "[Nginx] reload that bai - quit + restart" -ForegroundColor Yellow
& $nginxExe -p "$nginxDir/" -c "conf/nginx.conf" -s quit 2>$null | Out-Null
Start-Sleep -Milliseconds 1500
Get-Process -Name "nginx" -ErrorAction SilentlyContinue | Stop-Process -Force -ErrorAction SilentlyContinue
Start-Process -FilePath $nginxExe -ArgumentList @("-p", "$nginxDir/", "-c", "conf/nginx.conf") -WindowStyle Hidden
Start-Sleep -Seconds 2
}
} else {
Write-Host "[Nginx] khoi dong..." -ForegroundColor Yellow
Start-Process -FilePath $nginxExe -ArgumentList @("-p", "$nginxDir/", "-c", "conf/nginx.conf") -WindowStyle Hidden
Start-Sleep -Seconds 2
}
if (Get-Process -Name "nginx" -ErrorAction SilentlyContinue) {
Write-Host "[Nginx] OK - http://localhost" -ForegroundColor Green
} else {
Write-Host "[Nginx] khong start duoc - check $nginxDir\logs\error.log" -ForegroundColor Red
exit 1
}
} else {
Write-Host "[Nginx] khong tim thay $nginxExe - bo qua" -ForegroundColor DarkYellow
}
# ----------------------------------------------------------------
# 2. Don dep port 8080
# ----------------------------------------------------------------
Write-Host ""
Write-Host "[Port] kiem tra $springPort..."
$conns = Get-NetTCPConnection -LocalPort $springPort -State Listen -ErrorAction SilentlyContinue
foreach ($c in $conns) {
Write-Host "[Port] kill PID $($c.OwningProcess) giu $springPort" -ForegroundColor Yellow
Stop-Process -Id $c.OwningProcess -Force -ErrorAction SilentlyContinue
}
# ----------------------------------------------------------------
# 3. OLLAMA
# ----------------------------------------------------------------
Write-Host ""
$ollamaProc = Get-Process -Name "ollama" -ErrorAction SilentlyContinue
if (-not $ollamaProc) {
Write-Host "[Ollama] chua chay - khoi dong 'ollama serve'..." -ForegroundColor Yellow
Start-Process -FilePath "ollama" -ArgumentList "serve" -WindowStyle Hidden
Start-Sleep -Seconds 3
} else {
Write-Host "[Ollama] da chay (PID $($ollamaProc.Id -join ','))" -ForegroundColor Green
}
$ready = $false
for ($i = 0; $i -lt 15; $i++) {
try {
Invoke-WebRequest -Uri "$ollamaBase/api/tags" -UseBasicParsing -TimeoutSec 2 | Out-Null
$ready = $true
break
} catch {
Start-Sleep -Seconds 2
}
}
if ($ready) {
Write-Host "[Ollama] san sang." -ForegroundColor Green
Write-Host "[Ollama] warm-up model $ollamaModel..." -ForegroundColor Yellow
try {
$body = @{
model = $ollamaModel
prompt = "Hi"
stream = $false
options = @{ num_predict = 1 }
} | ConvertTo-Json -Compress
Invoke-WebRequest -Uri "$ollamaBase/api/generate" -Method POST -Body $body `
-ContentType "application/json" -UseBasicParsing -TimeoutSec 180 | Out-Null
Write-Host "[Ollama] warm-up xong." -ForegroundColor Green
} catch {
Write-Host "[Ollama] warm-up loi (bo qua): $($_.Exception.Message)" -ForegroundColor DarkYellow
}
} else {
Write-Host "[Ollama] khong san sang sau 30s - bo qua warm-up" -ForegroundColor DarkYellow
}
# ----------------------------------------------------------------
# 4. JVM env + Spring Boot
# ----------------------------------------------------------------
Write-Host ""
Write-Host "=== Khoi dong Spring Boot (profile=local, Xmx=2g) ===" -ForegroundColor Cyan
Write-Host ""
$env:MAVEN_OPTS = "-Xms256m -Xmx1g"
$jvmArgs = "-Xms512m -Xmx2g -XX:+UseG1GC -XX:MaxMetaspaceSize=512m -XX:+ExitOnOutOfMemoryError"
$springExit = 0
try {
& .\mvnw.cmd spring-boot:run `
"-Dspring-boot.run.arguments=--spring.profiles.active=local" `
"-Dspring-boot.run.jvmArguments=$jvmArgs"
$springExit = $LASTEXITCODE
} finally {
Write-Host ""
Write-Host "=== Spring Boot da dung (exit=$springExit) ===" -ForegroundColor Cyan
if ($nginxAvailable) {
# Read-Host khong support timeout, nen mac dinh giu nginx chay (tuong duong choice /D N)
$stop = Read-Host "Stop nginx? (y/N)"
if ($stop -match '^[Yy]') {
& $nginxExe -p "$nginxDir/" -c "conf/nginx.conf" -s quit 2>$null | Out-Null
Start-Sleep -Milliseconds 800
Get-Process -Name "nginx" -ErrorAction SilentlyContinue | Stop-Process -Force -ErrorAction SilentlyContinue
Write-Host "[Nginx] da stop." -ForegroundColor Green
} else {
Write-Host "[Nginx] van chay tai http://localhost" -ForegroundColor DarkYellow
}
}
}
exit $springExit