refactor(LogicServer): 在 run.sh 中添加停止服务器的步骤
- 在脚本开始时添加了 ./stop.sh 命令 - 这样可以确保在启动服务器之前,任何正在运行的实例都会被停止
This commit is contained in:
		| @@ -1,4 +1,7 @@ | |||||||
| #! /bin/bash | #! /bin/bash | ||||||
|  |  | ||||||
|  | ./stop.sh | ||||||
|  |  | ||||||
| if [ "$1" == "Debug" ]; then | if [ "$1" == "Debug" ]; then | ||||||
| 	./logicserver_d LogicServerLinux.txt | 	./logicserver_d LogicServerLinux.txt | ||||||
| else | else | ||||||
|   | |||||||
							
								
								
									
										32
									
								
								LogicServer/stop.sh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								LogicServer/stop.sh
									
									
									
									
									
										Normal file
									
								
							| @@ -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 | ||||||
		Reference in New Issue
	
	Block a user