From cb86244ff852a5f30be5f4f7b7ba97167cab6ebe Mon Sep 17 00:00:00 2001 From: aixianling Date: Thu, 20 Feb 2025 12:11:22 +0800 Subject: [PATCH] =?UTF-8?q?feat(server):=20=E6=B7=BB=E5=8A=A0=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=BA=93=E5=92=8C=E7=BD=91=E5=85=B3=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E8=84=9A=E6=9C=AC=E5=B9=B6=E6=9B=B4=E6=96=B0=20Docker=20?= =?UTF-8?q?=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 DBServer 和 Gateway 的启动和停止脚本 - 更新 docker-compose.yml,添加 db 和 gate 服务 - 优化服务启动顺序,确保 db 服务先于 logic 和 gate 服务启动 --- DBServer/start.sh | 11 +++++++++++ DBServer/stop.sh | 32 ++++++++++++++++++++++++++++++++ Gateway/start.sh | 11 +++++++++++ Gateway/stop.sh | 32 ++++++++++++++++++++++++++++++++ docker-compose.yml | 29 ++++++++++++++++++++++------- 5 files changed, 108 insertions(+), 7 deletions(-) create mode 100644 DBServer/start.sh create mode 100644 DBServer/stop.sh create mode 100644 Gateway/start.sh create mode 100644 Gateway/stop.sh diff --git a/DBServer/start.sh b/DBServer/start.sh new file mode 100644 index 0000000..059d058 --- /dev/null +++ b/DBServer/start.sh @@ -0,0 +1,11 @@ +#!/bin/bash +cd $(cd "$(dirname "$0")" && pwd) +path=`pwd` +./stop.sh + +echo "======================【启动】========================" +datetime=`date "+%Y-%m-%d.%H:%M:%S"` + +echo "["$datetime"] 正在启动 DB 服务器 [dbserver_r]..." + +$path/dbserver_r $path/DBServerLinux.txt \ No newline at end of file diff --git a/DBServer/stop.sh b/DBServer/stop.sh new file mode 100644 index 0000000..f8ebf6e --- /dev/null +++ b/DBServer/stop.sh @@ -0,0 +1,32 @@ +#!/bin/bash +path=`pwd` +srv = "dbserver" + +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 diff --git a/Gateway/start.sh b/Gateway/start.sh new file mode 100644 index 0000000..3306d72 --- /dev/null +++ b/Gateway/start.sh @@ -0,0 +1,11 @@ +#!/bin/bash +cd $(cd "$(dirname "$0")" && pwd) +path=`pwd` +./stop.sh + +echo "======================【启动】========================" +datetime=`date "+%Y-%m-%d.%H:%M:%S"` + +echo "["$datetime"] 正在启动 Logic 服务器 [gateway_r]..." + +$path/gateway_r $path/GateWay.txt \ No newline at end of file diff --git a/Gateway/stop.sh b/Gateway/stop.sh new file mode 100644 index 0000000..88d9455 --- /dev/null +++ b/Gateway/stop.sh @@ -0,0 +1,32 @@ +#!/bin/bash +path=`pwd` +srv = "gateway" + +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 diff --git a/docker-compose.yml b/docker-compose.yml index a87ba61..8e89318 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,24 +1,24 @@ version: '3.8' services: - server: + db: image: chuanqi-os:latest - container_name: chuanqi-server-dev - cpus: '2' + container_name: chuanqi-server-db stdin_open: true volumes: - - .:/data/server/s1 + - ./DBServer:/data/server/s1/DBServer - ./wch:/etc/yum/wch - entrypoint: "/data/server/s1/run.sh" + entrypoint: "/data/server/s1/DBServer/start.sh" network_mode: "host" restart: unless-stopped environment: TZ: Asia/Shanghai + logic: image: chuanqi-os:latest container_name: chuanqi-server-logic - cpus: '4' - cpuset: '13,14,15,16' + depends_on: + - db # 等待db服务启动 stdin_open: true volumes: - ./LogicServer:/data/server/s1/LogicServer @@ -28,3 +28,18 @@ services: restart: unless-stopped environment: TZ: Asia/Shanghai + + gate: + image: chuanqi-os:latest + container_name: chuanqi-server-gate + depends_on: + - logic # 等待logic服务启动 + stdin_open: true + volumes: + - ./GateServer:/data/server/s1/GateServer + - ./wch:/etc/yum/wch + entrypoint: "/data/server/s1/GateServer/start.sh" + network_mode: "host" + restart: unless-stopped + environment: + TZ: Asia/Shanghai \ No newline at end of file