From e5bf8dc30470bd4ce9cf78ce75175a9152a87854 Mon Sep 17 00:00:00 2001 From: liangtongchuan Date: Wed, 12 Apr 2023 14:26:59 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9E=20fix(monitor):=20=E8=A1=A5?= =?UTF-8?q?=E5=85=85=E5=88=86=E5=B8=83=E5=BC=8F=E6=9C=8D=E5=8A=A1=E5=99=A8?= =?UTF-8?q?=E7=9B=91=E6=8E=A7=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- game-server/pm2DistributeConfig.js | 23 ++++++++++++++++++++++- game-server/pm2StarterDistribute.sh | 5 +++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/game-server/pm2DistributeConfig.js b/game-server/pm2DistributeConfig.js index 97fe05fbf..0389e3aaf 100644 --- a/game-server/pm2DistributeConfig.js +++ b/game-server/pm2DistributeConfig.js @@ -54,6 +54,7 @@ let onairEnvs = ['sq1', 'sq3', 'sq4', 'sq7', 'sq9']; // var masterConfig = masterJsonFile[masterEnvType]; var serversConfig = serversJosnFile[distributeEnvType]; +let titles = []; //生成master 的配置 // var pm2Master = clone(processConfigType); @@ -99,7 +100,8 @@ for (serverType in serversConfig) { appPm2Config.out_file = './logs/' + singleServer.id + '_app.log'; appPm2Config.error_file = './logs/' + singleServer.id + '_error.log'; } - + appPm2Config.env={NODE_PROCESS_TITLE: distributeEnvType+'_'+singleServer.id}; + titles.push(distributeEnvType+'_'+singleServer.id); resultJson.apps.push(appPm2Config); } } @@ -121,6 +123,25 @@ fs.writeFile(outputFilePath, resultFileStr, function (err) { } }); +const xtransitConfigFile = './xtransitConfig/'+masterEnvType+'.js'; +if (fs.existsSync(xtransitConfigFile)) { + fs.readFile(xtransitConfigFile, 'utf8', function (err, data) { + if (err) { + console.log(err); + return; + } + const newData = data.replace(/titles:\s*\[[^\]]*\]/, "titles: "+JSON.stringify(titles)); + + // 3. 将更改后的内容写回文件 + fs.writeFile(xtransitConfigFile, newData, 'utf8', (err) => { + if (err) { + console.error('Error writing file:', err); + return; + } + console.log('File updated successfully.'); + }); + }); +} diff --git a/game-server/pm2StarterDistribute.sh b/game-server/pm2StarterDistribute.sh index d017a743b..5ddaff3fc 100755 --- a/game-server/pm2StarterDistribute.sh +++ b/game-server/pm2StarterDistribute.sh @@ -12,3 +12,8 @@ npm install #安装依赖库 npm run build node pm2DistributeConfig.js ${1} ${2} #使用pm2来做进程管理,生成进程配置文件 pm2 start pomeloPm2Start.json #pm2 启动游戏服务器 +json=$(cat config.json) +env=$(echo "$json" | grep -o '"env": *"[^"]*"' | sed 's/"env": *"\(.*\)"$/\1/') +echo $env +xtransit stop all +xtransit start xtransitConfig/$env.js