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