langmart-gateway-type3 3.0.7 → 3.0.9

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.
@@ -0,0 +1,211 @@
1
+ # Check Gateway Type 3 status on Windows
2
+ # This script is designed to work both interactively and via SSH
3
+ # Output format is designed to be parseable for remote status checks
4
+
5
+ param(
6
+ [int]$Port = 8083,
7
+ [switch]$Json,
8
+ [switch]$Brief
9
+ )
10
+
11
+ # Get script/project directory
12
+ $ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
13
+ $ProjectDir = Split-Path -Parent $ScriptDir
14
+
15
+ # If running from node_modules, adjust path
16
+ if ($ProjectDir -like "*node_modules*") {
17
+ $ProjectDir = (Get-Location).Path
18
+ }
19
+
20
+ # Load .env file to get port if not specified
21
+ $EnvFile = Join-Path $ProjectDir ".env"
22
+ $envVars = @{}
23
+ if (Test-Path $EnvFile) {
24
+ Get-Content $EnvFile | ForEach-Object {
25
+ if ($_ -match '^([^#][^=]+)=(.*)$') {
26
+ $key = $matches[1].Trim()
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
+ }
32
+ }
33
+ }
34
+ }
35
+
36
+ # Status object for JSON output
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
+ }
49
+
50
+ # Output helper
51
+ function Write-Log {
52
+ param([string]$Message, [string]$Type = "INFO")
53
+ if (-not $Json) {
54
+ Write-Output "[$Type] $Message"
55
+ }
56
+ }
57
+
58
+ # Check if gateway package is installed
59
+ $EntryFile = $null
60
+ if (Test-Path "$ProjectDir\node_modules\langmart-gateway-type3\dist\index-server.js") {
61
+ $EntryFile = "$ProjectDir\node_modules\langmart-gateway-type3\dist\index-server.js"
62
+ $status.installed = $true
63
+ } elseif (Test-Path "$ProjectDir\dist\index-server.js") {
64
+ $EntryFile = "$ProjectDir\dist\index-server.js"
65
+ $status.installed = $true
66
+ }
67
+
68
+ # Get version from package.json
69
+ $PackageJson = "$ProjectDir\node_modules\langmart-gateway-type3\package.json"
70
+ if (Test-Path $PackageJson) {
71
+ try {
72
+ $pkg = Get-Content $PackageJson | ConvertFrom-Json
73
+ $status.version = $pkg.version
74
+ } catch {}
75
+ }
76
+
77
+ # Get gateway config
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
+ }
86
+
87
+ # Check if running
88
+ try {
89
+ $existingPID = (Get-NetTCPConnection -LocalPort $Port -State Listen -ErrorAction SilentlyContinue).OwningProcess | Select-Object -First 1
90
+ if ($existingPID) {
91
+ $status.running = $true
92
+ $status.pid = $existingPID
93
+ }
94
+ } catch {
95
+ $status.error = $_.Exception.Message
96
+ }
97
+
98
+ # Check health if running
99
+ if ($status.running) {
100
+ try {
101
+ $health = Invoke-RestMethod -Uri "http://localhost:$Port/health" -TimeoutSec 3 -ErrorAction Stop
102
+ $status.health = $true
103
+ if ($health.version) {
104
+ $status.version = $health.version
105
+ }
106
+ if ($health.gateway_id) {
107
+ $status.gateway_id = $health.gateway_id
108
+ }
109
+ } catch {
110
+ $status.health = $false
111
+ }
112
+ }
113
+
114
+ # JSON output mode
115
+ if ($Json) {
116
+ $status | ConvertTo-Json -Compress
117
+ exit $(if ($status.running) { 0 } else { 1 })
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"
126
+ } else {
127
+ Write-Output "HEALTH:FAIL"
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)"
134
+ }
135
+ } else {
136
+ Write-Output "STOPPED"
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
+ }
148
+ }
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
+
158
+ if ($status.running) {
159
+ Write-Log "Status: Running" "SUCCESS"
160
+ Write-Log "PID: $($status.pid)"
161
+ Write-Log "Port: $Port"
162
+
163
+ if ($status.health) {
164
+ Write-Log "Health: OK" "SUCCESS"
165
+ } else {
166
+ Write-Log "Health: Port open but API not responding" "WARN"
167
+ }
168
+
169
+ if ($status.version) {
170
+ Write-Log "Version: $($status.version)"
171
+ }
172
+ if ($status.gateway_id) {
173
+ Write-Log "Gateway ID: $($status.gateway_id)"
174
+ }
175
+ if ($status.gateway_name) {
176
+ Write-Log "Gateway Name: $($status.gateway_name)"
177
+ }
178
+ } else {
179
+ Write-Log "Status: Not Running" "WARN"
180
+ Write-Log "Port: $Port (not in use)"
181
+
182
+ if ($status.installed) {
183
+ Write-Log "Installed: Yes"
184
+ if ($status.version) {
185
+ Write-Log "Version: $($status.version)"
186
+ }
187
+ } else {
188
+ Write-Log "Installed: No" "WARN"
189
+ }
190
+ if ($status.gateway_id) {
191
+ Write-Log "Gateway ID: $($status.gateway_id) (from config)"
192
+ }
193
+ }
194
+
195
+ # Show log files
196
+ $LogDir = Join-Path $ProjectDir "logs"
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)"
202
+ }
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 })
@@ -0,0 +1,108 @@
1
+ # Stop Gateway Type 3 on Windows
2
+ # This script is designed to work both interactively and via SSH
3
+
4
+ param(
5
+ [int]$Port = 8083,
6
+ [switch]$Force
7
+ )
8
+
9
+ # Get script/project directory
10
+ $ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
11
+ $ProjectDir = Split-Path -Parent $ScriptDir
12
+
13
+ # If running from node_modules, adjust path
14
+ if ($ProjectDir -like "*node_modules*") {
15
+ $ProjectDir = (Get-Location).Path
16
+ }
17
+
18
+ # Load .env file to get port if not specified
19
+ $EnvFile = Join-Path $ProjectDir ".env"
20
+ if (Test-Path $EnvFile) {
21
+ Get-Content $EnvFile | ForEach-Object {
22
+ if ($_ -match '^GATEWAY_PORT=(.*)$') {
23
+ $envPort = $matches[1].Trim()
24
+ if ($Port -eq 8083 -and $envPort) {
25
+ $Port = [int]$envPort
26
+ }
27
+ }
28
+ }
29
+ }
30
+
31
+ # Output helper
32
+ function Write-Log {
33
+ param([string]$Message, [string]$Type = "INFO")
34
+ Write-Output "[$Type] $Message"
35
+ }
36
+
37
+ Write-Log "Stopping Gateway Type 3..."
38
+
39
+ # Check if running
40
+ try {
41
+ $existingPID = (Get-NetTCPConnection -LocalPort $Port -State Listen -ErrorAction SilentlyContinue).OwningProcess | Select-Object -First 1
42
+ } catch {
43
+ $existingPID = $null
44
+ }
45
+
46
+ if (-not $existingPID) {
47
+ Write-Log "Gateway is not running on port $Port" "WARN"
48
+
49
+ # Clean up PID file if exists
50
+ $PidFile = Join-Path $ProjectDir "gateway.pid"
51
+ if (Test-Path $PidFile) {
52
+ Remove-Item $PidFile -Force
53
+ }
54
+ exit 0
55
+ }
56
+
57
+ Write-Log "Found gateway process (PID: $existingPID) on port $Port"
58
+
59
+ # Try graceful shutdown via API first (unless -Force)
60
+ if (-not $Force) {
61
+ Write-Log "Attempting graceful shutdown via API..."
62
+ try {
63
+ $response = Invoke-RestMethod -Uri "http://localhost:$Port/shutdown" -Method POST -TimeoutSec 5 -ErrorAction SilentlyContinue
64
+ Write-Log "Shutdown signal sent"
65
+ Start-Sleep -Seconds 2
66
+
67
+ # Check if stopped
68
+ $stillRunning = (Get-NetTCPConnection -LocalPort $Port -State Listen -ErrorAction SilentlyContinue).OwningProcess | Select-Object -First 1
69
+ if (-not $stillRunning) {
70
+ Write-Log "Gateway stopped gracefully" "SUCCESS"
71
+
72
+ # Clean up PID file
73
+ $PidFile = Join-Path $ProjectDir "gateway.pid"
74
+ if (Test-Path $PidFile) {
75
+ Remove-Item $PidFile -Force
76
+ }
77
+ exit 0
78
+ }
79
+ } catch {
80
+ Write-Log "Graceful shutdown failed, forcing stop..." "WARN"
81
+ }
82
+ }
83
+
84
+ # Force kill the process
85
+ Write-Log "Force stopping process (PID: $existingPID)..."
86
+ try {
87
+ Stop-Process -Id $existingPID -Force -ErrorAction Stop
88
+ Start-Sleep -Seconds 1
89
+
90
+ # Verify stopped
91
+ $stillRunning = (Get-NetTCPConnection -LocalPort $Port -State Listen -ErrorAction SilentlyContinue).OwningProcess | Select-Object -First 1
92
+ if (-not $stillRunning) {
93
+ Write-Log "Gateway stopped" "SUCCESS"
94
+
95
+ # Clean up PID file
96
+ $PidFile = Join-Path $ProjectDir "gateway.pid"
97
+ if (Test-Path $PidFile) {
98
+ Remove-Item $PidFile -Force
99
+ }
100
+ exit 0
101
+ } else {
102
+ Write-Log "Failed to stop gateway" "ERROR"
103
+ exit 1
104
+ }
105
+ } catch {
106
+ Write-Log "Failed to stop process: $_" "ERROR"
107
+ exit 1
108
+ }