panrouter 6.3.8 → 6.3.10
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/pool-worker.mjs +33 -19
package/package.json
CHANGED
package/pool-worker.mjs
CHANGED
|
@@ -142,6 +142,10 @@ function connectToHub() {
|
|
|
142
142
|
}
|
|
143
143
|
log(`主控已确认节点注册 (ID: ${msg.nodeId})`, "OK");
|
|
144
144
|
startHeartbeat();
|
|
145
|
+
// 如果 9router 已经就绪,通知这个新连上的主控
|
|
146
|
+
if (_serverReady) {
|
|
147
|
+
safeSend({ type: "ready" });
|
|
148
|
+
}
|
|
145
149
|
break;
|
|
146
150
|
|
|
147
151
|
case "request":
|
|
@@ -152,6 +156,9 @@ function connectToHub() {
|
|
|
152
156
|
ws.send(JSON.stringify({ type: "pong" }));
|
|
153
157
|
break;
|
|
154
158
|
|
|
159
|
+
case "pong":
|
|
160
|
+
break;
|
|
161
|
+
|
|
155
162
|
case "upgrade":
|
|
156
163
|
handleUpgrade();
|
|
157
164
|
break;
|
|
@@ -215,7 +222,9 @@ function handleUpgrade() {
|
|
|
215
222
|
hasNewer = true;
|
|
216
223
|
}
|
|
217
224
|
|
|
218
|
-
|
|
225
|
+
// ponytail: Windows 跳过内联 install(当前进程锁着 npm 目录必 EBUSY)
|
|
226
|
+
// 后续 start /b 脚本在进程退出后再执行 install
|
|
227
|
+
if (hasNewer && process.platform !== 'win32') {
|
|
219
228
|
try {
|
|
220
229
|
execSync("npm install -g panrouter@latest", { stdio: "inherit", timeout: 120000 });
|
|
221
230
|
} catch (e) {
|
|
@@ -223,26 +232,25 @@ function handleUpgrade() {
|
|
|
223
232
|
}
|
|
224
233
|
}
|
|
225
234
|
|
|
226
|
-
// 从磁盘重新读(跳过 require 缓存)
|
|
227
|
-
const newVersion = JSON.parse(fs.readFileSync(pkgPath, "utf-8")).version;
|
|
228
|
-
|
|
229
235
|
log("正在重启 9router...");
|
|
230
236
|
killPort(SERVER_PORT);
|
|
231
237
|
|
|
238
|
+
// Windows:无论如何走 start /b 脚本(当前进程锁着 npm 目录无法内联升级)
|
|
239
|
+
if (process.platform === 'win32') {
|
|
240
|
+
const tmpDir = process.env.TEMP || process.env.TMP || "C:\\Windows\\Temp";
|
|
241
|
+
// 如果已经是最新版也跳过 install
|
|
242
|
+
const noInstall = hasNewer ? "" : "& npm cache clean --force 2>nul & npm install -g panrouter@latest";
|
|
243
|
+
// 先 ping 等当前进程退出锁释放 → 杀残留 node → 切 tmp 目录避免被删 → install → 启动
|
|
244
|
+
const upgradeCmd = `start /b cmd /c "@ping 127.0.0.1 -n 3 >nul && taskkill /f /im node.exe 2>nul & ping 127.0.0.1 -n 3 >nul & cd /d \"${tmpDir}\"${noInstall} && panrouter --pool"`;
|
|
245
|
+
try { execSync(upgradeCmd, { stdio: 'pipe', timeout: 5000, shell: true }); } catch {}
|
|
246
|
+
log("升级脚本已提交 (当前进程退出后自动执行),旧进程退出", "OFF");
|
|
247
|
+
process.exit(0);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// Unix:检查版本,需要就 install,然后 spawn 新实例
|
|
251
|
+
const newVersion = JSON.parse(fs.readFileSync(pkgPath, "utf-8")).version;
|
|
232
252
|
if (oldVersion !== newVersion) {
|
|
233
253
|
log(`版本变更: v${oldVersion} → v${newVersion},升级并重启`, "OK");
|
|
234
|
-
|
|
235
|
-
// Windows 下当前进程锁住了 npm 目录 → 先 exit 释放锁再 npm install
|
|
236
|
-
// 用 start /b 提交一个后台脚本,等 2 秒(进程退出锁释放)后执行升级 + 启动
|
|
237
|
-
// start /b 的输出会打到当前终端,用户能看到进度
|
|
238
|
-
if (process.platform === 'win32') {
|
|
239
|
-
const cmd = `start /b cmd /c "@ping 127.0.0.1 -n 3 >nul && npm install -g panrouter@latest && panrouter --pool"`;
|
|
240
|
-
try { execSync(cmd, { stdio: 'pipe', timeout: 5000, shell: true }); } catch {}
|
|
241
|
-
log("升级脚本已提交 (当前进程退出后自动执行),旧进程退出", "OFF");
|
|
242
|
-
process.exit(0);
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
// Unix 可以直接 spawn(不会锁)
|
|
246
254
|
spawn(process.execPath, [process.argv[1], "--pool"], {
|
|
247
255
|
cwd: __dirname,
|
|
248
256
|
stdio: "inherit",
|
|
@@ -588,10 +596,16 @@ export async function start() {
|
|
|
588
596
|
const checkReady = setInterval(async () => {
|
|
589
597
|
if (_serverReady || (await isPortOpen(SERVER_PORT))) {
|
|
590
598
|
_serverReady = true;
|
|
591
|
-
clearInterval(checkReady);
|
|
592
599
|
startWatchdog();
|
|
593
|
-
|
|
594
|
-
|
|
600
|
+
// 持续发 ready 直到 WebSocket 连通(注册可能还没完成)
|
|
601
|
+
const tryReady = setInterval(() => {
|
|
602
|
+
if (ws && ws.readyState === WebSocket.OPEN) {
|
|
603
|
+
ws.send(JSON.stringify({ type: "ready" }));
|
|
604
|
+
clearInterval(tryReady);
|
|
605
|
+
clearInterval(checkReady);
|
|
606
|
+
log("9router 已就绪,节点可正常处理请求", "ON");
|
|
607
|
+
}
|
|
608
|
+
}, 1000);
|
|
595
609
|
}
|
|
596
610
|
}, 3000);
|
|
597
611
|
}
|