param( [switch]$UsePm2, [string]$Pm2Name = "lolympus-agent" ) # [System.Environment]::SetEnvironmentVariable("NODE_ENV", $null) # NODE_ENV 환경 변수가 설정되어 있지 않으면 'dev'로 설정 if (-not $env:NODE_ENV) { $env:NODE_ENV = 'dev' } if ($isMacOS -or $isLinux) { $env:ENV_FILE = "$PSScriptRoot/env-vars/$env:NODE_ENV.env" } elseif ($isWindows) { $env:ENV_FILE = "$PSScriptRoot\env-vars\$env:NODE_ENV.env" } $GLOBAL_ENV_FILE = Join-Path $HOME "source/global-env-vars.txt" function Import-EnvFileIfPresent { param( [string]$Path, [switch]$Required ) if (-Not (Test-Path $Path)) { if ($Required) { Write-Error "The file '$Path' does not exist." exit 1 } return } Get-Content $Path | ForEach-Object { if ($_ -match '^\s*([^#]+?)\s*=\s*(.*)$') { $key, $value = $matches[1].Trim(), $matches[2].Trim().Trim("`"") if (-not [System.Environment]::GetEnvironmentVariable($key)) { [System.Environment]::SetEnvironmentVariable($key, $value) } } } } # 환경 변수 파일 확인 Import-EnvFileIfPresent -Path $GLOBAL_ENV_FILE Import-EnvFileIfPresent -Path $env:ENV_FILE -Required Get-ChildItem Env: | Where-Object { $_.Name -eq "NODE_ENV" -or $_.Name -like "IMDS_*" -or $_.Name -like "METADATA_*" -or $_.Name -eq "MACHINE_ENV_BASE_URL" } if ($UsePm2) { pm2 start ecosystem.config.cjs --only lolympus-agent,lolympus-agent-worker --update-env } else { node ./dist/main.js }