fa-mcp-sdk 0.2.84 → 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.
- package/bin/fa-mcp.js +46 -7
- package/cli-template/.env.example +0 -2
- package/cli-template/config/_local.yaml +3 -2
- package/cli-template/config/default.yaml +18 -8
- package/cli-template/deploy/{mcp-template.com.conf → NGINX/sites-enabled/mcp-template.com.conf} +1 -1
- package/cli-template/deploy/NGINX/snippets/ssl-params.conf +18 -0
- package/cli-template/deploy/NGINX/snippets/ssl-wildcard.conf +3 -0
- package/cli-template/deploy/srv.cjs +449 -0
- package/cli-template/deploy/srv.sh.readme.md +122 -259
- package/cli-template/update.cjs +32 -25
- package/dist/core/logger.d.ts.map +1 -1
- package/dist/core/logger.js +7 -3
- package/dist/core/logger.js.map +1 -1
- package/dist/core/token/token-core.js +4 -3
- package/dist/core/token/token-core.js.map +1 -1
- package/package.json +1 -1
- package/cli-template/deploy/srv.sh +0 -359
|
@@ -1,187 +1,174 @@
|
|
|
1
|
-
# srv.
|
|
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
|
|
8
|
-
- ✅ **
|
|
9
|
-
- ✅ **Smart Node.js
|
|
10
|
-
- ✅ **Automatic
|
|
11
|
-
- ✅ **systemd unit
|
|
12
|
-
- ✅ **Process management**: Stops processes
|
|
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
|
-
##
|
|
14
|
+
## Requirements and how to run
|
|
15
15
|
|
|
16
|
-
|
|
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
|
-
|
|
20
|
-
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")" # Project root: /path/to/project/
|
|
19
|
+
chmod +x deploy/srv.cjs
|
|
21
20
|
```
|
|
22
21
|
|
|
23
|
-
|
|
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
|
-
|
|
24
|
+
```bash
|
|
25
|
+
# From the project root or from the deploy/ folder
|
|
26
|
+
./deploy/srv.cjs <command> [options]
|
|
66
27
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
###
|
|
34
|
+
### Install service
|
|
78
35
|
|
|
79
36
|
```bash
|
|
80
|
-
# Basic
|
|
81
|
-
./deploy/srv.
|
|
82
|
-
./deploy/srv.
|
|
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.
|
|
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.
|
|
44
|
+
# With a specific Node.js version
|
|
45
|
+
./deploy/srv.cjs install -v 20.10.0
|
|
89
46
|
|
|
90
|
-
# Combined
|
|
91
|
-
./deploy/srv.
|
|
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
|
|
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
|
|
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
|
-
###
|
|
58
|
+
### Delete service
|
|
102
59
|
|
|
103
60
|
```bash
|
|
104
61
|
# Auto-detect port from config
|
|
105
|
-
./deploy/srv.
|
|
106
|
-
./deploy/srv.
|
|
62
|
+
./deploy/srv.cjs delete
|
|
63
|
+
./deploy/srv.cjs d
|
|
107
64
|
|
|
108
|
-
# With custom service name
|
|
109
|
-
./deploy/srv.
|
|
65
|
+
# With a custom service name
|
|
66
|
+
./deploy/srv.cjs delete -n custom-service
|
|
110
67
|
|
|
111
|
-
# With specific port
|
|
112
|
-
./deploy/srv.
|
|
68
|
+
# With a specific port
|
|
69
|
+
./deploy/srv.cjs delete -p 8080
|
|
113
70
|
|
|
114
|
-
# Combined
|
|
115
|
-
./deploy/srv.
|
|
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
|
|
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
|
-
###
|
|
83
|
+
### Reinstall service
|
|
127
84
|
|
|
128
85
|
```bash
|
|
129
|
-
#
|
|
130
|
-
./deploy/srv.
|
|
131
|
-
./deploy/srv.
|
|
86
|
+
# Full reinstall
|
|
87
|
+
./deploy/srv.cjs reinstall
|
|
88
|
+
./deploy/srv.cjs r
|
|
132
89
|
|
|
133
|
-
# With
|
|
134
|
-
./deploy/srv.
|
|
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.
|
|
139
|
-
2.
|
|
140
|
-
3.
|
|
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
|
-
##
|
|
99
|
+
## How it works
|
|
143
100
|
|
|
144
|
-
###
|
|
101
|
+
### Resolving working directories
|
|
145
102
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
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
|
-
|
|
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
|
-
|
|
156
|
-
cd deploy/
|
|
118
|
+
### Node.js version detection algorithm
|
|
157
119
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
./srv.
|
|
161
|
-
|
|
162
|
-
```
|
|
120
|
+
1. **CLI param `-v <version>`** (highest priority)
|
|
121
|
+
```bash
|
|
122
|
+
./deploy/srv.cjs install -v 20.10.0
|
|
123
|
+
```
|
|
163
124
|
|
|
164
|
-
|
|
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
|
-
|
|
167
|
-
|
|
168
|
-
|
|
132
|
+
3. **Current Node.js version** (fallback)
|
|
133
|
+
```bash
|
|
134
|
+
node -v # For example: v22.17.1 → 22.17.1
|
|
135
|
+
```
|
|
169
136
|
|
|
170
|
-
|
|
171
|
-
./deploy/srv.sh install
|
|
137
|
+
### Node.js binary path lookup
|
|
172
138
|
|
|
173
|
-
|
|
174
|
-
|
|
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
|
|
167
|
+
## Generated systemd unit file
|
|
181
168
|
|
|
182
169
|
```ini
|
|
183
170
|
[Unit]
|
|
184
|
-
Description
|
|
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
|
|
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
|
|
187
|
+
## Debugging and monitoring
|
|
203
188
|
|
|
204
|
-
### View Status
|
|
205
189
|
|
|
206
|
-
|
|
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
|
-
#
|
|
227
|
-
|
|
193
|
+
# Short status with logs
|
|
194
|
+
systemctl -l status <serviceName>
|
|
228
195
|
|
|
229
|
-
#
|
|
230
|
-
|
|
196
|
+
# Latest logs (compact output)
|
|
197
|
+
journalctl -o cat -u <serviceName>
|
|
231
198
|
|
|
232
|
-
#
|
|
233
|
-
|
|
199
|
+
# Follow logs in real time (equivalent to what `reinstall` starts)
|
|
200
|
+
journalctl -o cat -xefu <serviceName>
|
|
234
201
|
|
|
235
|
-
#
|
|
236
|
-
|
|
202
|
+
# Logs for the last hour
|
|
203
|
+
journalctl -u <serviceName> --since "1 hour ago"
|
|
237
204
|
```
|
|
238
205
|
|
|
239
|
-
|
|
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
|
-
|
|
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
|
```
|
package/cli-template/update.cjs
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
1
3
|
// noinspection UnnecessaryLocalVariableJS
|
|
2
4
|
|
|
3
5
|
const fs = require('fs');
|
|
@@ -5,12 +7,12 @@ const path = require('path');
|
|
|
5
7
|
const { execSync, spawn } = require('child_process');
|
|
6
8
|
const os = require('os');
|
|
7
9
|
|
|
8
|
-
const version = '2025.11.
|
|
10
|
+
const version = '2025.11.25-0506';
|
|
9
11
|
console.log(`Update script version: ${version}`);
|
|
10
12
|
|
|
11
|
-
//
|
|
13
|
+
// Name of this folder
|
|
12
14
|
const scriptDirName = require('path').basename(__dirname);
|
|
13
|
-
//
|
|
15
|
+
// Changing the working directory to a script directory
|
|
14
16
|
process.chdir(__dirname);
|
|
15
17
|
const CWD = process.cwd();
|
|
16
18
|
const VON = path.resolve(path.join(CWD, '..'));
|
|
@@ -122,7 +124,7 @@ const truncateCumulativeLogIfNeeded = () => {
|
|
|
122
124
|
const tailContent = buffer.toString('utf8').replace(/^[\r\n]*/, ''); // Remove leading newlines
|
|
123
125
|
fs.writeFileSync(logFile, tailContent);
|
|
124
126
|
|
|
125
|
-
|
|
127
|
+
logIt(`Cumulative log truncated to ${Math.round(tailContent.length / 1024)}KB`);
|
|
126
128
|
}
|
|
127
129
|
}
|
|
128
130
|
} catch (error) {
|
|
@@ -152,10 +154,7 @@ function execCommand (command, options = {}, withSetupScript = false) {
|
|
|
152
154
|
});
|
|
153
155
|
return result;
|
|
154
156
|
} catch (error) {
|
|
155
|
-
|
|
156
|
-
throw error;
|
|
157
|
-
}
|
|
158
|
-
return error.stdout || '';
|
|
157
|
+
throw error;
|
|
159
158
|
}
|
|
160
159
|
}
|
|
161
160
|
|
|
@@ -322,7 +321,10 @@ function getServiceName () {
|
|
|
322
321
|
serviceName = packageJson.name;
|
|
323
322
|
}
|
|
324
323
|
|
|
325
|
-
return
|
|
324
|
+
return {
|
|
325
|
+
serviceName,
|
|
326
|
+
serviceNamePM: `${serviceName}${serviceInstance}`,
|
|
327
|
+
};
|
|
326
328
|
} catch (error) {
|
|
327
329
|
console.error('Error getting service name:', error.message);
|
|
328
330
|
process.exit(1);
|
|
@@ -334,7 +336,7 @@ function getServiceName () {
|
|
|
334
336
|
*/
|
|
335
337
|
function systemctlServiceExists (serviceName) {
|
|
336
338
|
try {
|
|
337
|
-
execCommand(`systemctl list-unit-files "${serviceName}.service"`);
|
|
339
|
+
const res = execCommand(`systemctl list-unit-files "${serviceName}.service"`);
|
|
338
340
|
return true;
|
|
339
341
|
} catch {
|
|
340
342
|
return false;
|
|
@@ -343,8 +345,8 @@ function systemctlServiceExists (serviceName) {
|
|
|
343
345
|
|
|
344
346
|
function pm2ServiceExists (serviceName) {
|
|
345
347
|
try {
|
|
346
|
-
execCommand(`pm2 id "${serviceName}"`);
|
|
347
|
-
return
|
|
348
|
+
const res = execCommand(`pm2 id "${serviceName}"`);
|
|
349
|
+
return /\[\s*\d\s*]/.test(res);
|
|
348
350
|
} catch {
|
|
349
351
|
return false;
|
|
350
352
|
}
|
|
@@ -374,7 +376,11 @@ function getRepoInfo () {
|
|
|
374
376
|
upstreamHash,
|
|
375
377
|
};
|
|
376
378
|
} catch (error) {
|
|
377
|
-
|
|
379
|
+
const message = String(error.message).includes(error.stderr)
|
|
380
|
+
? error.message
|
|
381
|
+
: [error.stderr, error.message].join('\n');
|
|
382
|
+
|
|
383
|
+
console.error('Error getting repo info:', message);
|
|
378
384
|
return null;
|
|
379
385
|
}
|
|
380
386
|
}
|
|
@@ -423,7 +429,6 @@ ${colorizeHTML(clearColors(body))}
|
|
|
423
429
|
logIt(`Sending update notification to: ${emailAddress}`);
|
|
424
430
|
const subject = `${status} Update: ${serviceName} (on ${hostname})`;
|
|
425
431
|
|
|
426
|
-
// Подаем тело письма через stdin, задаем Content-Type
|
|
427
432
|
const command = `mail -a "Content-Type: text/html; charset=UTF-8" -s "${subject.replace(/"/g, '\\"')}" "${emailAddress}"`;
|
|
428
433
|
const child = spawn('/bin/bash', ['-lc', command], { stdio: ['pipe', 'inherit', 'inherit'] });
|
|
429
434
|
child.stdin.write(htmlContent);
|
|
@@ -482,18 +487,18 @@ const buildQuasar = () => {
|
|
|
482
487
|
logIt('Quasar build completed');
|
|
483
488
|
};
|
|
484
489
|
|
|
485
|
-
const restartService = (
|
|
490
|
+
const restartService = (serviceNamePM) => {
|
|
486
491
|
let srvc = '';
|
|
487
|
-
if (systemctlServiceExists(
|
|
492
|
+
if (systemctlServiceExists(serviceNamePM)) {
|
|
488
493
|
srvc = 'systemctl';
|
|
489
|
-
} else if (pm2ServiceExists(
|
|
494
|
+
} else if (pm2ServiceExists(serviceNamePM)) {
|
|
490
495
|
srvc = 'pm2';
|
|
491
496
|
} else {
|
|
492
|
-
logIt(`Service ${
|
|
497
|
+
logIt(`Service ${serviceNamePM} not found in systemctl or PM2`);
|
|
493
498
|
return;
|
|
494
499
|
}
|
|
495
|
-
logIt(`Restarting service ${
|
|
496
|
-
execCommand(`${srvc} restart "${
|
|
500
|
+
logIt(`Restarting service ${serviceNamePM} via ${srvc}`, true);
|
|
501
|
+
execCommand(`${srvc} restart "${serviceNamePM}"`);
|
|
497
502
|
logIt(`Service restarted`);
|
|
498
503
|
};
|
|
499
504
|
|
|
@@ -511,7 +516,7 @@ async function main () {
|
|
|
511
516
|
}
|
|
512
517
|
|
|
513
518
|
// Get service information
|
|
514
|
-
const serviceName = getServiceName();
|
|
519
|
+
const { serviceName, serviceNamePM } = getServiceName();
|
|
515
520
|
|
|
516
521
|
logIt(`<status>Update <y>${colorG.y(serviceName)}</y> ${nowPretty()}`);
|
|
517
522
|
|
|
@@ -533,7 +538,7 @@ async function main () {
|
|
|
533
538
|
const expectedBranch = args.expectedBranch || config.branch;
|
|
534
539
|
let updateDeployedLogFile = false;
|
|
535
540
|
try {
|
|
536
|
-
// 1)
|
|
541
|
+
// 1) If there are local changes, roll back
|
|
537
542
|
const hasChanges = execCommand('git status --porcelain').trim().length > 0;
|
|
538
543
|
if (hasChanges) {
|
|
539
544
|
logIt(`Found uncommited changes. Reset to HEAD...`);
|
|
@@ -546,7 +551,7 @@ async function main () {
|
|
|
546
551
|
const repoInfo = getRepoInfo();
|
|
547
552
|
let { branch, headHash, upstreamHash } = repoInfo;
|
|
548
553
|
|
|
549
|
-
// 2)
|
|
554
|
+
// 2) If the branch is not the same, hard switch to the head of the deleted expectedBranch
|
|
550
555
|
const expectedUpstream = `origin/${expectedBranch}`;
|
|
551
556
|
if (branch !== expectedBranch) {
|
|
552
557
|
needUpdate = true;
|
|
@@ -566,7 +571,7 @@ async function main () {
|
|
|
566
571
|
}
|
|
567
572
|
|
|
568
573
|
if (headHash !== upstreamHash) {
|
|
569
|
-
// 3)
|
|
574
|
+
// 3) The branch is the same, but we need to tighten up the changes
|
|
570
575
|
needUpdate = true;
|
|
571
576
|
updateReason += `${updateReason ? '. ' : ''}headHash !== upstreamHash (${headHash} != ${upstreamHash})`;
|
|
572
577
|
printCurrenBranch();
|
|
@@ -584,7 +589,7 @@ async function main () {
|
|
|
584
589
|
reinstallDependencies();
|
|
585
590
|
compile();
|
|
586
591
|
buildQuasar();
|
|
587
|
-
restartService(
|
|
592
|
+
restartService(serviceNamePM);
|
|
588
593
|
|
|
589
594
|
// Add completion info to build log
|
|
590
595
|
logIt(`Update completed successfully at ${new Date().toISOString().replace('T', ' ').substring(0, 19)}`);
|
|
@@ -594,6 +599,8 @@ async function main () {
|
|
|
594
599
|
} else {
|
|
595
600
|
logIt('EMAIL not found');
|
|
596
601
|
}
|
|
602
|
+
} else {
|
|
603
|
+
logIt('No changes detected. Update skipped.');
|
|
597
604
|
}
|
|
598
605
|
} catch (err) {
|
|
599
606
|
const message = String(err.message).includes(err.stderr)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/core/logger.ts"],"names":[],"mappings":"AAKA,OAAO,EAAe,MAAM,EAAE,UAAU,EAAE,OAAO,
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/core/logger.ts"],"names":[],"mappings":"AAKA,OAAO,EAAe,MAAM,EAAE,UAAU,EAAE,OAAO,EAAmB,MAAM,cAAc,CAAC;AAEzF,QAAA,MAAe,aAAa,SAAkC,CAAC;AAK/D,QAAA,IAAI,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;AAC5B,QAAA,IAAI,UAAU,EAAE,UAAU,GAAG,SAAS,CAAC;AAiDvC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,aAAa,EAAE,CAAC"}
|
package/dist/core/logger.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { red, reset } from 'af-color';
|
|
4
4
|
import { appConfig } from './bootstrap/init-config.js';
|
|
5
5
|
import { getAFLogger } from 'af-logger-ts';
|
|
6
|
-
const { level, useFileLogger } = appConfig.logger;
|
|
6
|
+
const { level, useFileLogger, dir: logDir } = appConfig.logger;
|
|
7
7
|
// Check if we're in STDIO mode to disable console logging
|
|
8
8
|
const isStdioMode = appConfig.mcp.transportType === 'stdio';
|
|
9
9
|
let logger;
|
|
@@ -22,7 +22,7 @@ if (appConfig.mcp.transportType === 'stdio') {
|
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
24
|
else {
|
|
25
|
-
const
|
|
25
|
+
const settings = {
|
|
26
26
|
level: isStdioMode ? 'error' : level, // Suppress most logs in STDIO mode
|
|
27
27
|
maxSize: '500m',
|
|
28
28
|
name: '\x1b[1P',
|
|
@@ -45,7 +45,11 @@ else {
|
|
|
45
45
|
/https?:\/\/[^:]+:[^@]+@/gi,
|
|
46
46
|
],
|
|
47
47
|
noFileLogger: !Boolean(useFileLogger),
|
|
48
|
-
}
|
|
48
|
+
};
|
|
49
|
+
if (useFileLogger && logDir) {
|
|
50
|
+
settings.logDir = logDir;
|
|
51
|
+
}
|
|
52
|
+
const { logger: l, fileLogger: fl } = getAFLogger(settings);
|
|
49
53
|
logger = l;
|
|
50
54
|
fileLogger = fl;
|
|
51
55
|
}
|