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.
@@ -0,0 +1,187 @@
1
+ # Gateway Type 3 - Install as Windows Service
2
+ # Uses NSSM (Non-Sucking Service Manager) to install as Windows service
3
+ #
4
+ # Prerequisites: NSSM must be installed (choco install nssm OR download from nssm.cc)
5
+ # Usage: Run as Administrator: powershell -ExecutionPolicy Bypass -File install-service.ps1
6
+ # Output: RESULT:installed=true|false
7
+
8
+ $ErrorActionPreference = "Stop"
9
+
10
+ # Get script directory
11
+ $ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
12
+ $ProjectDir = Split-Path -Parent $ScriptDir
13
+
14
+ # If running from node_modules, find install dir
15
+ if ($ProjectDir -like "*node_modules*") {
16
+ $InstallDir = (Get-Location).Path
17
+ } else {
18
+ $InstallDir = $ProjectDir
19
+ }
20
+
21
+ # Configuration
22
+ $ServiceName = "LangMartGateway"
23
+ $ServiceDisplayName = "LangMart Gateway Type 3"
24
+ $ServiceDescription = "LangMart Gateway Type 3 - Self-hosted gateway for LLM routing"
25
+ $EnvFile = Join-Path $InstallDir ".env"
26
+ $LogDir = Join-Path $InstallDir "logs"
27
+
28
+ # Output helper
29
+ function Write-Log {
30
+ param([string]$Message, [string]$Type = "INFO")
31
+ $timestamp = Get-Date -Format "HH:mm:ss"
32
+ Write-Output "[$Type] $timestamp - $Message"
33
+ }
34
+
35
+ Write-Log "=== Gateway Type 3 Install Service ==="
36
+ Write-Log "Install directory: $InstallDir"
37
+
38
+ # Check if running as Administrator
39
+ $isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
40
+ if (-not $isAdmin) {
41
+ Write-Log "This script must be run as Administrator" "ERROR"
42
+ Write-Output "RESULT:installed=false"
43
+ exit 1
44
+ }
45
+
46
+ # Check for NSSM
47
+ $nssmPath = $null
48
+ if (Get-Command "nssm" -ErrorAction SilentlyContinue) {
49
+ $nssmPath = "nssm"
50
+ } elseif (Test-Path "C:\tools\nssm\win64\nssm.exe") {
51
+ $nssmPath = "C:\tools\nssm\win64\nssm.exe"
52
+ } elseif (Test-Path "C:\nssm\nssm.exe") {
53
+ $nssmPath = "C:\nssm\nssm.exe"
54
+ } elseif (Test-Path "$InstallDir\nssm.exe") {
55
+ $nssmPath = "$InstallDir\nssm.exe"
56
+ }
57
+
58
+ if (-not $nssmPath) {
59
+ Write-Log "NSSM not found. Please install NSSM:" "ERROR"
60
+ Write-Log " Option 1: choco install nssm"
61
+ Write-Log " Option 2: Download from https://nssm.cc/download"
62
+ Write-Log " Option 3: Place nssm.exe in $InstallDir"
63
+ Write-Output "RESULT:installed=false"
64
+ exit 1
65
+ }
66
+
67
+ Write-Log "Using NSSM: $nssmPath"
68
+
69
+ # Check .env file
70
+ if (-not (Test-Path $EnvFile)) {
71
+ Write-Log ".env file not found at $EnvFile" "ERROR"
72
+ Write-Output "RESULT:installed=false"
73
+ exit 1
74
+ }
75
+
76
+ # Load .env for GATEWAY_PORT
77
+ Get-Content $EnvFile | ForEach-Object {
78
+ if ($_ -match '^([^#=]+)=(.*)$') {
79
+ $key = $matches[1].Trim()
80
+ $value = $matches[2].Trim().Trim('"').Trim("'")
81
+ [Environment]::SetEnvironmentVariable($key, $value, 'Process')
82
+ }
83
+ }
84
+
85
+ # Find Node.js
86
+ $nodePath = $null
87
+ if (Test-Path "$InstallDir\node\node.exe") {
88
+ $nodePath = "$InstallDir\node\node.exe"
89
+ } elseif (Get-Command "node" -ErrorAction SilentlyContinue) {
90
+ $nodePath = (Get-Command "node").Source
91
+ }
92
+
93
+ if (-not $nodePath) {
94
+ Write-Log "Node.js not found" "ERROR"
95
+ Write-Output "RESULT:installed=false"
96
+ exit 1
97
+ }
98
+
99
+ Write-Log "Node.js: $nodePath"
100
+
101
+ # Find entry file
102
+ $entryFile = $null
103
+ if (Test-Path "$InstallDir\node_modules\langmart-gateway-type3\dist\index-server.js") {
104
+ $entryFile = "$InstallDir\node_modules\langmart-gateway-type3\dist\index-server.js"
105
+ } elseif (Test-Path "$ProjectDir\dist\index-server.js") {
106
+ $entryFile = "$ProjectDir\dist\index-server.js"
107
+ }
108
+
109
+ if (-not $entryFile) {
110
+ Write-Log "Entry file not found" "ERROR"
111
+ Write-Output "RESULT:installed=false"
112
+ exit 1
113
+ }
114
+
115
+ Write-Log "Entry file: $entryFile"
116
+
117
+ # Create logs directory
118
+ if (-not (Test-Path $LogDir)) {
119
+ New-Item -ItemType Directory -Path $LogDir -Force | Out-Null
120
+ }
121
+
122
+ # Check if service already exists
123
+ $existingService = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue
124
+ if ($existingService) {
125
+ Write-Log "Service already exists, removing..." "WARN"
126
+ & $nssmPath stop $ServiceName 2>$null
127
+ & $nssmPath remove $ServiceName confirm 2>$null
128
+ Start-Sleep -Seconds 2
129
+ }
130
+
131
+ # Install service with NSSM
132
+ Write-Log "Installing service..."
133
+
134
+ & $nssmPath install $ServiceName $nodePath $entryFile
135
+ if ($LASTEXITCODE -ne 0) {
136
+ Write-Log "Failed to install service" "ERROR"
137
+ Write-Output "RESULT:installed=false"
138
+ exit 1
139
+ }
140
+
141
+ # Configure service
142
+ & $nssmPath set $ServiceName DisplayName $ServiceDisplayName
143
+ & $nssmPath set $ServiceName Description $ServiceDescription
144
+ & $nssmPath set $ServiceName AppDirectory $InstallDir
145
+ & $nssmPath set $ServiceName AppStdout "$LogDir\service-stdout.log"
146
+ & $nssmPath set $ServiceName AppStderr "$LogDir\service-stderr.log"
147
+ & $nssmPath set $ServiceName AppRotateFiles 1
148
+ & $nssmPath set $ServiceName AppRotateBytes 10485760
149
+
150
+ # Set environment variables from .env file
151
+ $envVars = @()
152
+ Get-Content $EnvFile | ForEach-Object {
153
+ if ($_ -match '^([^#=]+)=(.*)$') {
154
+ $key = $matches[1].Trim()
155
+ $value = $matches[2].Trim().Trim('"').Trim("'")
156
+ $envVars += "$key=$value"
157
+ }
158
+ }
159
+ if ($envVars.Count -gt 0) {
160
+ & $nssmPath set $ServiceName AppEnvironmentExtra $envVars
161
+ }
162
+
163
+ # Set restart on failure
164
+ & $nssmPath set $ServiceName AppExit Default Restart
165
+ & $nssmPath set $ServiceName AppRestartDelay 10000
166
+
167
+ # Set startup type to automatic
168
+ & $nssmPath set $ServiceName Start SERVICE_AUTO_START
169
+
170
+ # Create service marker file
171
+ "windows-service" | Out-File -FilePath "$InstallDir\.service-mode" -Encoding UTF8 -Force
172
+
173
+ Write-Log "Service installed successfully" "SUCCESS"
174
+ Write-Log ""
175
+ Write-Log "Commands:"
176
+ Write-Log " Start: Start-Service $ServiceName"
177
+ Write-Log " Stop: Stop-Service $ServiceName"
178
+ Write-Log " Status: Get-Service $ServiceName"
179
+ Write-Log " Logs: Get-Content $LogDir\service-stdout.log -Tail 50"
180
+ Write-Log ""
181
+ Write-Log "Or use the gateway scripts:"
182
+ Write-Log " powershell -File $ScriptDir\start.ps1"
183
+ Write-Log " powershell -File $ScriptDir\stop.ps1"
184
+ Write-Log " powershell -File $ScriptDir\status.ps1"
185
+
186
+ Write-Output "RESULT:installed=true"
187
+ exit 0
@@ -0,0 +1,166 @@
1
+ #!/bin/bash
2
+ # Gateway Type 3 - Install as systemd Service
3
+ # Installs the gateway as a systemd service for automatic startup
4
+ #
5
+ # Usage: sudo bash install-service.sh
6
+ # Output: RESULT:installed=true|false
7
+
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
+ # scripts -> langmart-gateway-type3 -> node_modules -> INSTALL_DIR
17
+ INSTALL_DIR="$(cd "$PROJECT_DIR/../.." && pwd)"
18
+ else
19
+ INSTALL_DIR="$PROJECT_DIR"
20
+ fi
21
+
22
+ # Configuration
23
+ SERVICE_NAME="langmart-gateway"
24
+ ENV_FILE="${INSTALL_DIR}/.env"
25
+
26
+ # Log function
27
+ log() {
28
+ local level="${2:-INFO}"
29
+ local timestamp=$(date +"%H:%M:%S")
30
+ echo "[$level] $timestamp - $1"
31
+ }
32
+
33
+ log "=== Gateway Type 3 Install Service ==="
34
+ log "Install directory: $INSTALL_DIR"
35
+
36
+ # Check if running as root
37
+ if [ "$EUID" -ne 0 ]; then
38
+ log "This script must be run as root (use sudo)" "ERROR"
39
+ echo "RESULT:installed=false"
40
+ exit 1
41
+ fi
42
+
43
+ # Check if systemd is available
44
+ if ! command -v systemctl &> /dev/null; then
45
+ log "systemd not found - this script only supports systemd-based systems" "ERROR"
46
+ echo "RESULT:installed=false"
47
+ exit 1
48
+ fi
49
+
50
+ # Load .env to get configuration
51
+ if [ -f "$ENV_FILE" ]; then
52
+ set -a
53
+ source "$ENV_FILE"
54
+ set +a
55
+ else
56
+ log ".env file not found at $ENV_FILE" "ERROR"
57
+ log "Create .env file with at least GATEWAY_API_KEY and MARKETPLACE_URL"
58
+ echo "RESULT:installed=false"
59
+ exit 1
60
+ fi
61
+
62
+ # Get the user who owns the install directory
63
+ INSTALL_USER=$(stat -c '%U' "$INSTALL_DIR")
64
+ INSTALL_GROUP=$(stat -c '%G' "$INSTALL_DIR")
65
+
66
+ # Find Node.js binary
67
+ if [ -f "$INSTALL_DIR/node/bin/node" ]; then
68
+ NODE_BIN="$INSTALL_DIR/node/bin/node"
69
+ elif command -v node &> /dev/null; then
70
+ NODE_BIN=$(which node)
71
+ else
72
+ log "Node.js not found" "ERROR"
73
+ echo "RESULT:installed=false"
74
+ exit 1
75
+ fi
76
+
77
+ # Find entry file
78
+ if [ -f "$INSTALL_DIR/node_modules/langmart-gateway-type3/dist/index-server.js" ]; then
79
+ ENTRY_FILE="$INSTALL_DIR/node_modules/langmart-gateway-type3/dist/index-server.js"
80
+ elif [ -f "$PROJECT_DIR/dist/index-server.js" ]; then
81
+ ENTRY_FILE="$PROJECT_DIR/dist/index-server.js"
82
+ else
83
+ log "Entry file not found" "ERROR"
84
+ echo "RESULT:installed=false"
85
+ exit 1
86
+ fi
87
+
88
+ log "Service name: $SERVICE_NAME"
89
+ log "Node.js: $NODE_BIN"
90
+ log "Entry file: $ENTRY_FILE"
91
+ log "Run as user: $INSTALL_USER"
92
+
93
+ # Check if service already exists
94
+ if systemctl list-unit-files | grep -q "^${SERVICE_NAME}.service"; then
95
+ log "Service already exists, will be overwritten" "WARN"
96
+ systemctl stop "$SERVICE_NAME" 2>/dev/null || true
97
+ systemctl disable "$SERVICE_NAME" 2>/dev/null || true
98
+ fi
99
+
100
+ # Create systemd service file
101
+ SERVICE_FILE="/etc/systemd/system/${SERVICE_NAME}.service"
102
+
103
+ log "Creating service file: $SERVICE_FILE"
104
+
105
+ cat > "$SERVICE_FILE" << EOF
106
+ [Unit]
107
+ Description=LangMart Gateway Type 3
108
+ Documentation=https://github.com/langmart/gateway-type3
109
+ After=network-online.target
110
+ Wants=network-online.target
111
+
112
+ [Service]
113
+ Type=simple
114
+ User=$INSTALL_USER
115
+ Group=$INSTALL_GROUP
116
+ WorkingDirectory=$INSTALL_DIR
117
+ EnvironmentFile=$ENV_FILE
118
+ ExecStart=$NODE_BIN $ENTRY_FILE
119
+ Restart=on-failure
120
+ RestartSec=10
121
+ StandardOutput=append:$INSTALL_DIR/logs/gateway.log
122
+ StandardError=append:$INSTALL_DIR/logs/gateway.log
123
+
124
+ # Security hardening
125
+ NoNewPrivileges=true
126
+ ProtectSystem=strict
127
+ ProtectHome=read-only
128
+ ReadWritePaths=$INSTALL_DIR
129
+
130
+ # Resource limits
131
+ LimitNOFILE=65535
132
+
133
+ [Install]
134
+ WantedBy=multi-user.target
135
+ EOF
136
+
137
+ # Create logs directory if not exists
138
+ mkdir -p "$INSTALL_DIR/logs"
139
+ chown "$INSTALL_USER:$INSTALL_GROUP" "$INSTALL_DIR/logs"
140
+
141
+ # Create service marker file
142
+ echo "systemd" > "$INSTALL_DIR/.service-mode"
143
+ chown "$INSTALL_USER:$INSTALL_GROUP" "$INSTALL_DIR/.service-mode"
144
+
145
+ # Reload systemd and enable service
146
+ log "Reloading systemd daemon..."
147
+ systemctl daemon-reload
148
+
149
+ log "Enabling service..."
150
+ systemctl enable "$SERVICE_NAME"
151
+
152
+ log "Service installed successfully" "SUCCESS"
153
+ log ""
154
+ log "Commands:"
155
+ log " Start: sudo systemctl start $SERVICE_NAME"
156
+ log " Stop: sudo systemctl stop $SERVICE_NAME"
157
+ log " Status: sudo systemctl status $SERVICE_NAME"
158
+ log " Logs: sudo journalctl -u $SERVICE_NAME -f"
159
+ log ""
160
+ log "Or use the gateway scripts:"
161
+ log " bash $SCRIPT_DIR/start.sh"
162
+ log " bash $SCRIPT_DIR/stop.sh"
163
+ log " bash $SCRIPT_DIR/status.sh"
164
+
165
+ echo "RESULT:installed=true"
166
+ exit 0
@@ -16,7 +16,7 @@
16
16
  # -Port Gateway port (default: 8083)
17
17
  # -InstallDir Installation directory (default: C:\langmart-gateway)
18
18
  # -Capabilities Gateway capabilities: session,llm or llm (default: llm)
19
- # -Full Enable full capabilities (DevOps + LLM routing)
19
+ # -Full Enable full capabilities (Automation + LLM routing)
20
20
  # -Service Install as Windows Service
21
21
 
22
22
  [CmdletBinding()]
@@ -64,7 +64,7 @@ Options:
64
64
  -Port PORT Gateway port (default: 8083)
65
65
  -InstallDir DIR Installation directory (default: C:\langmart-gateway)
66
66
  -Capabilities CAPS Gateway capabilities: session,llm or llm (default: llm)
67
- -Full Enable full capabilities (DevOps + LLM routing)
67
+ -Full Enable full capabilities (Automation + LLM routing)
68
68
  -Service Install as Windows Service
69
69
  -Help Show this help message
70
70
 
@@ -72,7 +72,7 @@ Examples:
72
72
  # Basic installation (LLM routing only)
73
73
  .\install.ps1 -MarketplaceUrl "ws://10.0.1.117:8081" -ApiKey "sk-test-key"
74
74
 
75
- # Full DevOps mode with Windows Service
75
+ # Full Automation mode with Windows Service
76
76
  .\install.ps1 -MarketplaceUrl "ws://10.0.1.117:8081" -ApiKey "sk-test-key" -Full -Service
77
77
 
78
78
  # One-liner from web (set env vars first)
@@ -205,7 +205,7 @@ MARKETPLACE_URL=$MarketplaceUrl
205
205
  # Gateway authentication
206
206
  GATEWAY_API_KEY=$ApiKey
207
207
 
208
- # Gateway capabilities (session,llm = full DevOps mode, llm = LLM routing only)
208
+ # Gateway capabilities (session,llm = full Automation mode, llm = LLM routing only)
209
209
  GATEWAY_CAPABILITIES=$Capabilities
210
210
 
211
211
  # Local vault configuration
@@ -339,7 +339,7 @@ Write-Info "Gateway Port: $Port"
339
339
  Write-Info "Marketplace URL: $MarketplaceUrl"
340
340
 
341
341
  if ($Capabilities -eq "session,llm") {
342
- Write-Info "Mode: Full (DevOps + LLM Routing)"
342
+ Write-Info "Mode: Full (Automation + LLM Routing)"
343
343
  } else {
344
344
  Write-Info "Mode: LLM Routing Only"
345
345
  }
@@ -17,7 +17,7 @@
17
17
  # --port PORT Gateway port (default: 8083)
18
18
  # --install-dir DIR Installation directory (default: /opt/langmart-gateway)
19
19
  # --capabilities CAPS Gateway capabilities: session,llm or llm (default: llm)
20
- # --full Enable full capabilities (DevOps + LLM routing)
20
+ # --full Enable full capabilities (Automation + LLM routing)
21
21
  # --service Install as systemd service
22
22
  # --help Show this help message
23
23
 
@@ -87,7 +87,7 @@ while [[ $# -gt 0 ]]; do
87
87
  echo " --install-dir DIR Installation directory (default: /opt/langmart-gateway)"
88
88
  echo " --service Install as systemd service"
89
89
  echo " --capabilities CAPS Gateway capabilities: session,llm or llm (default: llm only)"
90
- echo " --full Enable full capabilities (session + llm) - DevOps mode"
90
+ echo " --full Enable full capabilities (session + llm) - Automation mode"
91
91
  echo " --github-token TOKEN GitHub token for npm package access"
92
92
  echo " --help Show this help message"
93
93
  echo ""
@@ -201,7 +201,7 @@ MARKETPLACE_URL=${MARKETPLACE_URL}
201
201
  # Gateway authentication
202
202
  GATEWAY_API_KEY=${GATEWAY_API_KEY}
203
203
 
204
- # Gateway capabilities (session,llm = full DevOps mode, llm = LLM routing only)
204
+ # Gateway capabilities (session,llm = full Automation mode, llm = LLM routing only)
205
205
  GATEWAY_CAPABILITIES=${GATEWAY_CAPABILITIES:-llm}
206
206
 
207
207
  # Local vault configuration
@@ -291,7 +291,7 @@ echo -e "${CYAN}Installation Directory: ${INSTALL_DIR}${NC}"
291
291
  echo -e "${CYAN}Gateway Port: ${GATEWAY_PORT}${NC}"
292
292
  echo -e "${CYAN}Marketplace URL: ${MARKETPLACE_URL}${NC}"
293
293
  if [ -n "$GATEWAY_CAPABILITIES" ] && [ "$GATEWAY_CAPABILITIES" = "session,llm" ]; then
294
- echo -e "${CYAN}Mode: Full (DevOps + LLM Routing)${NC}"
294
+ echo -e "${CYAN}Mode: Full (Automation + LLM Routing)${NC}"
295
295
  else
296
296
  echo -e "${CYAN}Mode: LLM Routing Only${NC}"
297
297
  fi
@@ -0,0 +1,104 @@
1
+ # Gateway Type 3 - Remove Windows Service
2
+ # Removes the gateway Windows service installed via NSSM
3
+ #
4
+ # Usage: Run as Administrator: powershell -ExecutionPolicy Bypass -File remove-service.ps1
5
+ # Output: RESULT:removed=true|false
6
+
7
+ $ErrorActionPreference = "Stop"
8
+
9
+ # Get script directory
10
+ $ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
11
+ $ProjectDir = Split-Path -Parent $ScriptDir
12
+
13
+ # If running from node_modules, find install dir
14
+ if ($ProjectDir -like "*node_modules*") {
15
+ $InstallDir = (Get-Location).Path
16
+ } else {
17
+ $InstallDir = $ProjectDir
18
+ }
19
+
20
+ # Configuration
21
+ $ServiceName = "LangMartGateway"
22
+
23
+ # Output helper
24
+ function Write-Log {
25
+ param([string]$Message, [string]$Type = "INFO")
26
+ $timestamp = Get-Date -Format "HH:mm:ss"
27
+ Write-Output "[$Type] $timestamp - $Message"
28
+ }
29
+
30
+ Write-Log "=== Gateway Type 3 Remove Service ==="
31
+ Write-Log "Install directory: $InstallDir"
32
+
33
+ # Check if running as Administrator
34
+ $isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
35
+ if (-not $isAdmin) {
36
+ Write-Log "This script must be run as Administrator" "ERROR"
37
+ Write-Output "RESULT:removed=false"
38
+ exit 1
39
+ }
40
+
41
+ # Check if service exists
42
+ $existingService = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue
43
+ if (-not $existingService) {
44
+ Write-Log "Service not found - nothing to remove" "WARN"
45
+ # Remove marker file if exists
46
+ Remove-Item -Path "$InstallDir\.service-mode" -Force -ErrorAction SilentlyContinue
47
+ Write-Output "RESULT:removed=true"
48
+ exit 0
49
+ }
50
+
51
+ # Check for NSSM
52
+ $nssmPath = $null
53
+ if (Get-Command "nssm" -ErrorAction SilentlyContinue) {
54
+ $nssmPath = "nssm"
55
+ } elseif (Test-Path "C:\tools\nssm\win64\nssm.exe") {
56
+ $nssmPath = "C:\tools\nssm\win64\nssm.exe"
57
+ } elseif (Test-Path "C:\nssm\nssm.exe") {
58
+ $nssmPath = "C:\nssm\nssm.exe"
59
+ } elseif (Test-Path "$InstallDir\nssm.exe") {
60
+ $nssmPath = "$InstallDir\nssm.exe"
61
+ }
62
+
63
+ if ($nssmPath) {
64
+ # Use NSSM to remove (preferred)
65
+ # Temporarily allow errors since NSSM writes to stderr even on success
66
+ $ErrorActionPreference = "Continue"
67
+
68
+ Write-Log "Stopping service..."
69
+ $null = & $nssmPath stop $ServiceName 2>&1
70
+ Start-Sleep -Seconds 2
71
+
72
+ Write-Log "Removing service..."
73
+ $null = & $nssmPath remove $ServiceName confirm 2>&1
74
+
75
+ $ErrorActionPreference = "Stop"
76
+ } else {
77
+ # Fallback to sc.exe
78
+ Write-Log "NSSM not found, using sc.exe" "WARN"
79
+
80
+ Write-Log "Stopping service..."
81
+ Stop-Service -Name $ServiceName -Force -ErrorAction SilentlyContinue
82
+ Start-Sleep -Seconds 2
83
+
84
+ Write-Log "Removing service..."
85
+ sc.exe delete $ServiceName
86
+ }
87
+
88
+ # Verify removal
89
+ Start-Sleep -Seconds 2
90
+ $checkService = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue
91
+ if ($checkService) {
92
+ Write-Log "Service still exists - may need reboot to complete removal" "WARN"
93
+ }
94
+
95
+ # Remove service marker file
96
+ Remove-Item -Path "$InstallDir\.service-mode" -Force -ErrorAction SilentlyContinue
97
+
98
+ Write-Log "Service removed successfully" "SUCCESS"
99
+ Write-Log ""
100
+ Write-Log "The gateway can still be run manually:"
101
+ Write-Log " powershell -File $ScriptDir\start.ps1"
102
+
103
+ Write-Output "RESULT:removed=true"
104
+ exit 0
@@ -0,0 +1,79 @@
1
+ #!/bin/bash
2
+ # Gateway Type 3 - Remove systemd Service
3
+ # Removes the gateway systemd service
4
+ #
5
+ # Usage: sudo bash remove-service.sh
6
+ # Output: RESULT:removed=true|false
7
+
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
20
+
21
+ # Configuration
22
+ SERVICE_NAME="langmart-gateway"
23
+ SERVICE_FILE="/etc/systemd/system/${SERVICE_NAME}.service"
24
+
25
+ # Log function
26
+ log() {
27
+ local level="${2:-INFO}"
28
+ local timestamp=$(date +"%H:%M:%S")
29
+ echo "[$level] $timestamp - $1"
30
+ }
31
+
32
+ log "=== Gateway Type 3 Remove Service ==="
33
+ log "Install directory: $INSTALL_DIR"
34
+
35
+ # Check if running as root
36
+ if [ "$EUID" -ne 0 ]; then
37
+ log "This script must be run as root (use sudo)" "ERROR"
38
+ echo "RESULT:removed=false"
39
+ exit 1
40
+ fi
41
+
42
+ # Check if systemd is available
43
+ if ! command -v systemctl &> /dev/null; then
44
+ log "systemd not found" "ERROR"
45
+ echo "RESULT:removed=false"
46
+ exit 1
47
+ fi
48
+
49
+ # Check if service exists
50
+ if [ ! -f "$SERVICE_FILE" ]; then
51
+ log "Service not installed (no service file found)" "WARN"
52
+ # Remove marker file if exists
53
+ rm -f "$INSTALL_DIR/.service-mode"
54
+ echo "RESULT:removed=true"
55
+ exit 0
56
+ fi
57
+
58
+ log "Stopping service..."
59
+ systemctl stop "$SERVICE_NAME" 2>/dev/null || true
60
+
61
+ log "Disabling service..."
62
+ systemctl disable "$SERVICE_NAME" 2>/dev/null || true
63
+
64
+ log "Removing service file..."
65
+ rm -f "$SERVICE_FILE"
66
+
67
+ log "Reloading systemd daemon..."
68
+ systemctl daemon-reload
69
+
70
+ # Remove service marker file
71
+ rm -f "$INSTALL_DIR/.service-mode"
72
+
73
+ log "Service removed successfully" "SUCCESS"
74
+ log ""
75
+ log "The gateway can still be run manually:"
76
+ log " bash $SCRIPT_DIR/start.sh"
77
+
78
+ echo "RESULT:removed=true"
79
+ exit 0