자산관리 시스템 도커라이징
This commit is contained in:
@@ -1,6 +1,49 @@
|
||||
# HM ITAM Server Start Script
|
||||
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
||||
|
||||
function Get-EnvValue {
|
||||
param(
|
||||
[string]$FilePath,
|
||||
[string]$Key
|
||||
)
|
||||
|
||||
if (-not (Test-Path $FilePath)) {
|
||||
return $null
|
||||
}
|
||||
|
||||
$line = Get-Content $FilePath | Where-Object { $_ -match "^$Key=" } | Select-Object -First 1
|
||||
if (-not $line) {
|
||||
return $null
|
||||
}
|
||||
|
||||
return ($line -split '=', 2)[1].Trim()
|
||||
}
|
||||
|
||||
function Test-TcpPortFast {
|
||||
param(
|
||||
[string]$HostName,
|
||||
[int]$Port,
|
||||
[int]$TimeoutMs = 3000
|
||||
)
|
||||
|
||||
$client = New-Object System.Net.Sockets.TcpClient
|
||||
try {
|
||||
$asyncResult = $client.BeginConnect($HostName, $Port, $null, $null)
|
||||
if (-not $asyncResult.AsyncWaitHandle.WaitOne($TimeoutMs, $false)) {
|
||||
$client.Close()
|
||||
return $false
|
||||
}
|
||||
|
||||
$client.EndConnect($asyncResult)
|
||||
$client.Close()
|
||||
return $true
|
||||
}
|
||||
catch {
|
||||
$client.Close()
|
||||
return $false
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host "============================================" -ForegroundColor Cyan
|
||||
Write-Host " HM ITAM System Start" -ForegroundColor Cyan
|
||||
Write-Host "============================================" -ForegroundColor Cyan
|
||||
@@ -21,6 +64,13 @@ if (-not (Test-Path "node_modules")) {
|
||||
Write-Host "[INFO] Checking ports..."
|
||||
$backendPort = 3000
|
||||
$frontendPort = 8080
|
||||
$envFilePath = Join-Path $PSScriptRoot '.env'
|
||||
$dbHost = Get-EnvValue -FilePath $envFilePath -Key 'DB_HOST'
|
||||
$dbPort = Get-EnvValue -FilePath $envFilePath -Key 'DB_PORT'
|
||||
|
||||
if (-not $dbPort) {
|
||||
$dbPort = '3306'
|
||||
}
|
||||
|
||||
if (Get-NetTCPConnection -LocalPort $backendPort -ErrorAction SilentlyContinue) {
|
||||
Write-Host "[WARNING] Port $backendPort [Backend] is already in use." -ForegroundColor Yellow
|
||||
@@ -30,6 +80,21 @@ if (Get-NetTCPConnection -LocalPort $frontendPort -ErrorAction SilentlyContinue)
|
||||
Write-Host "[WARNING] Port $frontendPort [Frontend] is already in use." -ForegroundColor Yellow
|
||||
}
|
||||
|
||||
if (-not $dbHost) {
|
||||
Write-Host "[WARNING] .env is missing DB_HOST. Backend and frontend will still start, but DB calls will fail until DB settings are fixed." -ForegroundColor Yellow
|
||||
}
|
||||
else {
|
||||
Write-Host "[INFO] Checking external DB reachability..."
|
||||
$dbReachable = Test-TcpPortFast -HostName $dbHost -Port ([int]$dbPort)
|
||||
if ($dbReachable) {
|
||||
Write-Host "[INFO] External DB reachable: $dbHost`:$dbPort"
|
||||
}
|
||||
else {
|
||||
Write-Host "[WARNING] External DB is unreachable: $dbHost`:$dbPort" -ForegroundColor Yellow
|
||||
Write-Host "[WARNING] Backend and frontend will still start, but DB-backed screens and APIs may fail." -ForegroundColor Yellow
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "[INFO] Starting Backend [Port: 3000]..."
|
||||
Start-Process cmd -ArgumentList "/k npm run server"
|
||||
|
||||
Reference in New Issue
Block a user