@yeaft/webchat-agent 1.0.126 → 1.0.128
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/package.json +1 -1
- package/service/windows.js +23 -19
package/package.json
CHANGED
package/service/windows.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import { execSync, spawn } from 'child_process';
|
|
5
5
|
import { existsSync, mkdirSync, writeFileSync, readFileSync, unlinkSync } from 'fs';
|
|
6
6
|
import { join, dirname } from 'path';
|
|
7
|
-
import { getConfigDir, getLogDir, getNodePath, getCliPath, getPm2AppName, DEFAULT_INSTANCE_ID } from './config.js';
|
|
7
|
+
import { getConfigDir, getLogDir, getNodePath, getCliPath, getPm2AppName, loadServiceConfig, DEFAULT_INSTANCE_ID } from './config.js';
|
|
8
8
|
|
|
9
9
|
const WIN_TASK_NAME = 'YeaftAgent';
|
|
10
10
|
|
|
@@ -61,6 +61,26 @@ function generateEcosystem(config) {
|
|
|
61
61
|
`;
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
+
function registerCurrentAgent(instanceId) {
|
|
65
|
+
const config = loadServiceConfig(instanceId);
|
|
66
|
+
if (!config) {
|
|
67
|
+
console.error('Service not installed. Run "yeaft-agent install" first.');
|
|
68
|
+
process.exit(1);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const pm2AppName = getPm2AppName(instanceId);
|
|
72
|
+
const ecoPath = getEcosystemPath(instanceId);
|
|
73
|
+
mkdirSync(getLogDir(instanceId), { recursive: true });
|
|
74
|
+
writeFileSync(ecoPath, generateEcosystem(config));
|
|
75
|
+
|
|
76
|
+
// PM2 keeps the original script path and package metadata when an existing
|
|
77
|
+
// app is started or restarted by name. Re-register from the current CLI so
|
|
78
|
+
// npm prefix changes and upgraded package versions are actually picked up.
|
|
79
|
+
try { execSync(`pm2 delete ${pm2AppName}`, { stdio: 'pipe' }); } catch {}
|
|
80
|
+
execSync(`pm2 start "${ecoPath}"`, { stdio: 'inherit' });
|
|
81
|
+
execSync('pm2 save', { stdio: 'pipe' });
|
|
82
|
+
}
|
|
83
|
+
|
|
64
84
|
export function winInstall(config) {
|
|
65
85
|
ensurePm2();
|
|
66
86
|
const logDir = getLogDir(config.instanceId);
|
|
@@ -130,19 +150,7 @@ export function winUninstall(instanceId = DEFAULT_INSTANCE_ID) {
|
|
|
130
150
|
}
|
|
131
151
|
|
|
132
152
|
export function winStart(instanceId = DEFAULT_INSTANCE_ID) {
|
|
133
|
-
|
|
134
|
-
try {
|
|
135
|
-
execSync(`pm2 start ${pm2AppName}`, { stdio: 'inherit' });
|
|
136
|
-
} catch {
|
|
137
|
-
// Try ecosystem file
|
|
138
|
-
const ecoPath = getEcosystemPath(instanceId);
|
|
139
|
-
if (existsSync(ecoPath)) {
|
|
140
|
-
execSync(`pm2 start "${ecoPath}"`, { stdio: 'inherit' });
|
|
141
|
-
} else {
|
|
142
|
-
console.error('Service not installed. Run "yeaft-agent install" first.');
|
|
143
|
-
process.exit(1);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
153
|
+
registerCurrentAgent(instanceId);
|
|
146
154
|
}
|
|
147
155
|
|
|
148
156
|
export function winStop(instanceId = DEFAULT_INSTANCE_ID) {
|
|
@@ -154,11 +162,7 @@ export function winStop(instanceId = DEFAULT_INSTANCE_ID) {
|
|
|
154
162
|
}
|
|
155
163
|
|
|
156
164
|
export function winRestart(instanceId = DEFAULT_INSTANCE_ID) {
|
|
157
|
-
|
|
158
|
-
execSync(`pm2 restart ${getPm2AppName(instanceId)}`, { stdio: 'inherit' });
|
|
159
|
-
} catch {
|
|
160
|
-
console.error('Service not running. Use "yeaft-agent start" to start.');
|
|
161
|
-
}
|
|
165
|
+
registerCurrentAgent(instanceId);
|
|
162
166
|
}
|
|
163
167
|
|
|
164
168
|
/**
|