refactor(server): 重构 LogicServer 监控和启动脚本

- 新增 LogicServer/daemon.sh 脚本,专门用于监控和重启 LogicServer
- 修改 LogicServer/run.sh,添加启动日志输出
- 从 daemon.sh 中移除 LogicServer 相关的监控逻辑
- 在 run.sh 中注释掉 LogicServer 启动代码,统一启动逻辑
This commit is contained in:
aixianling
2025-01-10 16:27:11 +08:00
parent d91c3d8d8a
commit a9808773da
4 changed files with 56 additions and 37 deletions

50
LogicServer/daemon.sh Normal file
View File

@@ -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

View File

@@ -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

View File

@@ -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

6
run.sh
View File

@@ -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 &