Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
build/*.sh
build/*.bat
scripts
docker
kubernetes
deployment
cmake-build-debug
test
examples
Expand Down
90 changes: 56 additions & 34 deletions build/README.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,61 @@
# Binary
# Runtime files

Build artifacts are written to `<cmake-build-directory>/bin`. Use separate
build directories for Release, Debug and sanitizer builds so their archives,
plugins and executables cannot overwrite each other:
[简体中文](README_CN.md)

Build artifacts belong to `<cmake-build-directory>/bin`. Keep Release, Debug and
sanitizer builds in separate directories. Stage an application's executable and
plugins from the same build into a runtime directory containing `bin/`, `conf/`
and, when required, `resource/`. This source directory contains example
configuration, resources and tools; generated binaries are not checked in.

## Run one application

The shell and Windows helpers share one interface:

```text
run.sh <Release|Debug> <name> <busid> [runtime-directory]
run.bat <Release|Debug> <name> <busid> [runtime-directory]
```

The default runtime directory is the script's directory. An explicit runtime path
is relative to the caller's working directory. The helper selects `bin/app`
(`app.exe` on Windows) for Release or `bin/app_d` (`app_d.exe`) for Debug, reads
`conf/<name>.app.conf` and `conf/log.conf`, and runs in the foreground. The name
also becomes the application's `--name` value. Use the executable directly for
TOML manifests, a different process name or other launcher flags.

After preparing the [Sample1 runtime](../docs/get-started/quick-start.md), run from
the repository root:

```sh
cmake -S . -B out/release -DCMAKE_BUILD_TYPE=Release
cmake --build out/release --parallel 2
sh build/run.sh Release sample1 1.0.1.1 run/sample1
```

This build produces `out/release/bin/app` (`app.exe` on Windows) and the enabled
plugins in the same directory. `cmake -S . -B build` retains the `build/bin`
location. The Docker build copies its artifacts from `cmake-build/bin`.

When staging a server, copy the chosen build's artifacts into the runtime
directory's `bin/` alongside its configuration and resources. The scripts below
use this runtime layout; they do not select a CMake build directory.

This folder is the runtime folder, include

- bin
- binlog
- bus_conf
- plugin_conf
- resource
- tools

## Batch/shell

| name | descriptor |
| -------- | ------------------------------------- |
| rund.bat | run debug version in Windows |
| run.bat | run release version in Windows |
| kill.bat | kill debug & release version in Linux |
| | |
| run.sh | run release version in Linux |
| rund.sh | run debug version in Linux |
| kill.sh | kill debug & release version in Linux |
On Windows, use `build\run.bat Release sample1 1.0.1.1 run\sample1`.
Check the application's initialization log before using it; the helper's path
checks do not validate plugins, business configuration or readiness.

## Stop one application

Prefer Ctrl+C on macOS/Linux or `exit` in the Windows application console.
For a process whose PID has been confirmed, `kill.sh <pid>` requests `SIGTERM`;
`kill.bat <pid>` forcibly terminates that PID. Both helpers reject other executable
names and require exactly one explicit PID. Recheck the PID's executable and
command line immediately before use; a PID can be reused after a process exits.
There is no process-name wildcard or machine-wide stop command.

## Migrate old helper commands

- Replace `rund.sh` / `rund.bat` with `run.sh Debug ...` / `run.bat Debug ...`.
- Replace `sample1.sh`, `mysql_sample.sh` and `sample5http_test.sh` with
`run.sh Debug <name> <busid>`, using `sample1`, `mysql_sample` or `sample5`.
- The old no-argument five-service launch sequence used missing `plugin_conf/`
paths and inconsistent Release/Debug Bus IDs. Supply each application's name
and Bus ID explicitly, and arrange service startup separately for the target
environment. The helper no longer daemonizes applications.
- Replace `vc_clear.bat` with `cmake --build <cmake-build-directory> --target clean`
to clean a selected build directory.
- Container recipes and cluster examples now live under [deployment/](../deployment/README.md).

The byte-preserved historical articles under `docs/site/legacy-source/` still show
their original `bin/rund.*` commands. Use the current commands above instead.
53 changes: 53 additions & 0 deletions build/README_CN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# 运行文件

[English](README.md)

构建产物保存在 `<cmake-build-directory>/bin`。Release、Debug 和 sanitizer 构建使用
独立目录。将同一次构建的程序和插件复制到运行目录的 `bin/`,并准备 `conf/`;使用
业务资源的应用还需要 `resource/`。本目录保存示例配置、资源与工具,不追踪生成的二进制文件。

## 启动一个应用

Shell 和 Windows 脚本使用相同参数:

```text
run.sh <Release|Debug> <name> <busid> [runtime-directory]
run.bat <Release|Debug> <name> <busid> [runtime-directory]
```

运行目录默认为脚本所在目录。显式传入的相对路径以调用者的工作目录为基准。
Release 使用 `bin/app`(Windows 为 `app.exe`),Debug 使用 `bin/app_d`
(Windows 为 `app_d.exe`)。脚本读取 `conf/<name>.app.conf` 和 `conf/log.conf`,
在前台运行应用;`name` 同时作为 `--name` 的值。使用 TOML 配置、不同的进程名称或
其他启动参数时,直接调用程序。

按[Sample1 快速开始](../docs/get-started/quick-start_CN.md)准备运行目录后,在仓库根目录执行:

```sh
sh build/run.sh Release sample1 1.0.1.1 run/sample1
```

Windows 使用 `build\run.bat Release sample1 1.0.1.1 run\sample1`。
使用应用前,检查初始化日志。脚本的路径检查不验证插件、业务配置或服务就绪状态。

## 停止一个应用

macOS/Linux 优先使用 Ctrl+C,Windows 优先在应用控制台输入 `exit`。
确认目标进程的 PID 后,使用 `kill.sh <pid>` 请求 `SIGTERM`;`kill.bat <pid>` 会强制终止
该 PID。两个脚本都只接受一个显式 PID,并拒绝其他可执行文件名。执行前重新确认 PID 的
可执行文件与命令行;进程退出后,PID 可能被复用。脚本不按名称通配批量停止进程。

## 迁移旧命令

- 将 `rund.sh` / `rund.bat` 改为 `run.sh Debug ...` / `run.bat Debug ...`。
- 将 `sample1.sh`、`mysql_sample.sh` 和 `sample5http_test.sh` 改为
`run.sh Debug <name> <busid>`;名称分别为 `sample1`、`mysql_sample`、`sample5`。
- 旧版无参数五服务启动顺序引用了不存在的 `plugin_conf/`,Release 与 Debug 的总线 ID
也不一致。现在需要显式传入每个应用的名称与总线 ID,并按目标环境安排启动顺序。
新脚本不再将应用转为守护进程。
- 使用 `cmake --build <cmake-build-directory> --target clean` 清理选定构建目录,
替代 `vc_clear.bat`。
- 容器构建文件和集群示例已移至 [deployment/](../deployment/README_CN.md)。

`docs/site/legacy-source/` 按原始字节保留历史文章,其中的 `bin/rund.*` 命令不再适用,
请使用上面的当前命令。
23 changes: 19 additions & 4 deletions build/kill.bat
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
cd /d %~dp0

@echo off

taskkill /f /im app*
setlocal
if "%~1"=="" goto usage
if not "%~2"=="" goto usage
for /f "delims=0123456789" %%p in ("%~1") do goto usage
set "pid=%~1"
if "%pid:~0,1%"=="0" goto usage
if "%~1"=="1" goto usage
for /f "tokens=1 delims=," %%p in ('tasklist /fi "PID eq %~1" /fo csv /nh') do (
if /i "%%~p"=="app.exe" goto stop
if /i "%%~p"=="app_d.exe" goto stop
)
echo PID %~1 is not an app.exe or app_d.exe process; refusing to stop it. 1>&2
exit /b 1
:stop
taskkill /f /pid %~1
exit /b %errorlevel%
:usage
echo Usage: %~nx0 ^<application-pid^> 1>&2
exit /b 2
17 changes: 15 additions & 2 deletions build/kill.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
kill -9 $(pidof *_server)
#!/bin/sh
set -eu

ps aux | grep *_server
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <application-pid>" >&2
exit 2
fi
case "$1" in
''|*[!0-9]*|0|1|0*) echo "Supply one application PID greater than 1" >&2; exit 2 ;;
esac
command_name=$(ps -p "$1" -o comm=) || exit 1
command_name=${command_name##*/}
case "$command_name" in
app|app_d) kill -TERM "$1" ;;
*) echo "PID $1 is not an app or app_d process; refusing to stop it" >&2; exit 1 ;;
esac
13 changes: 0 additions & 13 deletions build/mysql_sample.sh

This file was deleted.

58 changes: 25 additions & 33 deletions build/run.bat
Original file line number Diff line number Diff line change
@@ -1,34 +1,26 @@
cd /d %~dp0

@echo off

REM the default zone is 1001

set CHANNEL_ID=1
set ZONE_ID=1

cd Release

echo Starting master...
start "master" bin/app.exe -x --busid=1.0.1.1 --name=master_server --app_conf=plugin_conf/master.app.conf
choice /t 5 /d y /n >nul

echo Starting world...
start "world" bin/app.exe -x --busid=1.1.30.1 --name=world_server --app_conf=plugin_conf/world.app.conf
choice /t 5 /d y /n >nul

echo Starting login...
start "login" bin/app.exe -x --busid=1.1.31.1 --name=login_server --app_conf=plugin_conf/login.app.conf
choice /t 5 /d y /n >nul

echo Starting proxy...
start "proxy" bin/app.exe -x --busid=1.1.32.1 --name=proxy_server --app_conf=plugin_conf/proxy.app.conf
choice /t 5 /d y /n >nul

echo Starting game...
start "game" bin/app.exe -x --busid=1.1.33.1 --name=game_server --app_conf=plugin_conf/game.app.conf
choice /t 5 /d y /n >nul

echo All processes are launching...

cd
setlocal
if "%~3"=="" goto usage
if not "%~5"=="" goto usage
set "binary="
if "%~1"=="Release" set "binary=bin\app.exe"
if "%~1"=="Debug" set "binary=bin\app_d.exe"
if not defined binary goto usage
echo(%~2| findstr /r /x "[a-zA-Z0-9_-][a-zA-Z0-9_-]*" >nul || goto usage
set "runtime=%~dp0"
if not "%~4"=="" set "runtime=%~4"
pushd "%runtime%" || exit /b 1
if not exist "%binary%" goto missing
if not exist "conf\%~2.app.conf" goto missing
if not exist "conf\log.conf" goto missing
"%binary%" "--busid=%~3" "--name=%~2" "--app_conf=conf/%~2.app.conf" --log_conf=conf/log.conf
set "result=%errorlevel%"
popd
exit /b %result%
:missing
echo Missing executable or configuration in "%CD%". 1>&2
popd
exit /b 1
:usage
echo Usage: %~nx0 ^<Release^|Debug^> ^<name^> ^<busid^> [runtime-directory] 1>&2
exit /b 2
55 changes: 26 additions & 29 deletions build/run.sh
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
cd bin

export LC_ALL="C"

#The default zone is 1001

CHANNEL_ID=1
ZONE_ID=1

echo Starting master...
./bin/app -d --busid=1.0.1.1 --name=master_server --app_conf=plugin_conf/master.app.conf

echo Starting world...
./bin/app -d --busid=1.1.30.1 --name=world_server --app_conf=plugin_conf/world.app.conf

echo Starting login...
./bin/app -d --busid=1.1.31.1 --name=login_server --app_conf=plugin_conf/login.app.conf

echo Starting proxy...
./bin/app -d --busid=1.1.32.1 --name=proxy_server --app_conf=plugin_conf/proxy.app.conf

echo Starting game...
./bin/app -d --busid=1.1.33.1 --name=game_server --app_conf=plugin_conf/game.app.conf

echo All processes are launching...

ps aux | grep app

cd ../
#!/bin/sh
set -eu

if [ "$#" -lt 3 ] || [ "$#" -gt 4 ]; then
echo "Usage: $0 <Release|Debug> <name> <busid> [runtime-directory]" >&2
exit 2
fi
case "$1" in
Release) binary=./bin/app ;;
Debug) binary=./bin/app_d ;;
*) echo "Configuration must be Release or Debug" >&2; exit 2 ;;
esac
case "$2" in
''|*[!a-zA-Z0-9_-]*) echo "Name must contain only letters, digits, _ or -" >&2; exit 2 ;;
esac
if [ "$#" -eq 4 ]; then
cd -- "$4"
else
CDPATH='' cd -- "$(dirname -- "$0")"
fi
[ -x "$binary" ] || { echo "Missing executable: $binary" >&2; exit 1; }
for config in "conf/$2.app.conf" conf/log.conf; do
[ -f "$config" ] || { echo "Missing configuration: $config" >&2; exit 1; }
done
export LC_ALL=C
exec "$binary" "--busid=$3" "--name=$2" "--app_conf=conf/$2.app.conf" --log_conf=conf/log.conf
32 changes: 0 additions & 32 deletions build/rund.bat

This file was deleted.

Loading
Loading