修复重启没应用代理问题
This commit is contained in:
+45
-6
@@ -31,6 +31,19 @@ class PixivServer {
|
||||
this.port = 3000; // 默认端口,会在init时重新设置
|
||||
this.logLevel = process.env.LOG_LEVEL || 'info'; // 获取日志级别
|
||||
this.isVerboseMode = ['debug', 'trace'].includes(this.logLevel.toLowerCase()); // 检查是否为详细模式
|
||||
|
||||
// 保存启动时的命令行参数和环境变量
|
||||
this.startupArgs = {
|
||||
argv: [...process.argv], // 复制命令行参数
|
||||
env: {
|
||||
PORT: process.env.PORT,
|
||||
PROXY_PORT: process.env.PROXY_PORT,
|
||||
LOG_LEVEL: process.env.LOG_LEVEL,
|
||||
NODE_ENV: process.env.NODE_ENV,
|
||||
AUTO_OPEN_BROWSER: process.env.AUTO_OPEN_BROWSER,
|
||||
UV_THREADPOOL_SIZE: process.env.UV_THREADPOOL_SIZE
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -203,15 +216,41 @@ class PixivServer {
|
||||
await this.backend.cleanup?.();
|
||||
}
|
||||
|
||||
logger.info('正在重新初始化服务器...');
|
||||
logger.info('正在使用原始启动参数重新启动服务器...');
|
||||
|
||||
// 重新初始化
|
||||
await this.init();
|
||||
// 使用spawn重新启动进程,保持原始参数
|
||||
const { spawn } = require('child_process');
|
||||
const path = require('path');
|
||||
|
||||
// 重新启动
|
||||
this.start();
|
||||
// 构建启动命令
|
||||
const nodeExecutable = process.execPath;
|
||||
const startScript = path.join(__dirname, 'start.js');
|
||||
|
||||
// 获取原始命令行参数(排除node和脚本路径)
|
||||
const originalArgs = this.startupArgs.argv.slice(2);
|
||||
|
||||
logger.info('重启命令:', nodeExecutable, [startScript, ...originalArgs]);
|
||||
|
||||
// 启动新进程
|
||||
const child = spawn(nodeExecutable, [startScript, ...originalArgs], {
|
||||
detached: true,
|
||||
stdio: 'inherit',
|
||||
env: {
|
||||
...process.env,
|
||||
...this.startupArgs.env // 恢复原始环境变量
|
||||
}
|
||||
});
|
||||
|
||||
// 分离子进程
|
||||
child.unref();
|
||||
|
||||
logger.info('新进程已启动,当前进程即将退出');
|
||||
|
||||
// 延迟退出当前进程
|
||||
setTimeout(() => {
|
||||
process.exit(0);
|
||||
}, 500);
|
||||
|
||||
logger.info('服务器重启完成');
|
||||
return { success: true, message: '服务器重启成功' };
|
||||
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user