create-entity-server 0.7.11 → 0.9.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,248 +1,248 @@
1
- # Entity Server - Run Script (Windows PowerShell)
2
- param(
3
- [Parameter(Position=0)]
4
- [string]$Mode = ""
5
- )
6
-
7
- $ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
8
- $ProjectRoot = Split-Path -Parent $ScriptDir
9
-
10
- Set-Location $ProjectRoot
11
-
12
- $ServerConfig = Join-Path $ProjectRoot "configs\server.json"
13
- $DatabaseConfig = Join-Path $ProjectRoot "configs\database.json"
14
- $RunDir = Join-Path $ProjectRoot ".run"
15
- $PidFile = Join-Path $RunDir "entity-server.pid"
16
- $StdoutLog = Join-Path $ProjectRoot "logs\server.out.log"
17
-
18
- if (-not (Test-Path $RunDir)) { New-Item -ItemType Directory -Path $RunDir | Out-Null }
19
- if (-not (Test-Path (Join-Path $ProjectRoot "logs"))) { New-Item -ItemType Directory -Path (Join-Path $ProjectRoot "logs") | Out-Null }
20
-
21
- # Load language from .env
22
- $Language = "ko"
23
- $EnvFile = Join-Path $ProjectRoot ".env"
24
- if (Test-Path $EnvFile) {
25
- $LangLine = Get-Content $EnvFile | Where-Object { $_ -match '^LANGUAGE=' } | Select-Object -First 1
26
- if ($LangLine) { $Language = $LangLine -replace '^LANGUAGE=', '' }
27
- }
28
-
29
- function Is-Running {
30
- if (-not (Test-Path $PidFile)) { return $false }
31
- $pid = (Get-Content $PidFile -ErrorAction SilentlyContinue).Trim()
32
- if (-not $pid) { return $false }
33
- try {
34
- $proc = Get-Process -Id ([int]$pid) -ErrorAction Stop
35
- return $true
36
- } catch { return $false }
37
- }
38
-
39
- function Stop-Server {
40
- if (-not (Test-Path $PidFile)) {
41
- if ($Language -eq "en") { Write-Host "i Server is not running (pid file not found)." }
42
- else { Write-Host "i 서버가 실행 중이 아닙니다 (pid 파일 없음)." }
43
- return
44
- }
45
- $pid = (Get-Content $PidFile -ErrorAction SilentlyContinue).Trim()
46
- if (-not $pid) {
47
- Remove-Item $PidFile -Force
48
- if ($Language -eq "en") { Write-Host "i Empty pid file removed." }
49
- else { Write-Host "i 비어있는 pid 파일을 정리했습니다." }
50
- return
51
- }
52
- try {
53
- $proc = Get-Process -Id ([int]$pid) -ErrorAction Stop
54
- $procInfo = "$($proc.Id) $($proc.UserName) $($proc.StartTime) $($proc.ProcessName)"
55
- if ($Language -eq "en") {
56
- Write-Host "Running process:"
57
- Write-Host " PID ELAPSED COMMAND"
58
- Write-Host " $procInfo"
59
- Write-Host ""
60
- $input = Read-Host "Stop this process? [y/N]"
61
- } else {
62
- Write-Host "실행 중인 프로세스:"
63
- Write-Host " PID 실행시간 COMMAND"
64
- Write-Host " $procInfo"
65
- Write-Host ""
66
- $input = Read-Host "이 프로세스를 중지할까요? [y/N]"
67
- }
68
- if ($input -notmatch '^[Yy](es)?$') {
69
- if ($Language -eq "en") { Write-Host "Canceled." }
70
- else { Write-Host "취소되었습니다." }
71
- return
72
- }
73
- Stop-Process -Id ([int]$pid) -Force
74
- Remove-Item $PidFile -Force
75
- if ($Language -eq "en") { Write-Host "OK Server stopped (pid: $pid)" }
76
- else { Write-Host "OK 서버가 중지되었습니다 (pid: $pid)" }
77
- } catch {
78
- Remove-Item $PidFile -Force -ErrorAction SilentlyContinue
79
- if ($Language -eq "en") { Write-Host "i Stale pid file removed (process not found)." }
80
- else { Write-Host "i 실행 중인 프로세스가 없어 stale pid 파일을 정리했습니다." }
81
- }
82
- }
83
-
84
- function Show-Status {
85
- $ServerBin = Join-Path $ProjectRoot "bin\entity-server.exe"
86
- if (-not (Test-Path $ServerBin)) {
87
- $LegacyBin = Join-Path $ProjectRoot "entity-server.exe"
88
- if (Test-Path $LegacyBin) { $ServerBin = $LegacyBin }
89
- }
90
- if (Is-Running) {
91
- & $ServerBin banner-status RUNNING
92
- if ($Language -eq "en") { Write-Host "Stop: .\run.ps1 stop" }
93
- else { Write-Host "중지: .\run.ps1 stop" }
94
- } else {
95
- & $ServerBin banner-status STOPPED
96
- if ($Language -eq "en") { Write-Host "Start: .\run.ps1 start" }
97
- else { Write-Host "시작: .\run.ps1 start" }
98
- }
99
- }
100
-
101
- if (-not $Mode) {
102
- if ($Language -eq "en") {
103
- Write-Host "Entity Server - Run Script"
104
- Write-Host "=========================="
105
- Write-Host ""
106
- Write-Host "Force configs/server.json environment and configs/database.json default group, then start compiled server binary."
107
- Write-Host ""
108
- Write-Host "Usage: .\run.ps1 <mode>"
109
- Write-Host ""
110
- Write-Host "Modes:"
111
- Write-Host " dev environment=development, database.default=development, then run binary"
112
- Write-Host " start environment=production, database.default=production, then run in background"
113
- Write-Host " stop stop background server started by this script"
114
- Write-Host " status show server status"
115
- Write-Host ""
116
- Write-Host "Examples:"
117
- Write-Host " .\run.ps1 dev"
118
- Write-Host " .\run.ps1 start"
119
- Write-Host " .\run.ps1 stop"
120
- Write-Host " .\run.ps1 status"
121
- } else {
122
- Write-Host "Entity Server - 실행 스크립트"
123
- Write-Host "==========================="
124
- Write-Host ""
125
- Write-Host "configs/server.json의 environment와 configs/database.json의 default를 강제 설정하고 바이너리를 실행합니다."
126
- Write-Host ""
127
- Write-Host "사용법: .\run.ps1 <모드>"
128
- Write-Host ""
129
- Write-Host "모드:"
130
- Write-Host " dev environment=development, database.default=development 강제 후 바이너리 실행"
131
- Write-Host " start environment=production, database.default=production 강제 후 백그라운드 실행"
132
- Write-Host " stop run.ps1로 백그라운드 실행한 서버 중지"
133
- Write-Host " status 서버 상태 조회"
134
- Write-Host ""
135
- Write-Host "예제:"
136
- Write-Host " .\run.ps1 dev"
137
- Write-Host " .\run.ps1 start"
138
- Write-Host " .\run.ps1 stop"
139
- Write-Host " .\run.ps1 status"
140
- }
141
- exit 0
142
- }
143
-
144
- if (-not (Test-Path $ServerConfig)) {
145
- if ($Language -eq "en") { Write-Host "X configs/server.json not found" }
146
- else { Write-Host "X configs/server.json 파일이 없습니다" }
147
- exit 1
148
- }
149
- if (-not (Test-Path $DatabaseConfig)) {
150
- if ($Language -eq "en") { Write-Host "X configs/database.json not found" }
151
- else { Write-Host "X configs/database.json 파일이 없습니다" }
152
- exit 1
153
- }
154
- $ServerBin = Join-Path $ProjectRoot "bin\entity-server.exe"
155
- if (-not (Test-Path $ServerBin)) {
156
- $LegacyBin = Join-Path $ProjectRoot "entity-server.exe"
157
- if (Test-Path $LegacyBin) {
158
- $ServerBin = $LegacyBin
159
- } else {
160
- if ($Language -eq "en") { Write-Host "X entity-server.exe not found (bin/entity-server.exe or .\entity-server.exe)" }
161
- else { Write-Host "X entity-server.exe 파일이 없습니다 (bin/entity-server.exe 또는 .\entity-server.exe)" }
162
- exit 1
163
- }
164
- }
165
-
166
- function Update-JsonField {
167
- param([string]$File, [string]$Key, [string]$Value)
168
- $content = Get-Content $File -Raw
169
- $content = $content -replace "(`"$Key`"\s*:\s*`")[^`"]+(`")", "`${1}$Value`${2}"
170
- Set-Content $File $content -NoNewline
171
- }
172
-
173
- switch ($Mode) {
174
- { $_ -in @("dev", "development") } {
175
- if (Is-Running) {
176
- $pid = (Get-Content $PidFile).Trim()
177
- if ($Language -eq "en") { Write-Host "X Server already running (pid: $pid). Stop first: .\run.ps1 stop" }
178
- else { Write-Host "X 이미 서버가 실행 중입니다 (pid: $pid). 먼저 중지하세요: .\run.ps1 stop" }
179
- exit 1
180
- }
181
- $dbContent = Get-Content $DatabaseConfig -Raw
182
- if ($dbContent -notmatch '"development"\s*:') {
183
- if ($Language -eq "en") { Write-Host "X database group 'development' not found in configs/database.json" }
184
- else { Write-Host "X configs/database.json에 'development' 그룹이 없습니다" }
185
- exit 1
186
- }
187
- Update-JsonField $ServerConfig "environment" "development"
188
- Update-JsonField $DatabaseConfig "default" "development"
189
- & $ServerBin
190
- }
191
-
192
- "start" {
193
- if (Is-Running) {
194
- $pid = (Get-Content $PidFile).Trim()
195
- if ($Language -eq "en") { Write-Host "X Server already running (pid: $pid). Stop first: .\run.ps1 stop" }
196
- else { Write-Host "X 이미 서버가 실행 중입니다 (pid: $pid). 먼저 중지하세요: .\run.ps1 stop" }
197
- exit 1
198
- }
199
- $dbContent = Get-Content $DatabaseConfig -Raw
200
- if ($dbContent -notmatch '"production"\s*:') {
201
- if ($Language -eq "en") { Write-Host "X database group 'production' not found in configs/database.json" }
202
- else { Write-Host "X configs/database.json에 'production' 그룹이 없습니다" }
203
- exit 1
204
- }
205
- Update-JsonField $ServerConfig "environment" "production"
206
- Update-JsonField $DatabaseConfig "default" "production"
207
- & $ServerBin banner
208
- $proc = Start-Process -FilePath $ServerBin -RedirectStandardOutput $StdoutLog -RedirectStandardError $StdoutLog -WindowStyle Hidden -PassThru
209
- $proc.Id | Set-Content $PidFile
210
- Start-Sleep -Milliseconds 300
211
- try {
212
- $check = Get-Process -Id $proc.Id -ErrorAction Stop
213
- if ($Language -eq "en") {
214
- Write-Host "OK Entity Server started in background (pid: $($proc.Id))"
215
- Write-Host "Status: .\run.ps1 status"
216
- } else {
217
- Write-Host "OK Entity Server가 백그라운드에서 시작되었습니다 (pid: $($proc.Id))"
218
- Write-Host "상태: .\run.ps1 status"
219
- Write-Host "중지: .\run.ps1 stop"
220
- }
221
- } catch {
222
- Remove-Item $PidFile -Force
223
- if ($Language -eq "en") {
224
- Write-Host "X Failed to start Entity Server in background"
225
- Write-Host "Check logs: $StdoutLog"
226
- } else {
227
- Write-Host "X Entity Server 백그라운드 시작에 실패했습니다"
228
- Write-Host "로그 확인: $StdoutLog"
229
- }
230
- exit 1
231
- }
232
- }
233
-
234
- "stop" { Stop-Server }
235
-
236
- "status" { Show-Status }
237
-
238
- default {
239
- if ($Language -eq "en") {
240
- Write-Host "X Unknown mode: $Mode"
241
- Write-Host "Run '.\run.ps1' for usage information"
242
- } else {
243
- Write-Host "X 알 수 없는 모드: $Mode"
244
- Write-Host "'.\run.ps1'로 사용법을 확인하세요"
245
- }
246
- exit 1
247
- }
248
- }
1
+ # Entity Server - Run Script (Windows PowerShell)
2
+ param(
3
+ [Parameter(Position=0)]
4
+ [string]$Mode = ""
5
+ )
6
+
7
+ $ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
8
+ $ProjectRoot = Split-Path -Parent $ScriptDir
9
+
10
+ Set-Location $ProjectRoot
11
+
12
+ $ServerConfig = Join-Path $ProjectRoot "configs\server.json"
13
+ $DatabaseConfig = Join-Path $ProjectRoot "configs\database.json"
14
+ $RunDir = Join-Path $ProjectRoot ".run"
15
+ $PidFile = Join-Path $RunDir "entity-server.pid"
16
+ $StdoutLog = Join-Path $ProjectRoot "logs\server.out.log"
17
+
18
+ if (-not (Test-Path $RunDir)) { New-Item -ItemType Directory -Path $RunDir | Out-Null }
19
+ if (-not (Test-Path (Join-Path $ProjectRoot "logs"))) { New-Item -ItemType Directory -Path (Join-Path $ProjectRoot "logs") | Out-Null }
20
+
21
+ # Load language from .env
22
+ $Language = "ko"
23
+ $EnvFile = Join-Path $ProjectRoot ".env"
24
+ if (Test-Path $EnvFile) {
25
+ $LangLine = Get-Content $EnvFile | Where-Object { $_ -match '^LANGUAGE=' } | Select-Object -First 1
26
+ if ($LangLine) { $Language = $LangLine -replace '^LANGUAGE=', '' }
27
+ }
28
+
29
+ function Is-Running {
30
+ if (-not (Test-Path $PidFile)) { return $false }
31
+ $pid = (Get-Content $PidFile -ErrorAction SilentlyContinue).Trim()
32
+ if (-not $pid) { return $false }
33
+ try {
34
+ $proc = Get-Process -Id ([int]$pid) -ErrorAction Stop
35
+ return $true
36
+ } catch { return $false }
37
+ }
38
+
39
+ function Stop-Server {
40
+ if (-not (Test-Path $PidFile)) {
41
+ if ($Language -eq "en") { Write-Host "i Server is not running (pid file not found)." }
42
+ else { Write-Host "i 서버가 실행 중이 아닙니다 (pid 파일 없음)." }
43
+ return
44
+ }
45
+ $pid = (Get-Content $PidFile -ErrorAction SilentlyContinue).Trim()
46
+ if (-not $pid) {
47
+ Remove-Item $PidFile -Force
48
+ if ($Language -eq "en") { Write-Host "i Empty pid file removed." }
49
+ else { Write-Host "i 비어있는 pid 파일을 정리했습니다." }
50
+ return
51
+ }
52
+ try {
53
+ $proc = Get-Process -Id ([int]$pid) -ErrorAction Stop
54
+ $procInfo = "$($proc.Id) $($proc.UserName) $($proc.StartTime) $($proc.ProcessName)"
55
+ if ($Language -eq "en") {
56
+ Write-Host "Running process:"
57
+ Write-Host " PID ELAPSED COMMAND"
58
+ Write-Host " $procInfo"
59
+ Write-Host ""
60
+ $input = Read-Host "Stop this process? [y/N]"
61
+ } else {
62
+ Write-Host "실행 중인 프로세스:"
63
+ Write-Host " PID 실행시간 COMMAND"
64
+ Write-Host " $procInfo"
65
+ Write-Host ""
66
+ $input = Read-Host "이 프로세스를 중지할까요? [y/N]"
67
+ }
68
+ if ($input -notmatch '^[Yy](es)?$') {
69
+ if ($Language -eq "en") { Write-Host "Canceled." }
70
+ else { Write-Host "취소되었습니다." }
71
+ return
72
+ }
73
+ Stop-Process -Id ([int]$pid) -Force
74
+ Remove-Item $PidFile -Force
75
+ if ($Language -eq "en") { Write-Host "OK Server stopped (pid: $pid)" }
76
+ else { Write-Host "OK 서버가 중지되었습니다 (pid: $pid)" }
77
+ } catch {
78
+ Remove-Item $PidFile -Force -ErrorAction SilentlyContinue
79
+ if ($Language -eq "en") { Write-Host "i Stale pid file removed (process not found)." }
80
+ else { Write-Host "i 실행 중인 프로세스가 없어 stale pid 파일을 정리했습니다." }
81
+ }
82
+ }
83
+
84
+ function Show-Status {
85
+ $ServerBin = Join-Path $ProjectRoot "bin\entity-server.exe"
86
+ if (-not (Test-Path $ServerBin)) {
87
+ $LegacyBin = Join-Path $ProjectRoot "entity-server.exe"
88
+ if (Test-Path $LegacyBin) { $ServerBin = $LegacyBin }
89
+ }
90
+ if (Is-Running) {
91
+ & $ServerBin banner-status RUNNING
92
+ if ($Language -eq "en") { Write-Host "Stop: .\run.ps1 stop" }
93
+ else { Write-Host "중지: .\run.ps1 stop" }
94
+ } else {
95
+ & $ServerBin banner-status STOPPED
96
+ if ($Language -eq "en") { Write-Host "Start: .\run.ps1 start" }
97
+ else { Write-Host "시작: .\run.ps1 start" }
98
+ }
99
+ }
100
+
101
+ if (-not $Mode) {
102
+ if ($Language -eq "en") {
103
+ Write-Host "Entity Server - Run Script"
104
+ Write-Host "=========================="
105
+ Write-Host ""
106
+ Write-Host "Force configs/server.json environment and configs/database.json default group, then start compiled server binary."
107
+ Write-Host ""
108
+ Write-Host "Usage: .\run.ps1 <mode>"
109
+ Write-Host ""
110
+ Write-Host "Modes:"
111
+ Write-Host " dev environment=development, database.default=development, then run binary"
112
+ Write-Host " start environment=production, database.default=production, then run in background"
113
+ Write-Host " stop stop background server started by this script"
114
+ Write-Host " status show server status"
115
+ Write-Host ""
116
+ Write-Host "Examples:"
117
+ Write-Host " .\run.ps1 dev"
118
+ Write-Host " .\run.ps1 start"
119
+ Write-Host " .\run.ps1 stop"
120
+ Write-Host " .\run.ps1 status"
121
+ } else {
122
+ Write-Host "Entity Server - 실행 스크립트"
123
+ Write-Host "==========================="
124
+ Write-Host ""
125
+ Write-Host "configs/server.json의 environment와 configs/database.json의 default를 강제 설정하고 바이너리를 실행합니다."
126
+ Write-Host ""
127
+ Write-Host "사용법: .\run.ps1 <모드>"
128
+ Write-Host ""
129
+ Write-Host "모드:"
130
+ Write-Host " dev environment=development, database.default=development 강제 후 바이너리 실행"
131
+ Write-Host " start environment=production, database.default=production 강제 후 백그라운드 실행"
132
+ Write-Host " stop run.ps1로 백그라운드 실행한 서버 중지"
133
+ Write-Host " status 서버 상태 조회"
134
+ Write-Host ""
135
+ Write-Host "예제:"
136
+ Write-Host " .\run.ps1 dev"
137
+ Write-Host " .\run.ps1 start"
138
+ Write-Host " .\run.ps1 stop"
139
+ Write-Host " .\run.ps1 status"
140
+ }
141
+ exit 0
142
+ }
143
+
144
+ if (-not (Test-Path $ServerConfig)) {
145
+ if ($Language -eq "en") { Write-Host "X configs/server.json not found" }
146
+ else { Write-Host "X configs/server.json 파일이 없습니다" }
147
+ exit 1
148
+ }
149
+ if (-not (Test-Path $DatabaseConfig)) {
150
+ if ($Language -eq "en") { Write-Host "X configs/database.json not found" }
151
+ else { Write-Host "X configs/database.json 파일이 없습니다" }
152
+ exit 1
153
+ }
154
+ $ServerBin = Join-Path $ProjectRoot "bin\entity-server.exe"
155
+ if (-not (Test-Path $ServerBin)) {
156
+ $LegacyBin = Join-Path $ProjectRoot "entity-server.exe"
157
+ if (Test-Path $LegacyBin) {
158
+ $ServerBin = $LegacyBin
159
+ } else {
160
+ if ($Language -eq "en") { Write-Host "X entity-server.exe not found (bin/entity-server.exe or .\entity-server.exe)" }
161
+ else { Write-Host "X entity-server.exe 파일이 없습니다 (bin/entity-server.exe 또는 .\entity-server.exe)" }
162
+ exit 1
163
+ }
164
+ }
165
+
166
+ function Update-JsonField {
167
+ param([string]$File, [string]$Key, [string]$Value)
168
+ $content = Get-Content $File -Raw
169
+ $content = $content -replace "(`"$Key`"\s*:\s*`")[^`"]+(`")", "`${1}$Value`${2}"
170
+ Set-Content $File $content -NoNewline
171
+ }
172
+
173
+ switch ($Mode) {
174
+ { $_ -in @("dev", "development") } {
175
+ if (Is-Running) {
176
+ $pid = (Get-Content $PidFile).Trim()
177
+ if ($Language -eq "en") { Write-Host "X Server already running (pid: $pid). Stop first: .\run.ps1 stop" }
178
+ else { Write-Host "X 이미 서버가 실행 중입니다 (pid: $pid). 먼저 중지하세요: .\run.ps1 stop" }
179
+ exit 1
180
+ }
181
+ $dbContent = Get-Content $DatabaseConfig -Raw
182
+ if ($dbContent -notmatch '"development"\s*:') {
183
+ if ($Language -eq "en") { Write-Host "X database group 'development' not found in configs/database.json" }
184
+ else { Write-Host "X configs/database.json에 'development' 그룹이 없습니다" }
185
+ exit 1
186
+ }
187
+ Update-JsonField $ServerConfig "environment" "development"
188
+ Update-JsonField $DatabaseConfig "default" "development"
189
+ & $ServerBin
190
+ }
191
+
192
+ "start" {
193
+ if (Is-Running) {
194
+ $pid = (Get-Content $PidFile).Trim()
195
+ if ($Language -eq "en") { Write-Host "X Server already running (pid: $pid). Stop first: .\run.ps1 stop" }
196
+ else { Write-Host "X 이미 서버가 실행 중입니다 (pid: $pid). 먼저 중지하세요: .\run.ps1 stop" }
197
+ exit 1
198
+ }
199
+ $dbContent = Get-Content $DatabaseConfig -Raw
200
+ if ($dbContent -notmatch '"production"\s*:') {
201
+ if ($Language -eq "en") { Write-Host "X database group 'production' not found in configs/database.json" }
202
+ else { Write-Host "X configs/database.json에 'production' 그룹이 없습니다" }
203
+ exit 1
204
+ }
205
+ Update-JsonField $ServerConfig "environment" "production"
206
+ Update-JsonField $DatabaseConfig "default" "production"
207
+ & $ServerBin banner
208
+ $proc = Start-Process -FilePath $ServerBin -RedirectStandardOutput $StdoutLog -RedirectStandardError $StdoutLog -WindowStyle Hidden -PassThru
209
+ $proc.Id | Set-Content $PidFile
210
+ Start-Sleep -Milliseconds 300
211
+ try {
212
+ $check = Get-Process -Id $proc.Id -ErrorAction Stop
213
+ if ($Language -eq "en") {
214
+ Write-Host "OK Entity Server started in background (pid: $($proc.Id))"
215
+ Write-Host "Status: .\run.ps1 status"
216
+ } else {
217
+ Write-Host "OK Entity Server가 백그라운드에서 시작되었습니다 (pid: $($proc.Id))"
218
+ Write-Host "상태: .\run.ps1 status"
219
+ Write-Host "중지: .\run.ps1 stop"
220
+ }
221
+ } catch {
222
+ Remove-Item $PidFile -Force
223
+ if ($Language -eq "en") {
224
+ Write-Host "X Failed to start Entity Server in background"
225
+ Write-Host "Check logs: $StdoutLog"
226
+ } else {
227
+ Write-Host "X Entity Server 백그라운드 시작에 실패했습니다"
228
+ Write-Host "로그 확인: $StdoutLog"
229
+ }
230
+ exit 1
231
+ }
232
+ }
233
+
234
+ "stop" { Stop-Server }
235
+
236
+ "status" { Show-Status }
237
+
238
+ default {
239
+ if ($Language -eq "en") {
240
+ Write-Host "X Unknown mode: $Mode"
241
+ Write-Host "Run '.\run.ps1' for usage information"
242
+ } else {
243
+ Write-Host "X 알 수 없는 모드: $Mode"
244
+ Write-Host "'.\run.ps1'로 사용법을 확인하세요"
245
+ }
246
+ exit 1
247
+ }
248
+ }
@@ -19,8 +19,12 @@ fi
19
19
  mkdir -p "$RUN_DIR" "$PROJECT_ROOT/logs"
20
20
  SERVER_NAME="Entity Server"
21
21
 
22
- # Load language from .env
22
+ # Load environment from .env
23
23
  if [ -f .env ]; then
24
+ set -o allexport
25
+ # shellcheck disable=SC1091
26
+ source .env
27
+ set +o allexport
24
28
  LANGUAGE=$(grep '^LANGUAGE=' .env | cut -d '=' -f2)
25
29
  fi
26
30
  LANGUAGE=${LANGUAGE:-ko}
@@ -29,20 +33,25 @@ has_command() {
29
33
  command -v "$1" >/dev/null 2>&1
30
34
  }
31
35
 
32
- # 현재 프로젝트를 관리하는 systemd 서비스명을 반환합니다.
36
+ # 현재 프로젝트를 관리하는 systemd 서비스명을 반환합니다 (상태 무관).
33
37
  find_systemd_service() {
34
- local unit=""
35
- local exec_start=""
36
-
37
38
  has_command systemctl || return 1
38
39
 
39
- for unit in $(systemctl list-units --type=service --state=active,activating --no-legend 2>/dev/null | awk '{print $1}'); do
40
- exec_start=$(systemctl show -p ExecStart --value "$unit" 2>/dev/null || true)
41
- if [[ "$exec_start" == *"$PROJECT_ROOT/scripts/run.sh"* ]] || [[ "$exec_start" == *"$SERVER_BIN"* ]]; then
42
- echo "$unit"
43
- return 0
44
- fi
45
- done
40
+ local namespace="${SERVER_NAMESPACE:-${NAMESPACE:-}}"
41
+ if [ -z "$namespace" ] && [ -f "$SERVER_CONFIG" ]; then
42
+ namespace=$(sed -n 's/.*"namespace"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' "$SERVER_CONFIG" | head -n 1)
43
+ fi
44
+ namespace=$(echo "$namespace" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9_-]/-/g')
45
+ [ -z "$namespace" ] && namespace="default"
46
+
47
+ local svc_name="${namespace}-entity-server.service"
48
+ local exec_start=""
49
+ exec_start=$(systemctl show -p ExecStart --value "$svc_name" 2>/dev/null || true)
50
+
51
+ if [[ "$exec_start" == *"$PROJECT_ROOT/scripts/run.sh"* ]] || [[ "$exec_start" == *"$SERVER_BIN"* ]]; then
52
+ echo "$svc_name"
53
+ return 0
54
+ fi
46
55
 
47
56
  return 1
48
57
  }
@@ -462,11 +471,17 @@ stop_server() {
462
471
  local svc=""
463
472
  svc=$(find_systemd_service || true)
464
473
  if [ -n "$svc" ]; then
465
- echo "ℹ️ systemd 서비스 중지: $svc"
466
- sudo systemctl stop "$svc"
474
+ local svc_state=""
475
+ svc_state=$(systemctl is-active "$svc" 2>/dev/null || true)
476
+ if [ "$svc_state" = "active" ] || [ "$svc_state" = "activating" ]; then
477
+ echo "ℹ️ systemd 서비스 중지: $svc"
478
+ sudo systemctl stop "$svc"
479
+ rm -f "$PID_FILE"
480
+ echo "✅ ${SERVER_NAME} 종료 완료 (systemd)"
481
+ return 0
482
+ fi
483
+ # systemd 서비스가 inactive 이어도 고아 프로세스가 남아 있을 수 있으므로 아래로 진행
467
484
  rm -f "$PID_FILE"
468
- echo "✅ ${SERVER_NAME} 종료 완료 (systemd)"
469
- return 0
470
485
  fi
471
486
 
472
487
  local pid=""
@@ -475,11 +490,25 @@ stop_server() {
475
490
  rm -f "$PID_FILE"
476
491
 
477
492
  if [ -n "$pid" ]; then
493
+ if [ -n "$svc" ]; then
494
+ if [ "$LANGUAGE" = "en" ]; then
495
+ echo "⚠️ systemd service ($svc) is inactive, but an orphan process was found."
496
+ else
497
+ echo "⚠️ systemd 서비스($svc)는 비활성이지만, 고아 프로세스가 발견되었습니다."
498
+ fi
499
+ fi
478
500
  stop_pid_with_confirm "$pid" "active process"
479
501
  return $?
480
502
  fi
481
503
 
482
504
  if is_port_in_use; then
505
+ if [ -n "$svc" ]; then
506
+ if [ "$LANGUAGE" = "en" ]; then
507
+ echo "⚠️ systemd service ($svc) is inactive, but the port is in use."
508
+ else
509
+ echo "⚠️ systemd 서비스($svc)는 비활성이지만, 포트가 사용 중입니다."
510
+ fi
511
+ fi
483
512
  show_unmanaged_server_message
484
513
  return 1
485
514
  fi
@@ -497,9 +526,14 @@ show_status() {
497
526
  local svc=""
498
527
  svc=$(find_systemd_service || true)
499
528
  if [ -n "$svc" ]; then
500
- echo "ℹ️ systemd 서비스로 관리 중: $svc"
501
- sudo systemctl status "$svc" --no-pager 2>/dev/null || true
502
- return
529
+ local svc_state=""
530
+ svc_state=$(systemctl is-active "$svc" 2>/dev/null || true)
531
+ if [ "$svc_state" = "active" ] || [ "$svc_state" = "activating" ]; then
532
+ echo "ℹ️ systemd 서비스로 관리 중: $svc"
533
+ sudo systemctl status "$svc" --no-pager 2>/dev/null || true
534
+ return
535
+ fi
536
+ # systemd inactive 일 때 고아 프로세스 여부까지 확인
503
537
  fi
504
538
 
505
539
  local status_pid=""
@@ -507,6 +541,13 @@ show_status() {
507
541
  status_pid=$(find_active_server_pid || true)
508
542
  if [ -n "$status_pid" ]; then
509
543
  "$SERVER_BIN" banner-status RUNNING
544
+ if [ -n "$svc" ]; then
545
+ if [ "$LANGUAGE" = "en" ]; then
546
+ echo "⚠️ systemd service ($svc) is inactive, but an orphan process is running."
547
+ else
548
+ echo "⚠️ systemd 서비스($svc)는 비활성이지만, 고아 프로세스가 실행 중입니다."
549
+ fi
550
+ fi
510
551
  if [ "$LANGUAGE" = "en" ]; then
511
552
  echo "PID: $status_pid (managed process)"
512
553
  echo "Stop: ./run.sh stop"
@@ -519,6 +560,9 @@ show_status() {
519
560
  if is_port_in_use; then
520
561
  show_unmanaged_server_message
521
562
  fi
563
+ if [ -n "$svc" ]; then
564
+ echo "ℹ️ systemd 서비스: $svc (inactive)"
565
+ fi
522
566
  if [ "$LANGUAGE" = "en" ]; then
523
567
  echo "Start: ./run.sh start"
524
568
  else
@@ -641,6 +685,12 @@ case "$MODE" in
641
685
  ;;
642
686
 
643
687
  start)
688
+ # systemd 에서 ExecStart 로 호출된 경우 바이너리를 직접 exec 한다.
689
+ if [ -n "${INVOCATION_ID:-}" ]; then
690
+ sync_database_default_for_environment "$LINENO" || exit 1
691
+ exec "$SERVER_BIN"
692
+ fi
693
+
644
694
  # systemd 서비스가 등록되어 있으면 systemctl 로 관리한다.
645
695
  svc=$(find_systemd_service || true)
646
696
  if [ -n "$svc" ]; then