From a9808773da3cee4477d65d72ee2a5afa7def3801 Mon Sep 17 00:00:00 2001 From: aixianling Date: Fri, 10 Jan 2025 16:27:11 +0800 Subject: [PATCH] =?UTF-8?q?refactor(server):=20=E9=87=8D=E6=9E=84=20LogicS?= =?UTF-8?q?erver=20=E7=9B=91=E6=8E=A7=E5=92=8C=E5=90=AF=E5=8A=A8=E8=84=9A?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 LogicServer/daemon.sh 脚本,专门用于监控和重启 LogicServer - 修改 LogicServer/run.sh,添加启动日志输出 - 从 daemon.sh 中移除 LogicServer 相关的监控逻辑 - 在 run.sh 中注释掉 LogicServer 启动代码,统一启动逻辑 --- LogicServer/daemon.sh | 50 +++++++++++++++++++++++++++++++++++++++++++ LogicServer/run.sh | 4 +++- daemon.sh | 33 ---------------------------- run.sh | 6 +++--- 4 files changed, 56 insertions(+), 37 deletions(-) create mode 100644 LogicServer/daemon.sh diff --git a/LogicServer/daemon.sh b/LogicServer/daemon.sh new file mode 100644 index 0000000..d8d1d99 --- /dev/null +++ b/LogicServer/daemon.sh @@ -0,0 +1,50 @@ +#!/bin/bash +if [ -n "$1" ]; then + dm=$1 +else + dm='_r' +fi + +if [ -n "$2" ]; then + path=$2 +else + path=`pwd` +fi + + # check LogicServer +while true; do + sleep 8 + + datetime=`date "+%Y-%m-%d.%H:%M:%S"` + + ret=`ps x |grep $path/LogicServer/logicserver$dm|grep -v grep|grep -v "/bin/bash"|wc -l` + if [ $ret == 0 ]; then + $path/LogicServer/logicserver$dm $path/LogicServer/LogicServerLinux.txt > /dev/null & + echo "[$datetime] $path/LogicServer/logicserver$dm $path/LogicServer/LogicServerLinux.txt" + else + pid=`top -bn 1 -i -c |awk '{ if (NR > 6) print }' |awk '{ if ($9 > 99) print $1}' |head -n1` + if [[ -n $pid ]]; then + echo "[$datetime] 开始结束服务器: $curdoc LogicServer (pid=$pid)" + kill -15 $pid + NUM=2 + while true; do + datetime=`date "+%Y-%m-%d.%H:%M:%S"` + proc=`ps aux |grep $path|grep logicserver|grep -v grep|grep "\<$curdoc\>"|grep -v "/bin/bash"|wc -l` + if [ $proc == 0 ]; then + break + fi + if [ $NUM -lt 0 ]; then + echo "[$datetime] 游戏服务 $curdoc LogicServer 强制结束" + kill -9 $pid + $path/LogicServer/logicserver$dm $path/LogicServer/LogicServerLinux.txt > /dev/null & + echo "[$datetime] 游戏服务 $curdoc LogicServer 启动完毕" + echo "--------------------------------------------------" + break + fi + echo "[$datetime] 游戏服务 $curdoc LogicServer 结束中..." + sleep 1 + let NUM-- + done + fi + fi +done \ No newline at end of file diff --git a/LogicServer/run.sh b/LogicServer/run.sh index dfe835f..684a16e 100755 --- a/LogicServer/run.sh +++ b/LogicServer/run.sh @@ -2,8 +2,10 @@ ./stop.sh +echo "["$datetime"] 正在启动 Logic 服务器 [logicserver$dm]..." + if [ "$1" == "Debug" ]; then ./logicserver_d LogicServerLinux.txt else ./logicserver_r LogicServerLinux.txt -fi +fi \ No newline at end of file diff --git a/daemon.sh b/daemon.sh index d159969..4053c0d 100755 --- a/daemon.sh +++ b/daemon.sh @@ -30,39 +30,6 @@ while true; do echo "[$datetime] $path/Gateway/gateway$dm $path/Gateway/GateWay.txt" fi - # check LogicServer - - ret=`ps x |grep $path/LogicServer/logicserver$dm|grep -v grep|grep -v "/bin/bash"|wc -l` - if [ $ret == 0 ]; then - $path/LogicServer/logicserver$dm $path/LogicServer/LogicServerLinux.txt > /dev/null & - echo "[$datetime] $path/LogicServer/logicserver$dm $path/LogicServer/LogicServerLinux.txt" - else - pid=`top -bn 1 -i -c |awk '{ if (NR > 6) print }' |awk '{ if ($9 > 99) print $1}' |head -n1` - if [[ -n $pid ]]; then - echo "[$datetime] 开始结束服务器: $curdoc LogicServer (pid=$pid)" - kill -15 $pid - NUM=2 - while true; do - datetime=`date "+%Y-%m-%d.%H:%M:%S"` - proc=`ps aux |grep $path|grep logicserver|grep -v grep|grep "\<$curdoc\>"|grep -v "/bin/bash"|wc -l` - if [ $proc == 0 ]; then - break - fi - if [ $NUM -lt 0 ]; then - echo "[$datetime] 游戏服务 $curdoc LogicServer 强制结束" - kill -9 $pid - $path/LogicServer/logicserver$dm $path/LogicServer/LogicServerLinux.txt > /dev/null & - echo "[$datetime] 游戏服务 $curdoc LogicServer 启动完毕" - echo "--------------------------------------------------" - break - fi - echo "[$datetime] 游戏服务 $curdoc LogicServer 结束中..." - sleep 1 - let NUM-- - done - fi - fi - #ret=`ps x |grep $path/LogicServer/robot$dm|grep -v grep|grep -v "/bin/bash"|wc -l` #if [ $ret == 0 ]; then #$path/LogicServer && ./robot$dm diff --git a/run.sh b/run.sh index e6dec42..f2a9ab4 100755 --- a/run.sh +++ b/run.sh @@ -16,9 +16,9 @@ echo "["$datetime"] 正在启动 DB 服务器 [dbserver$dm]..." $path/DBServer/dbserver$dm $path/DBServer/DBServerLinux.txt > /dev/null & echo "执行命令:$path/DBServer/dbserver$dm $path/DBServer/DBServerLinux.txt" -echo "["$datetime"] 正在启动 Logic 服务器 [logicserver$dm]..." -$path/LogicServer/logicserver$dm $path/LogicServer/LogicServerLinux.txt > /dev/null & -echo "执行命令:$path/LogicServer/logicserver$dm $path/LogicServer/LogicServerLinux.txt" +# echo "["$datetime"] 正在启动 Logic 服务器 [logicserver$dm]..." +# $path/LogicServer/logicserver$dm $path/LogicServer/LogicServerLinux.txt > /dev/null & +# echo "执行命令:$path/LogicServer/logicserver$dm $path/LogicServer/LogicServerLinux.txt" echo "["$datetime"] 正在启动 Gateway 服务器 [gateway$dm]..." $path/Gateway/gateway$dm $path/Gateway/GateWay.txt > /dev/null &