From 22bc4bcbcbf88042183011f534ed842821b466ed Mon Sep 17 00:00:00 2001 From: aixianling Date: Tue, 17 Dec 2024 11:38:53 +0800 Subject: [PATCH] =?UTF-8?q?refactor(LogicServer):=20=E5=9C=A8=20run.sh=20?= =?UTF-8?q?=E4=B8=AD=E6=B7=BB=E5=8A=A0=E5=81=9C=E6=AD=A2=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E5=99=A8=E7=9A=84=E6=AD=A5=E9=AA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在脚本开始时添加了 ./stop.sh 命令 - 这样可以确保在启动服务器之前,任何正在运行的实例都会被停止 --- LogicServer/run.sh | 3 +++ LogicServer/stop.sh | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 LogicServer/stop.sh diff --git a/LogicServer/run.sh b/LogicServer/run.sh index 568eebe..dfe835f 100755 --- a/LogicServer/run.sh +++ b/LogicServer/run.sh @@ -1,4 +1,7 @@ #! /bin/bash + +./stop.sh + if [ "$1" == "Debug" ]; then ./logicserver_d LogicServerLinux.txt else diff --git a/LogicServer/stop.sh b/LogicServer/stop.sh new file mode 100644 index 0000000..86324f0 --- /dev/null +++ b/LogicServer/stop.sh @@ -0,0 +1,32 @@ +#!/bin/bash +path=`pwd` +srv = "logicserver" + +datetime=`date "+%Y-%m-%d.%H:%M:%S"` +curdoc=$(pwd|awk -F \/ '{print $NF}') + + +pid=`ps aux |grep $path|grep $srv|grep -v grep|grep "\<$curdoc\>"|grep -v "/bin/bash"|awk '{print $2}'` +if [[ -n $pid ]]; then + echo "开始结束服务器: $srv (pid=$pid)" + kill -15 $pid + NUM=10 + while true; do + datetime=`date "+%Y-%m-%d.%H:%M:%S"` + proc=`ps aux |grep $path|grep $srv|grep -v grep|grep "\<$curdoc\>"|grep -v "/bin/bash"|wc -l` + if [ $proc == 0 ]; + then + break + fi + if [ $NUM -lt 0 ]; + then + kill -9 $pid + echo $datetime" 游戏服务 "$path" "$srv" 强制结束" + break + fi + echo $datetime" 游戏服务 "$path" "$srv" 结束中..." + sleep 1 + let NUM-- + done + echo "已结束服务器: $srv" +fi \ No newline at end of file