feat(server): 添加数据库和网关服务脚本并更新 Docker 配置

- 新增 DBServer 和 Gateway 的启动和停止脚本
- 更新 docker-compose.yml,添加 db 和 gate 服务
- 优化服务启动顺序,确保 db 服务先于 logic 和 gate 服务启动
This commit is contained in:
aixianling
2025-02-20 12:11:22 +08:00
parent 56013fb5fa
commit cb86244ff8
5 changed files with 108 additions and 7 deletions

11
DBServer/start.sh Normal file
View File

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

32
DBServer/stop.sh Normal file
View File

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

11
Gateway/start.sh Normal file
View File

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

32
Gateway/stop.sh Normal file
View File

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

View File

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