Files
chuanqi-server-instance/LogicServer/stop.sh
aixianling 22bc4bcbcb refactor(LogicServer): 在 run.sh 中添加停止服务器的步骤
- 在脚本开始时添加了 ./stop.sh 命令
- 这样可以确保在启动服务器之前,任何正在运行的实例都会被停止
2024-12-17 11:38:53 +08:00

32 lines
877 B
Bash

#!/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