langmart-gateway-type3 3.0.9 → 3.0.11
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.
- package/README.md +7 -7
- package/dist/{devops-tools.d.ts → automation-tools.d.ts} +8 -8
- package/dist/automation-tools.d.ts.map +1 -0
- package/dist/{devops-tools.js → automation-tools.js} +34 -34
- package/dist/automation-tools.js.map +1 -0
- package/dist/gateway-mode.d.ts +1 -1
- package/dist/gateway-mode.js +3 -3
- package/dist/gateway-mode.js.map +1 -1
- package/dist/gateway-server.d.ts +2 -2
- package/dist/gateway-server.js +3 -3
- package/dist/gateway-server.js.map +1 -1
- package/dist/headless-session.d.ts +5 -5
- package/dist/headless-session.d.ts.map +1 -1
- package/dist/headless-session.js +17 -17
- package/dist/headless-session.js.map +1 -1
- package/package.json +9 -5
- package/scripts/install-service.ps1 +187 -0
- package/scripts/install-service.sh +166 -0
- package/scripts/install.ps1 +5 -5
- package/scripts/install.sh +4 -4
- package/scripts/remove-service.ps1 +104 -0
- package/scripts/remove-service.sh +79 -0
- package/scripts/start.ps1 +112 -110
- package/scripts/start.sh +241 -72
- package/scripts/status.ps1 +77 -174
- package/scripts/status.sh +125 -52
- package/scripts/stop.ps1 +78 -84
- package/scripts/stop.sh +120 -42
- package/dist/devops-tools.d.ts.map +0 -1
- package/dist/devops-tools.js.map +0 -1
package/scripts/status.ps1
CHANGED
|
@@ -1,211 +1,114 @@
|
|
|
1
|
-
#
|
|
2
|
-
#
|
|
3
|
-
# Output format is designed to be parseable for remote status checks
|
|
1
|
+
# Gateway Type 3 Status Script for Windows
|
|
2
|
+
# Features: Service mode detection, health check, RESULT output
|
|
4
3
|
|
|
5
|
-
param(
|
|
6
|
-
[int]$Port = 8083,
|
|
7
|
-
[switch]$Json,
|
|
8
|
-
[switch]$Brief
|
|
9
|
-
)
|
|
10
|
-
|
|
11
|
-
# Get script/project directory
|
|
12
4
|
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
13
5
|
$ProjectDir = Split-Path -Parent $ScriptDir
|
|
6
|
+
$InstallDir = if ($ProjectDir -like "*node_modules*") { (Get-Location).Path } else { $ProjectDir }
|
|
7
|
+
|
|
8
|
+
$EnvFile = Join-Path $InstallDir ".env"
|
|
9
|
+
$PidFile = Join-Path $InstallDir "gateway.pid"
|
|
10
|
+
$LogFile = Join-Path $InstallDir "logs\gateway.log"
|
|
11
|
+
$ServiceModeFile = Join-Path $InstallDir ".service-mode"
|
|
12
|
+
$ServiceName = "LangMartGateway"
|
|
13
|
+
|
|
14
|
+
function Write-Log { param([string]$Message, [string]$Type = "INFO"); Write-Output "[$Type] $(Get-Date -Format 'HH:mm:ss') - $Message" }
|
|
14
15
|
|
|
15
|
-
|
|
16
|
-
if (
|
|
17
|
-
|
|
16
|
+
function Test-ServiceMode {
|
|
17
|
+
if (Test-Path $ServiceModeFile) {
|
|
18
|
+
$mode = Get-Content $ServiceModeFile -ErrorAction SilentlyContinue
|
|
19
|
+
if ($mode -eq "windows-service") {
|
|
20
|
+
if (Get-Service -Name $ServiceName -ErrorAction SilentlyContinue) { return $true }
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return $false
|
|
18
24
|
}
|
|
19
25
|
|
|
20
|
-
# Load .env
|
|
21
|
-
$EnvFile = Join-Path $ProjectDir ".env"
|
|
22
|
-
$envVars = @{}
|
|
26
|
+
# Load .env for GATEWAY_PORT
|
|
23
27
|
if (Test-Path $EnvFile) {
|
|
24
28
|
Get-Content $EnvFile | ForEach-Object {
|
|
25
|
-
if ($_ -match '^([
|
|
26
|
-
$
|
|
27
|
-
$value = $matches[2].Trim()
|
|
28
|
-
$envVars[$key] = $value
|
|
29
|
-
if ($key -eq "GATEWAY_PORT" -and $Port -eq 8083 -and $value) {
|
|
30
|
-
$Port = [int]$value
|
|
31
|
-
}
|
|
29
|
+
if ($_ -match '^([^#=]+)=(.*)$') {
|
|
30
|
+
[Environment]::SetEnvironmentVariable($matches[1].Trim(), $matches[2].Trim().Trim('"').Trim("'"), 'Process')
|
|
32
31
|
}
|
|
33
32
|
}
|
|
34
33
|
}
|
|
35
34
|
|
|
36
|
-
|
|
37
|
-
$status = @{
|
|
38
|
-
running = $false
|
|
39
|
-
port = $Port
|
|
40
|
-
pid = $null
|
|
41
|
-
health = $false
|
|
42
|
-
version = $null
|
|
43
|
-
gateway_id = $null
|
|
44
|
-
gateway_name = $null
|
|
45
|
-
installed = $false
|
|
46
|
-
mode = "direct"
|
|
47
|
-
error = $null
|
|
48
|
-
}
|
|
35
|
+
$GatewayPort = if ($env:GATEWAY_PORT) { [int]$env:GATEWAY_PORT } else { 8083 }
|
|
49
36
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
if (-not $Json) {
|
|
54
|
-
Write-Output "[$Type] $Message"
|
|
55
|
-
}
|
|
56
|
-
}
|
|
37
|
+
Write-Log "=== Gateway Type 3 Status ==="
|
|
38
|
+
Write-Log "Install directory: $InstallDir"
|
|
39
|
+
Write-Log "Port: $GatewayPort"
|
|
57
40
|
|
|
58
|
-
#
|
|
59
|
-
$
|
|
60
|
-
if (
|
|
61
|
-
|
|
62
|
-
$
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
41
|
+
# CHECK SERVICE MODE
|
|
42
|
+
$serviceMode = Test-ServiceMode
|
|
43
|
+
if ($serviceMode) {
|
|
44
|
+
Write-Log "Mode: Service (Windows Service)"
|
|
45
|
+
$service = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue
|
|
46
|
+
Write-Log "Service status: $($service.Status)"
|
|
47
|
+
Write-Log "Service startup: $($service.StartType)"
|
|
48
|
+
} else {
|
|
49
|
+
Write-Log "Mode: Standalone"
|
|
66
50
|
}
|
|
67
51
|
|
|
68
|
-
#
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
$pkg = Get-Content $PackageJson | ConvertFrom-Json
|
|
73
|
-
$status.version = $pkg.version
|
|
74
|
-
} catch {}
|
|
75
|
-
}
|
|
52
|
+
# Check if running on port
|
|
53
|
+
try {
|
|
54
|
+
$existingPID = (Get-NetTCPConnection -LocalPort $GatewayPort -State Listen -ErrorAction SilentlyContinue).OwningProcess | Select-Object -First 1
|
|
55
|
+
} catch { $existingPID = $null }
|
|
76
56
|
|
|
77
|
-
|
|
78
|
-
$ConfigFile = Join-Path $ProjectDir "gateway-config.json"
|
|
79
|
-
if (Test-Path $ConfigFile) {
|
|
80
|
-
try {
|
|
81
|
-
$config = Get-Content $ConfigFile | ConvertFrom-Json
|
|
82
|
-
$status.gateway_id = $config.gatewayId
|
|
83
|
-
$status.gateway_name = $config.gatewayName
|
|
84
|
-
} catch {}
|
|
85
|
-
}
|
|
57
|
+
$modeStr = if ($serviceMode) { "service" } else { "standalone" }
|
|
86
58
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
$status.running = $true
|
|
92
|
-
$status.pid = $existingPID
|
|
93
|
-
}
|
|
94
|
-
} catch {
|
|
95
|
-
$status.error = $_.Exception.Message
|
|
96
|
-
}
|
|
59
|
+
if ($existingPID) {
|
|
60
|
+
Write-Log "Status: RUNNING" "SUCCESS"
|
|
61
|
+
Write-Log "PID: $existingPID"
|
|
62
|
+
Write-Log "Port: $GatewayPort"
|
|
97
63
|
|
|
98
|
-
# Check health
|
|
99
|
-
if ($status.running) {
|
|
64
|
+
# Check health endpoint
|
|
100
65
|
try {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
if ($health.version) {
|
|
104
|
-
$status.version = $health.version
|
|
105
|
-
}
|
|
106
|
-
if ($health.gateway_id) {
|
|
107
|
-
$status.gateway_id = $health.gateway_id
|
|
108
|
-
}
|
|
66
|
+
Invoke-WebRequest -Uri "http://localhost:$GatewayPort/health" -TimeoutSec 5 -ErrorAction SilentlyContinue | Out-Null
|
|
67
|
+
Write-Log "Health: OK" "SUCCESS"
|
|
109
68
|
} catch {
|
|
110
|
-
|
|
69
|
+
Write-Log "Health: Port open but API not responding" "WARN"
|
|
111
70
|
}
|
|
112
|
-
}
|
|
113
71
|
|
|
114
|
-
#
|
|
115
|
-
if ($
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
# Brief output mode (for SSH parsing)
|
|
121
|
-
if ($Brief) {
|
|
122
|
-
if ($status.running) {
|
|
123
|
-
Write-Output "RUNNING:$($status.pid):$Port"
|
|
124
|
-
if ($status.health) {
|
|
125
|
-
Write-Output "HEALTH:OK"
|
|
72
|
+
# Show PID file status
|
|
73
|
+
if (Test-Path $PidFile) {
|
|
74
|
+
$savedPid = Get-Content $PidFile -ErrorAction SilentlyContinue
|
|
75
|
+
if ($savedPid -eq $existingPID) {
|
|
76
|
+
Write-Log "PID file: Match ($PidFile)"
|
|
126
77
|
} else {
|
|
127
|
-
Write-
|
|
128
|
-
}
|
|
129
|
-
if ($status.version) {
|
|
130
|
-
Write-Output "VERSION:$($status.version)"
|
|
131
|
-
}
|
|
132
|
-
if ($status.gateway_id) {
|
|
133
|
-
Write-Output "GATEWAY_ID:$($status.gateway_id)"
|
|
78
|
+
Write-Log "PID file: Mismatch (saved: $savedPid, actual: $existingPID)" "WARN"
|
|
134
79
|
}
|
|
135
80
|
} else {
|
|
136
|
-
Write-
|
|
137
|
-
if ($status.installed) {
|
|
138
|
-
Write-Output "INSTALLED:YES"
|
|
139
|
-
if ($status.version) {
|
|
140
|
-
Write-Output "VERSION:$($status.version)"
|
|
141
|
-
}
|
|
142
|
-
} else {
|
|
143
|
-
Write-Output "INSTALLED:NO"
|
|
144
|
-
}
|
|
145
|
-
if ($status.gateway_id) {
|
|
146
|
-
Write-Output "GATEWAY_ID:$($status.gateway_id)"
|
|
147
|
-
}
|
|
81
|
+
Write-Log "PID file: Not found" "WARN"
|
|
148
82
|
}
|
|
149
|
-
exit $(if ($status.running) { 0 } else { 1 })
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
# Full status output
|
|
153
|
-
Write-Output ""
|
|
154
|
-
Write-Output "=========================================="
|
|
155
|
-
Write-Output " Gateway Type 3 Status (Windows)"
|
|
156
|
-
Write-Output "=========================================="
|
|
157
83
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
if ($status.health) {
|
|
164
|
-
Write-Log "Health: OK" "SUCCESS"
|
|
165
|
-
} else {
|
|
166
|
-
Write-Log "Health: Port open but API not responding" "WARN"
|
|
84
|
+
# Show log file info
|
|
85
|
+
if (Test-Path $LogFile) {
|
|
86
|
+
$logSize = (Get-Item $LogFile).Length / 1KB
|
|
87
|
+
Write-Log "Log file: $LogFile ($([math]::Round($logSize, 1)) KB)"
|
|
167
88
|
}
|
|
168
89
|
|
|
169
|
-
if ($
|
|
170
|
-
Write-Log "
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
Write-Log "
|
|
174
|
-
}
|
|
175
|
-
if ($status.gateway_name) {
|
|
176
|
-
Write-Log "Gateway Name: $($status.gateway_name)"
|
|
90
|
+
if ($serviceMode) {
|
|
91
|
+
Write-Log ""
|
|
92
|
+
Write-Log "Service commands:"
|
|
93
|
+
Write-Log " Get-Service $ServiceName"
|
|
94
|
+
Write-Log " Get-Content $InstallDir\logs\service-stdout.log -Tail 50"
|
|
177
95
|
}
|
|
96
|
+
|
|
97
|
+
Write-Output "RESULT:running=true,port=$GatewayPort,pid=$existingPID,mode=$modeStr"
|
|
98
|
+
exit 0
|
|
178
99
|
} else {
|
|
179
|
-
Write-Log "Status:
|
|
180
|
-
Write-Log "Port: $
|
|
100
|
+
Write-Log "Status: NOT RUNNING" "WARN"
|
|
101
|
+
Write-Log "Port: $GatewayPort (not in use)"
|
|
181
102
|
|
|
182
|
-
if ($
|
|
183
|
-
Write-Log "
|
|
184
|
-
if ($status.version) {
|
|
185
|
-
Write-Log "Version: $($status.version)"
|
|
186
|
-
}
|
|
187
|
-
} else {
|
|
188
|
-
Write-Log "Installed: No" "WARN"
|
|
103
|
+
if (Test-Path $PidFile) {
|
|
104
|
+
Write-Log "PID file exists but process not running (stale)" "WARN"
|
|
189
105
|
}
|
|
190
|
-
|
|
191
|
-
|
|
106
|
+
|
|
107
|
+
if ($serviceMode) {
|
|
108
|
+
$service = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue
|
|
109
|
+
if ($service.Status -eq "Stopped") { Write-Log "Service is stopped" }
|
|
192
110
|
}
|
|
193
|
-
}
|
|
194
111
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
$LogFile = Join-Path $LogDir "gateway.log"
|
|
198
|
-
if (Test-Path $LogFile) {
|
|
199
|
-
$logSize = (Get-Item $LogFile).Length
|
|
200
|
-
$logSizeStr = if ($logSize -gt 1MB) { "{0:N2} MB" -f ($logSize / 1MB) } else { "{0:N0} KB" -f ($logSize / 1KB) }
|
|
201
|
-
Write-Log "Log File: $LogFile ($logSizeStr)"
|
|
112
|
+
Write-Output "RESULT:running=false,port=$GatewayPort,pid=,mode=$modeStr"
|
|
113
|
+
exit 0
|
|
202
114
|
}
|
|
203
|
-
|
|
204
|
-
Write-Output ""
|
|
205
|
-
Write-Output "Commands:"
|
|
206
|
-
Write-Output " npm start - Start gateway"
|
|
207
|
-
Write-Output " npm stop - Stop gateway"
|
|
208
|
-
Write-Output " npm run status - Show this status"
|
|
209
|
-
Write-Output ""
|
|
210
|
-
|
|
211
|
-
exit $(if ($status.running) { 0 } else { 1 })
|
package/scripts/status.sh
CHANGED
|
@@ -1,79 +1,152 @@
|
|
|
1
1
|
#!/bin/bash
|
|
2
|
-
#
|
|
2
|
+
# Gateway Type 3 Status Script
|
|
3
|
+
# Check if gateway is running and report status
|
|
4
|
+
# Handles both service mode and standalone mode
|
|
5
|
+
#
|
|
6
|
+
# Output: RESULT:running=true|false,port=PORT,pid=PID,mode=service|standalone
|
|
3
7
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
set -e
|
|
9
|
+
|
|
10
|
+
# Get script directory and project directory
|
|
11
|
+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
12
|
+
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
|
|
13
|
+
|
|
14
|
+
# If running from node_modules, find the actual install dir
|
|
15
|
+
if [[ "$PROJECT_DIR" == *"node_modules"* ]]; then
|
|
16
|
+
INSTALL_DIR="$(cd "$PROJECT_DIR/../.." && pwd)"
|
|
17
|
+
else
|
|
18
|
+
INSTALL_DIR="$PROJECT_DIR"
|
|
19
|
+
fi
|
|
10
20
|
|
|
11
21
|
# Configuration
|
|
12
|
-
|
|
13
|
-
PID_FILE="/
|
|
14
|
-
LOG_FILE="/
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
22
|
+
ENV_FILE="${INSTALL_DIR}/.env"
|
|
23
|
+
PID_FILE="${INSTALL_DIR}/gateway.pid"
|
|
24
|
+
LOG_FILE="${INSTALL_DIR}/logs/gateway.log"
|
|
25
|
+
SERVICE_MODE_FILE="${INSTALL_DIR}/.service-mode"
|
|
26
|
+
SERVICE_NAME="langmart-gateway"
|
|
27
|
+
service_mode=false
|
|
28
|
+
|
|
29
|
+
# Load .env for GATEWAY_PORT
|
|
30
|
+
if [ -f "$ENV_FILE" ]; then
|
|
31
|
+
set -a
|
|
32
|
+
source "$ENV_FILE"
|
|
33
|
+
set +a
|
|
20
34
|
fi
|
|
21
35
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
36
|
+
GATEWAY_PORT="${GATEWAY_PORT:-8083}"
|
|
37
|
+
|
|
38
|
+
# Log function
|
|
39
|
+
log() {
|
|
40
|
+
local level="${2:-INFO}"
|
|
41
|
+
local timestamp=$(date +"%H:%M:%S")
|
|
42
|
+
echo "[$level] $timestamp - $1"
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
# Check if running in service mode
|
|
46
|
+
check_service_mode() {
|
|
47
|
+
if [ -f "$SERVICE_MODE_FILE" ]; then
|
|
48
|
+
local mode=$(cat "$SERVICE_MODE_FILE" 2>/dev/null || echo "")
|
|
49
|
+
if [ "$mode" = "systemd" ]; then
|
|
50
|
+
if systemctl list-unit-files 2>/dev/null | grep -q "^${SERVICE_NAME}.service"; then
|
|
51
|
+
service_mode=true
|
|
52
|
+
return 0
|
|
53
|
+
fi
|
|
54
|
+
fi
|
|
55
|
+
fi
|
|
56
|
+
service_mode=false
|
|
57
|
+
return 1
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
log "=== Gateway Type 3 Status ==="
|
|
61
|
+
log "Install directory: $INSTALL_DIR"
|
|
62
|
+
log "Port: $GATEWAY_PORT"
|
|
63
|
+
|
|
64
|
+
# ============================================
|
|
65
|
+
# CHECK SERVICE MODE
|
|
66
|
+
# ============================================
|
|
67
|
+
check_service_mode
|
|
68
|
+
if [ "$service_mode" = true ]; then
|
|
69
|
+
log "Mode: Service (systemd)"
|
|
25
70
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
71
|
+
service_status=$(systemctl is-active "$SERVICE_NAME" 2>/dev/null || echo "inactive")
|
|
72
|
+
service_enabled=$(systemctl is-enabled "$SERVICE_NAME" 2>/dev/null || echo "disabled")
|
|
73
|
+
|
|
74
|
+
log "Service status: $service_status"
|
|
75
|
+
log "Service enabled: $service_enabled"
|
|
76
|
+
else
|
|
77
|
+
log "Mode: Standalone"
|
|
78
|
+
fi
|
|
79
|
+
|
|
80
|
+
# Check if running on port
|
|
81
|
+
existing_pid=$(lsof -ti:$GATEWAY_PORT 2>/dev/null || true)
|
|
82
|
+
|
|
83
|
+
if [ -n "$existing_pid" ]; then
|
|
84
|
+
mode_str="standalone"
|
|
85
|
+
[ "$service_mode" = true ] && mode_str="service"
|
|
86
|
+
|
|
87
|
+
log "Status: RUNNING" "SUCCESS"
|
|
88
|
+
log "PID: $existing_pid"
|
|
89
|
+
log "Port: $GATEWAY_PORT"
|
|
32
90
|
|
|
33
91
|
# Check health endpoint
|
|
92
|
+
HOST_IP=$(hostname -I 2>/dev/null | awk '{print $1}' || echo "localhost")
|
|
93
|
+
[ -z "$HOST_IP" ] && HOST_IP="localhost"
|
|
94
|
+
|
|
34
95
|
if curl -s "http://$HOST_IP:$GATEWAY_PORT/health" > /dev/null 2>&1; then
|
|
35
|
-
|
|
36
|
-
echo -e "Management API: ${CYAN}http://$HOST_IP:$GATEWAY_PORT${NC}"
|
|
96
|
+
log "Health: OK" "SUCCESS"
|
|
37
97
|
else
|
|
38
|
-
|
|
98
|
+
log "Health: Port open but API not responding" "WARN"
|
|
39
99
|
fi
|
|
40
100
|
|
|
41
101
|
# Show PID file status
|
|
42
102
|
if [ -f "$PID_FILE" ]; then
|
|
43
|
-
|
|
44
|
-
if [ "$
|
|
45
|
-
|
|
103
|
+
saved_pid=$(cat "$PID_FILE")
|
|
104
|
+
if [ "$existing_pid" = "$saved_pid" ]; then
|
|
105
|
+
log "PID file: Match ($PID_FILE)"
|
|
46
106
|
else
|
|
47
|
-
|
|
107
|
+
log "PID file: Mismatch (saved: $saved_pid, actual: $existing_pid)" "WARN"
|
|
48
108
|
fi
|
|
49
109
|
else
|
|
50
|
-
|
|
110
|
+
log "PID file: Not found" "WARN"
|
|
51
111
|
fi
|
|
52
112
|
|
|
53
|
-
# Show log file
|
|
113
|
+
# Show log file info
|
|
54
114
|
if [ -f "$LOG_FILE" ]; then
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
echo -e "Log Size: ${CYAN}$LOG_SIZE${NC}"
|
|
115
|
+
log_size=$(du -h "$LOG_FILE" 2>/dev/null | cut -f1 || echo "unknown")
|
|
116
|
+
log "Log file: $LOG_FILE ($log_size)"
|
|
58
117
|
fi
|
|
118
|
+
|
|
119
|
+
# Show service-specific info
|
|
120
|
+
if [ "$service_mode" = true ]; then
|
|
121
|
+
log ""
|
|
122
|
+
log "Service commands:"
|
|
123
|
+
log " sudo systemctl status $SERVICE_NAME"
|
|
124
|
+
log " sudo journalctl -u $SERVICE_NAME -f"
|
|
125
|
+
fi
|
|
126
|
+
|
|
127
|
+
echo "RESULT:running=true,port=$GATEWAY_PORT,pid=$existing_pid,mode=$mode_str"
|
|
128
|
+
exit 0
|
|
59
129
|
else
|
|
60
|
-
|
|
61
|
-
|
|
130
|
+
mode_str="standalone"
|
|
131
|
+
[ "$service_mode" = true ] && mode_str="service"
|
|
62
132
|
|
|
63
|
-
|
|
133
|
+
log "Status: NOT RUNNING" "WARN"
|
|
134
|
+
log "Port: $GATEWAY_PORT (not in use)"
|
|
135
|
+
|
|
136
|
+
# Check for stale PID file
|
|
64
137
|
if [ -f "$PID_FILE" ]; then
|
|
65
|
-
|
|
66
|
-
|
|
138
|
+
log "PID file exists but process not running (stale)" "WARN"
|
|
139
|
+
fi
|
|
140
|
+
|
|
141
|
+
# Service-specific info
|
|
142
|
+
if [ "$service_mode" = true ]; then
|
|
143
|
+
service_status=$(systemctl is-active "$SERVICE_NAME" 2>/dev/null || echo "inactive")
|
|
144
|
+
if [ "$service_status" = "failed" ]; then
|
|
145
|
+
log "Service is in failed state" "ERROR"
|
|
146
|
+
log "Check logs: sudo journalctl -u $SERVICE_NAME -n 50"
|
|
147
|
+
fi
|
|
67
148
|
fi
|
|
68
|
-
fi
|
|
69
149
|
|
|
70
|
-
echo
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
echo -e " npm start - Start gateway in background"
|
|
74
|
-
echo -e " npm stop - Stop gateway gracefully"
|
|
75
|
-
echo -e " npm restart - Restart gateway"
|
|
76
|
-
echo -e " npm run status - Show this status"
|
|
77
|
-
echo -e " npm run ui - Start interactive UI"
|
|
78
|
-
echo -e " npm run self - Start interactive UI (short form)"
|
|
79
|
-
echo -e ""
|
|
150
|
+
echo "RESULT:running=false,port=$GATEWAY_PORT,pid=,mode=$mode_str"
|
|
151
|
+
exit 0
|
|
152
|
+
fi
|