panrouter 5.4.3 → 5.4.5
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 +15 -6
package/package.json
CHANGED
package/pool-worker.mjs
CHANGED
|
@@ -178,6 +178,8 @@ function scheduleReconnect() {
|
|
|
178
178
|
|
|
179
179
|
function handleUpgrade() {
|
|
180
180
|
log("收到主控升级指令,开始升级...", "WARN");
|
|
181
|
+
// 设关闭标志,避免 ws.close → onclose → scheduleReconnect 启动重连
|
|
182
|
+
isShuttingDown = true;
|
|
181
183
|
if (ws) {
|
|
182
184
|
try { ws.close(1000, "Upgrading"); } catch {}
|
|
183
185
|
ws = null;
|
|
@@ -201,13 +203,19 @@ function handleUpgrade() {
|
|
|
201
203
|
killPort(SERVER_PORT);
|
|
202
204
|
|
|
203
205
|
if (oldVersion !== newVersion) {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
206
|
+
log(`版本变更: v${oldVersion} → v${newVersion},升级并重启`, "OK");
|
|
207
|
+
|
|
208
|
+
// Windows 下当前进程锁住了 npm 目录 → 先 exit 释放锁再 npm install
|
|
209
|
+
// 用 start /b 提交一个后台脚本,等 2 秒(进程退出锁释放)后执行升级 + 启动
|
|
210
|
+
// start /b 的输出会打到当前终端,用户能看到进度
|
|
211
|
+
if (process.platform === 'win32') {
|
|
212
|
+
const cmd = `start /b cmd /c "@ping 127.0.0.1 -n 3 >nul && npm install -g panrouter@latest && panrouter --pool"`;
|
|
213
|
+
try { execSync(cmd, { stdio: 'pipe', timeout: 5000, shell: true }); } catch {}
|
|
214
|
+
log("升级脚本已提交 (当前进程退出后自动执行),旧进程退出", "OFF");
|
|
215
|
+
process.exit(0);
|
|
216
|
+
}
|
|
210
217
|
|
|
218
|
+
// Unix 可以直接 spawn(不会锁)
|
|
211
219
|
spawn(process.execPath, [process.argv[1], "--pool"], {
|
|
212
220
|
cwd: __dirname,
|
|
213
221
|
stdio: "inherit",
|
|
@@ -222,6 +230,7 @@ function handleUpgrade() {
|
|
|
222
230
|
}
|
|
223
231
|
|
|
224
232
|
async function doRestart() {
|
|
233
|
+
isShuttingDown = false;
|
|
225
234
|
const serverOk = await ensureServer();
|
|
226
235
|
if (!serverOk) {
|
|
227
236
|
log("代理服务重启失败", "ERR");
|