fa-mcp-sdk 0.2.87 → 0.2.92

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,187 +1,174 @@
1
- # srv.sh - Unified systemd Service Management Script
2
-
3
- Universal script for managing systemd services for Node.js applications. Consolidates functionality from separate `deploy/systemd-service/` scripts into a single solution.
1
+ # srv.cjs
2
+ Universal script for managing systemd services of Node.js applications.
4
3
 
5
4
  ## Features
6
5
 
7
- - ✅ **Universal execution**: Works the same when launched from project root or from `deploy/` folder
8
- - ✅ **Auto-detection of Node.js version**: Priority: parameter → .envrc → current version
9
- - ✅ **Smart Node.js search**: NVM paths → system paths
10
- - ✅ **Automatic configuration reading**: package.json, config for port
11
- - ✅ **systemd unit file generation**: Correct paths and settings
12
- - ✅ **Process management**: Stops processes on ports when removing
6
+ - ✅ **Universal invocation**: Works the same when run from the project root or from the `deploy/` folder
7
+ - ✅ **Automatic Node.js version detection**: Priority is CLI param → .envrc → current version
8
+ - ✅ **Smart Node.js lookup**: NVM paths → system paths
9
+ - ✅ **Automatic config reading**: package.json, config for port
10
+ - ✅ **systemd unit generation**: Correct paths and settings
11
+ - ✅ **Process management**: Stops processes bound to ports on deletion
12
+ - ✅ **Instance support**: Service name can be extended with suffix `--<instance>` from `.env` (variable `SERVICE_INSTANCE`)
13
13
 
14
- ## Operation Algorithm
14
+ ## Requirements and how to run
15
15
 
16
- ### Working Directory Determination
16
+ - The file is executable: `deploy/srv.cjs` has a shebang `#!/usr/bin/env node`. On the server, make sure the file has execute permissions:
17
17
 
18
18
  ```bash
19
- SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # Script folder: /path/to/project/deploy/
20
- PROJECT_ROOT="$(dirname "$SCRIPT_DIR")" # Project root: /path/to/project/
19
+ chmod +x deploy/srv.cjs
21
20
  ```
22
21
 
23
- **Result**: Regardless of launch location, the script always uses the project root for:
24
- - Reading `package.json`
25
- - Reading `.envrc`
26
- - Reading configuration
27
- - Setting `WorkingDirectory` in systemd unit
28
-
29
- ### Node.js Version Detection Algorithm
30
-
31
- 1. **Parameter `-v <version>`** (highest priority)
32
- ```bash
33
- ./deploy/srv.sh install -v 20.10.0
34
- ```
35
-
36
- 2. **`.envrc` file in project root**
37
- ```bash
38
- # Searches for line like:
39
- nvm use 22.17.1
40
- # Extracts: 22.17.1
41
- ```
42
-
43
- 3. **Current Node.js version** (fallback)
44
- ```bash
45
- node -v # For example: v22.17.1 → 22.17.1
46
- ```
47
-
48
- ### Node.js Path Search Algorithm
49
-
50
- 1. **NVM path** (priority)
51
- ```bash
52
- $HOME/.nvm/versions/node/v22.17.1/bin/node
53
- ```
54
-
55
- 2. **System path** (fallback)
56
- ```bash
57
- which node # For example: /usr/bin/node
58
- ```
59
-
60
- ### Service Name Detection Algorithm
61
-
62
- 1. **Parameter `-n <name>`** (priority)
63
- 2. **`name` value from package.json** (default)
22
+ - You can run it in two equivalent ways:
64
23
 
65
- ### Port Detection Algorithm
24
+ ```bash
25
+ # From the project root or from the deploy/ folder
26
+ ./deploy/srv.cjs <command> [options]
66
27
 
67
- 1. **Parameter `-p <port>`** (priority)
68
- 2. **`config.webServer.port` value** (automatic)
69
- ```javascript
70
- // Executed from project root:
71
- const config = require('config');
72
- console.log(config.webServer?.port);
73
- ```
28
+ # Or via node
29
+ node deploy/srv.cjs <command> [options]
30
+ ```
74
31
 
75
32
  ## Commands
76
33
 
77
- ### Service Installation
34
+ ### Install service
78
35
 
79
36
  ```bash
80
- # Basic installation (auto-detect all parameters)
81
- ./deploy/srv.sh install
82
- ./deploy/srv.sh i
37
+ # Basic install (auto-detect everything)
38
+ ./deploy/srv.cjs install
39
+ ./deploy/srv.cjs i
83
40
 
84
- # With custom service name
85
- ./deploy/srv.sh install -n my-custom-service
41
+ # With a custom service name
42
+ ./deploy/srv.cjs install -n my-custom-service
86
43
 
87
- # With specific Node.js version
88
- ./deploy/srv.sh install -v 20.10.0
44
+ # With a specific Node.js version
45
+ ./deploy/srv.cjs install -v 20.10.0
89
46
 
90
- # Combined parameters
91
- ./deploy/srv.sh i -n custom-service -v 22.17.1
47
+ # Combined params
48
+ ./deploy/srv.cjs i -n custom-service -v 22.17.1
92
49
  ```
93
50
 
94
51
  **What happens:**
95
- 1. Node.js version and binary path are determined
52
+ 1. Node.js version and path to the binary are determined
96
53
  2. `package.json` is read to get `main` and `name`
97
- 3. systemd unit file is generated in `/etc/systemd/system/<service_name>.service`
54
+ 3. A systemd unit file is generated at `/etc/systemd/system/<service_name>.service`
98
55
  4. `systemctl daemon-reload` is executed
99
56
  5. `systemctl enable --now <service_name>` is executed
100
57
 
101
- ### Service Removal
58
+ ### Delete service
102
59
 
103
60
  ```bash
104
61
  # Auto-detect port from config
105
- ./deploy/srv.sh delete
106
- ./deploy/srv.sh d
62
+ ./deploy/srv.cjs delete
63
+ ./deploy/srv.cjs d
107
64
 
108
- # With custom service name
109
- ./deploy/srv.sh delete -n custom-service
65
+ # With a custom service name
66
+ ./deploy/srv.cjs delete -n custom-service
110
67
 
111
- # With specific port
112
- ./deploy/srv.sh delete -p 8080
68
+ # With a specific port
69
+ ./deploy/srv.cjs delete -p 8080
113
70
 
114
- # Combined parameters
115
- ./deploy/srv.sh d -n custom-service -p 9021
71
+ # Combined params
72
+ ./deploy/srv.cjs d -n custom-service -p 8080
116
73
  ```
117
74
 
118
75
  **What happens:**
119
- 1. Port is determined from configuration or parameter
76
+ 1. Port is determined from config or CLI param
120
77
  2. `systemctl stop <service_name>` is executed
121
78
  3. `systemctl disable <service_name>` is executed
122
79
  4. Unit file `/etc/systemd/system/<service_name>.service` is removed
123
- 5. Process on specified port is terminated (if exists)
80
+ 5. Process on the specified port is terminated (if exists)
124
81
  6. `systemctl daemon-reload` is executed
125
82
 
126
- ### Service Reinstallation
83
+ ### Reinstall service
127
84
 
128
85
  ```bash
129
- # Complete reinstallation
130
- ./deploy/srv.sh reinstall
131
- ./deploy/srv.sh r
86
+ # Full reinstall
87
+ ./deploy/srv.cjs reinstall
88
+ ./deploy/srv.cjs r
132
89
 
133
- # With parameters
134
- ./deploy/srv.sh r -n custom-service -v 22.17.1 -p 9021
90
+ # With params
91
+ ./deploy/srv.cjs r -n custom-service -v 22.17.1 -p 8080
135
92
  ```
136
93
 
137
94
  **What happens:**
138
- 1. Complete service removal is performed (as in `delete`)
139
- 2. Complete service installation is performed (as in `install`)
140
- 3. Status is shown and log viewing is started
95
+ 1. Performs a full deletion (as in `delete`)
96
+ 2. Performs a full installation (as in `install`)
97
+ 3. Shows status and starts tailing logs
141
98
 
142
- ## Execution Examples
99
+ ## How it works
143
100
 
144
- ### From Project Root
101
+ ### Resolving working directories
145
102
 
146
- ```bash
147
- # All commands work from root
148
- ./deploy/srv.sh install
149
- ./deploy/srv.sh delete -p 9021
150
- ./deploy/srv.sh reinstall -n mcp-fin-office-dev
103
+ The script computes directories by itself (within Node.js runtime):
104
+
105
+ ```javascript
106
+ // deploy/srv.cjs
107
+ const SCRIPT_DIR = __dirname; // /path/to/project/deploy/
108
+ const PROJECT_ROOT = path.resolve(SCRIPT_DIR, '..'); // /path/to/project/
109
+ process.chdir(PROJECT_ROOT);
151
110
  ```
152
111
 
153
- ### From deploy Folder
112
+ **Result**: Regardless of where it's launched, the script always uses the project root for:
113
+ - Reading `package.json`
114
+ - Reading `.envrc`
115
+ - Reading configuration
116
+ - Setting `WorkingDirectory` in the systemd unit
154
117
 
155
- ```bash
156
- cd deploy/
118
+ ### Node.js version detection algorithm
157
119
 
158
- # All commands work from deploy folder
159
- ./srv.sh install
160
- ./srv.sh delete -p 9021
161
- ./srv.sh reinstall -n mcp-fin-office-dev
162
- ```
120
+ 1. **CLI param `-v <version>`** (highest priority)
121
+ ```bash
122
+ ./deploy/srv.cjs install -v 20.10.0
123
+ ```
163
124
 
164
- ### Real-world Project Examples
125
+ 2. **`.envrc` file in the project root**
126
+ ```bash
127
+ # Looks for a line like:
128
+ nvm use 22.17.1
129
+ # Extracts: 22.17.1
130
+ ```
165
131
 
166
- ```bash
167
- # Development installation
168
- ./deploy/srv.sh install -n mcp-fin-office-dev -v 22.17.1
132
+ 3. **Current Node.js version** (fallback)
133
+ ```bash
134
+ node -v # For example: v22.17.1 → 22.17.1
135
+ ```
169
136
 
170
- # Production installation with auto-detection
171
- ./deploy/srv.sh install
137
+ ### Node.js binary path lookup
172
138
 
173
- # Remove dev version
174
- ./deploy/srv.sh delete -n mcp-fin-office-dev
139
+ 1. **NVM path** (priority)
140
+ ```bash
141
+ $HOME/.nvm/versions/node/v22.17.1/bin/node
142
+ ```
143
+
144
+ 2. **System path** (fallback)
145
+ ```bash
146
+ which node # For example: /usr/bin/node
147
+ ```
148
+
149
+ ### Service name resolution
150
+
151
+ 1. **CLI param `-n <name>`** (priority)
152
+ 2. **`.env` → `SERVICE_NAME`** (if provided)
153
+ 3. **`name` value from package.json** (default)
154
+ 4. Additionally: if `SERVICE_INSTANCE` is set in `.env`, the final name becomes `<name>--<instance>`
155
+
156
+ ### Port resolution
157
+
158
+ 1. **CLI param `-p <port>`** (priority)
159
+ 2. **`config.webServer.port` value** (automatic)
160
+ ```javascript
161
+ // Executed from the project root:
162
+ const config = require('config');
163
+ console.log(config.webServer?.port);
164
+ ```
175
165
 
176
- # Quick reinstall after changes
177
- ./deploy/srv.sh reinstall
178
- ```
179
166
 
180
- ## Generated systemd Unit File
167
+ ## Generated systemd unit file
181
168
 
182
169
  ```ini
183
170
  [Unit]
184
- Description=mcp-fin-office
171
+ Description=<serviceName>
185
172
  After=network.target
186
173
  StartLimitIntervalSec=0
187
174
 
@@ -189,159 +176,35 @@ StartLimitIntervalSec=0
189
176
  User=root
190
177
  WorkingDirectory=/path/to/project/root
191
178
  EnvironmentFile=/path/to/project/root/.env
192
- ExecStart=/root/.nvm/versions/node/v22.17.1/bin/node dist/src/_core/index.js
179
+ ExecStart=/root/.nvm/versions/node/v22.17.1/bin/node <package.json.main>
193
180
  Restart=always
194
181
  RestartSec=3
195
- StandardOutput=syslog
196
- StandardError=syslog
197
182
 
198
183
  [Install]
199
184
  WantedBy=multi-user.target
200
185
  ```
201
186
 
202
- ## Debugging and Monitoring
187
+ ## Debugging and monitoring
203
188
 
204
- ### View Status
205
189
 
206
- ```bash
207
- systemctl status mcp-fin-office
208
- ```
209
-
210
- ### View Logs
211
-
212
- ```bash
213
- # Recent logs
214
- journalctl -u mcp-fin-office
215
-
216
- # Follow logs in real-time
217
- journalctl -u mcp-fin-office -f
218
-
219
- # Logs from last hour
220
- journalctl -u mcp-fin-office --since "1 hour ago"
221
- ```
222
-
223
- ### Manual Control
190
+ ### Viewing logs
224
191
 
225
192
  ```bash
226
- # Stop
227
- sudo systemctl stop mcp-fin-office
193
+ # Short status with logs
194
+ systemctl -l status <serviceName>
228
195
 
229
- # Start
230
- sudo systemctl start mcp-fin-office
196
+ # Latest logs (compact output)
197
+ journalctl -o cat -u <serviceName>
231
198
 
232
- # Restart
233
- sudo systemctl restart mcp-fin-office
199
+ # Follow logs in real time (equivalent to what `reinstall` starts)
200
+ journalctl -o cat -xefu <serviceName>
234
201
 
235
- # Disable autostart
236
- sudo systemctl disable mcp-fin-office
202
+ # Logs for the last hour
203
+ journalctl -u <serviceName> --since "1 hour ago"
237
204
  ```
238
205
 
239
- ## Requirements
240
-
241
- - **Operating System**: Linux with systemd
242
- - **Permissions**: `sudo` privileges for managing systemd services
243
- - **Node.js**: Installed Node.js (NVM or system installation)
244
- - **Project Files**:
245
- - `package.json` in project root
246
- - Built application (file specified in `package.json` `main`)
247
- - Optional: `.envrc` for Node.js version detection
248
- - Optional: `config/` folder for port detection
249
-
250
- ## File Structure
251
-
252
- ```
253
- project-root/
254
- ├── package.json # Source: name, main
255
- ├── .envrc # Optional: Node.js version
256
- ├── config/
257
- │ └── default.yaml # Optional: webServer.port
258
- ├── deploy/
259
- │ ├── srv.sh # ← This script
260
- │ └── srv.sh.readme.md # ← This documentation
261
- └── dist/
262
- └── src/
263
- └── _core/
264
- └── index.js # Main application file
265
- ```
266
-
267
- ## Troubleshooting
268
-
269
- ### Script Cannot Find Node.js
206
+ ### Manual control
270
207
 
271
208
  ```bash
272
- # Check Node.js availability
273
- node -v
274
- which node
275
-
276
- # Check NVM installation
277
- ls -la ~/.nvm/versions/node/
278
- ```
279
-
280
- ### package.json Reading Error
281
-
282
- ```bash
283
- # Check JSON syntax
284
- cat package.json | jq .
285
-
286
- # Check for name and main fields
287
- node -e "const pkg = require('./package.json'); console.log('name:', pkg.name); console.log('main:', pkg.main);"
288
- ```
289
-
290
- ### Port Detection Error
291
-
292
- ```bash
293
- # Check configuration
294
- node -e "const c = require('config'); console.log('port:', c.webServer?.port);"
295
-
296
- # Check configuration files
297
- ls -la config/
298
- cat config/default.yaml | grep -A5 webServer
299
- ```
300
-
301
- ### Access Permissions
302
-
303
- ```bash
304
- # Check systemd management permissions
305
- sudo systemctl --version
306
-
307
- # Check write permissions for /etc/systemd/system/
308
- sudo ls -la /etc/systemd/system/
309
- ```
310
-
311
- ## CI/CD Integration
312
-
313
- ### Automated Deployment
314
-
315
- ```bash
316
- #!/bin/bash
317
- # deploy.sh
318
-
319
- # Build project
320
- npm ci
321
- npm run build
322
-
323
- # Install/reinstall service
324
- ./deploy/srv.sh reinstall
325
-
326
- # Check successful startup
327
- sleep 5
328
- systemctl is-active --quiet mcp-fin-office && echo "Service started successfully"
329
- ```
330
-
331
- ### Rollback Script
332
-
333
- ```bash
334
- #!/bin/bash
335
- # rollback.sh
336
-
337
- # Stop current service
338
- ./deploy/srv.sh delete
339
-
340
- # Restore previous version
341
- git checkout HEAD~1
342
- npm ci
343
- npm run build
344
-
345
- # Start previous version
346
- ./deploy/srv.sh install
209
+ sudo systemctl start|stop|restart|disable|status <serviceName>
347
210
  ```