Skip to content

Commit 82db8da

Browse files
committed
HACK: Single file with multiple instances
1 parent 8ee12c5 commit 82db8da

File tree

4 files changed

+148
-34
lines changed

4 files changed

+148
-34
lines changed

dockerfile.native

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
FROM debian
22

33
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
4+
COPY entrypoint_root.sh /usr/local/bin/entrypoint_root.sh
45

56
RUN apt-get update && apt-get install -y lib32gcc-s1 curl && rm -rf /var/lib/apt/lists/* && apt-get clean && \
6-
chmod +x /usr/local/bin/entrypoint.sh && useradd -m 5k
7+
chmod +x /usr/local/bin/entrypoint.sh /usr/local/bin/entrypoint_root.sh && useradd -m 5k
78

89
ENV APPID=884110
910
ENV STEAMPATH="/home/5k/Steam"
@@ -17,6 +18,7 @@ RUN mkdir -p "$STEAMPATH" "$SRVPATH" && cd "$STEAMPATH" && \
1718
ENV STARTENV=""
1819
ENV STARTCMD="./LinuxServer/PandemicServer.sh"
1920
ENV ENTRYPOINT_ARGS="native no no"
21+
ENV ENTRYPOINT_ROOT_ARGS="yes"
2022

2123
USER root
22-
CMD chown -R 5k:5k "$SRVPATH" && su 5k -c "entrypoint.sh $ENTRYPOINT_ARGS"
24+
CMD ["sh", "-c", "entrypoint_root.sh $ENTRYPOINT_ROOT_ARGS"]

dockerfile.wine

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
FROM debian
22

33
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
4+
COPY entrypoint_root.sh /usr/local/bin/entrypoint_root.sh
45

56
RUN apt-get update && apt-get install -y lib32gcc-s1 curl && rm -rf /var/lib/apt/lists/* && apt-get clean && \
6-
chmod +x /usr/local/bin/entrypoint.sh && useradd -m 5k
7+
chmod +x /usr/local/bin/entrypoint.sh /usr/local/bin/entrypoint_root.sh && useradd -m 5k
78

89
ENV APPID=884110
910
ENV STEAMPATH="/home/5k/Steam"
@@ -25,8 +26,9 @@ RUN dpkg --add-architecture i386 && \
2526
ENV STARTENV="WINEDLLOVERRIDES=dwmapi=native,builtin"
2627
ENV STARTCMD="wine ./WindowsServer/PandemicServer.exe"
2728
ENV ENTRYPOINT_ARGS="wine no no"
29+
ENV ENTRYPOINT_ROOT_ARGS="yes"
2830

2931
ENV UE4SS_LOG_SRC_PATH="${SRVPATH}/WindowsServer/Pandemic/Binaries/Win64/ue4ss"
3032
ENV UE4SS_LOG_TO_PATH="${UE4SS_LOG_SRC_PATH}/logs"
3133

32-
CMD chown -R 5k:5k "$SRVPATH" && su 5k -c "entrypoint.sh $ENTRYPOINT_ARGS"
34+
CMD ["sh", "-c", "entrypoint_root.sh $ENTRYPOINT_ROOT_ARGS"]

entrypoint_root.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/sh
2+
set -eu
3+
4+
if [ -z "${1-}" ]; then
5+
echo "entrypoint_root.sh: require arguments \$1."
6+
exit 1
7+
fi
8+
9+
if [ "$1" != "yes" ] && [ "$1" != "force" ] && [ "$1" != "no" ]; then
10+
echo "entrypoint_root.sh: invalid arguments \$1, use \"yes\" or \"no\"."
11+
exit 1
12+
fi
13+
14+
if [ "$1" = "yes" ]; then
15+
echo "entrypoint_root.sh: chown $SRVPATH!"
16+
chown -R 5k:5k "$SRVPATH"
17+
fi
18+
19+
if [ "$1" = "force" ]; then
20+
echo "entrypoint_root.sh: forced chown $SRVPATH!"
21+
chown -R 5k:5k "$SRVPATH" 2>/dev/null || true
22+
fi
23+
24+
if [ "$1" = "no" ]; then
25+
echo "entrypoint_root.sh: skipping chown!"
26+
fi
27+
28+
su 5k -c "entrypoint.sh $ENTRYPOINT_ARGS"

readme.md

Lines changed: 112 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ We currently have two different implementations, you need to choose one accordin
1212

1313
[For people who not a newbie to docker and linux](#advanced)
1414

15+
[HACK: Single file with multiple instances](#hack-single-file-with-multiple-instances)
16+
1517
[让我们说中文](#使用方法)
1618

1719
## Quick Start
@@ -85,24 +87,41 @@ Add `-d` if you want it running on background
8587

8688
## Advanced
8789

88-
You have to create a volume for stoagre your server files, mount it on `$SRVPATH` (see [ENVs](#envs))
90+
You have to create a volume for storage your server files, mount it on `$SRVPATH` (see [ENVs](#envs))
8991

9092
### ENVs
9193

92-
| ENVs | Default Value | Description |
93-
|-------------------- |--------------------------------------------------------------------------------------------------- |--------------------------------------------------------------------------------------- |
94-
| APPID | `884110` | Game server's steam appid |
95-
| STEAMPATH | `"/home/5k/Steam"` | Steamcmd path |
96-
| SRVPATH | `"${STEAMPATH}/steamapps/common/SCP Pandemic Dedicated Server"` | Game server path |
97-
| ARGS | `""` | The params you want sent to the server |
98-
| STARTENV | Native: `""`<br/>Wine: `"WINEDLLOVERRIDES=dwmapi=native,builtin"` | Start environments, **modify `WINEDLLOVERRIDES` may result in `UE4SS` not loading** |
99-
| STARTCMD | Native: `"./LinuxServer/PandemicServer.sh"`<br/>Wine: `"wine ./WindowsServer/PandemicServer.exe"` | Start command, used to start the server, a modify example: `"wine ./StartServer.bat"` |
100-
| ENTRYPOINT_ARGS | Native: `"native no no"`<br/>Wine: `"wine no no"` | Params for entrypoint.sh, see [Entrypoint Params](#entrypoint-params) |
101-
| UE4SS_LOG_SRC_PATH | Native: undefined<br/>Wine: `"${SRVPATH}/WindowsServer/Pandemic/Binaries/Win64/ue4ss"` | Used by [UE4SS Log Clipper](#ue4ss-log-clipper) |
102-
| UE4SS_LOG_TO_PATH | Native: undefined<br/>Wine: `"${UE4SS_LOG_SRC_PATH}/logs"` | Used by [UE4SS Log Clipper](#ue4ss-log-clipper) |
94+
| ENVs | Default Value | Description |
95+
|---------------------- |--------------------------------------------------------------------------------------------------- |--------------------------------------------------------------------------------------- |
96+
| APPID | `884110` | Game server's steam appid |
97+
| STEAMPATH | `"/home/5k/Steam"` | Steamcmd path |
98+
| SRVPATH | `"${STEAMPATH}/steamapps/common/SCP Pandemic Dedicated Server"` | Game server path |
99+
| ARGS | `""` | The params you want sent to the server |
100+
| STARTENV | Native: `""`<br/>Wine: `"WINEDLLOVERRIDES=dwmapi=native,builtin"` | Start environments, **modify `WINEDLLOVERRIDES` may result in `UE4SS` not loading** |
101+
| STARTCMD | Native: `"./LinuxServer/PandemicServer.sh"`<br/>Wine: `"wine ./WindowsServer/PandemicServer.exe"` | Start command, used to start the server, a modify example: `"wine ./StartServer.bat"` |
102+
| ENTRYPOINT_ARGS | Native: `"native no no"`<br/>Wine: `"wine no no"` | Params for entrypoint.sh, see [Entrypoint Params](#entrypoint-params) |
103+
| ENTRYPOINT_ROOT_ARGS | `"yes"` | Params for entrypoint_root.sh, see [Entrypoint Params](#entrypoint-params) |
104+
| UE4SS_LOG_SRC_PATH | Native: undefined<br/>Wine: `"${SRVPATH}/WindowsServer/Pandemic/Binaries/Win64/ue4ss"` | Used by [UE4SS Log Clipper](#ue4ss-log-clipper) |
105+
| UE4SS_LOG_TO_PATH | Native: undefined<br/>Wine: `"${UE4SS_LOG_SRC_PATH}/logs"` | Used by [UE4SS Log Clipper](#ue4ss-log-clipper) |
103106

104107
### Entrypoint Params
105108

109+
#### entrypoint_root.sh
110+
111+
| Params | Allowed value | Description |
112+
|-------- |---------------------- |----------------------------------------------------------- |
113+
| $1 | `yes`, `force`, `no` | Used to should chown `$SRVPATH`, `force` to ignore errors |
114+
115+
Example:
116+
117+
```sh
118+
-e ENTRYPOINT_ROOT_ARGS="yes"
119+
```
120+
121+
Will chown `$SRVPATH`
122+
123+
#### entrypoint.sh
124+
106125
| Params | Allowed value | Description |
107126
|-------- |-------------------------- |----------------------------------------------------------------------------- |
108127
| $1 | `native`, `wine`, `skip` | Used to set steamcmd's platform type, `skip` to skip the steamcmd |
@@ -130,24 +149,46 @@ Use windows platform, start UE4SS Log Clipper, Reset Wine, start Log Checker
130149

131150
Skip steamcmd, not start UE4SS Log Clipper, no Reset Wine, not start Log Checker
132151

133-
### UE4SS Log Clipper
152+
#### UE4SS Log Clipper
134153

135154
A simple script will clip `$UE4SS_LOG_SRC_PATH/UE4SS.log` to `$UE4SS_LOG_TO_PATH` everytime before server starting
136155

137156
The name format of the log: `$(date +"%Y%m%dT%H%M%S%z").log`
138157

139-
### Reset Wine
158+
#### Reset Wine
140159

141160
A simple script will `rm -rf /home/5k/.wine` everytime before server starting
142161

143-
### Log Checker
162+
#### Log Checker
144163

145164
A simple script will keep watching the stdout and stderr, and if it find any matched strings, it will kill the server
146165

147166
Default matched strings: `FOnlineAsyncTaskSteamCreateServer bWasSuccessful: 0`, `SteamSockets API: Error`
148167

149168
You can modify it in `entrypoint.sh` > `$MATCH_TARGET`
150169

170+
## HACK: Single file with multiple instances
171+
172+
> You may have to manually change the permission if you are import files from outside of the container
173+
174+
> By changing `$ENTRYPOINT_ROOT_ARGS` > `$1` to `force` may help for fix permission problems
175+
176+
> You must skip steamcmd, otherwise will got error because the server files are inside readonly fs
177+
178+
Create a volume as main server files storage, mount it **readonly** on `$SRVPATH` for every container (see [ENVs](#envs))
179+
180+
Create a volume for storage `Saved` folder, mount it **writeable** on `Saved` folder (each volume for each container)
181+
182+
**Wine**:`${SRVPATH}/LinuxServer/Pandemic/Saved`
183+
184+
**Native**:`${SRVPATH}/WindowsServer/Pandemic/Saved`
185+
186+
### For UE4SS
187+
188+
Create a volume for storage `ue4ss` folder, mount it **writeable** on `ue4ss` folder (each volume for each container)
189+
190+
> Or you can just mount `./ue4ss/Mods` folder
191+
151192
----
152193

153194
### 使用方法
@@ -162,6 +203,8 @@ You can modify it in `entrypoint.sh` > `$MATCH_TARGET`
162203

163204
[对于那些对Docker和Linux不是新手的人](#高级)
164205

206+
[HACK:使用单文件运行多实例](#hack使用单文件运行多实例)
207+
165208

166209
## 快速开始
167210

@@ -238,25 +281,42 @@ docker run --name scp5kserver -p 7777:7777/tcp -p 7777:7777/udp -p 27015:27015/t
238281

239282
### ENVs
240283

241-
| ENVs | 默认值 | 描述 |
242-
|-------------------- |--------------------------------------------------------------------------------------------------- |------------------------------------------------------------------ |
243-
| APPID | `884110` | 游戏服务器的steam appid |
244-
| STEAMPATH | `"/home/5k/Steam"` | steamcmd的路径 |
245-
| SRVPATH | `"${STEAMPATH}/steamapps/common/SCP Pandemic Dedicated Server"` | 游戏服务器的路径 |
246-
| ARGS | `""` | 你想发给服务器的参数 |
247-
| STARTENV | Native: `""`<br/>Wine: `"WINEDLLOVERRIDES=dwmapi=native,builtin"` | 环境变量,**修改`WINEDLLOVERRIDES`可能会导致`UE4SS`不加载** |
248-
| STARTCMD | Native: `"./LinuxServer/PandemicServer.sh"`<br/>Wine: `"wine ./WindowsServer/PandemicServer.exe"` | 用于启动服务器的指令,修改例: `"wine ./StartServer.bat"` |
249-
| ENTRYPOINT_ARGS | Native: `"native no no"`<br/>Wine: `"wine no no"` | entrypoint.sh的参数,详见[Entrypoint Params](#entrypoint-params-1) |
250-
| UE4SS_LOG_SRC_PATH | Native: undefined<br/>Wine: `"${SRVPATH}/WindowsServer/Pandemic/Binaries/Win64/ue4ss"` | 被用于 [UE4SS Log Clipper](#ue4ss-log-clipper-1) |
251-
| UE4SS_LOG_TO_PATH | Native: undefined<br/>Wine: `"${UE4SS_LOG_SRC_PATH}/logs"` | 被用于 [UE4SS Log Clipper](#ue4ss-log-clipper-1) |
284+
| ENVs | 默认值 | 描述 |
285+
|-------------------- |--------------------------------------------------------------------------------------------------- |--------------------------------------------------------------------- |
286+
| APPID | `884110` | 游戏服务器的steam appid |
287+
| STEAMPATH | `"/home/5k/Steam"` | steamcmd的路径 |
288+
| SRVPATH | `"${STEAMPATH}/steamapps/common/SCP Pandemic Dedicated Server"` | 游戏服务器的路径 |
289+
| ARGS | `""` | 你想发给服务器的参数 |
290+
| STARTENV | Native: `""`<br/>Wine: `"WINEDLLOVERRIDES=dwmapi=native,builtin"` | 环境变量,**修改`WINEDLLOVERRIDES`可能会导致`UE4SS`不加载** |
291+
| STARTCMD | Native: `"./LinuxServer/PandemicServer.sh"`<br/>Wine: `"wine ./WindowsServer/PandemicServer.exe"` | 用于启动服务器的指令,修改例: `"wine ./StartServer.bat"` |
292+
| ENTRYPOINT_ARGS | Native: `"native no no"`<br/>Wine: `"wine no no"` | entrypoint.sh的参数,详见[Entrypoint Params](#entrypoint-params-1) |
293+
| ENTRYPOINT_ROOT_ARGS | `"yes"` | entrypoint_root.sh的参数,详见[Entrypoint Params](#entrypoint-params-1) |
294+
| UE4SS_LOG_SRC_PATH | Native: undefined<br/>Wine: `"${SRVPATH}/WindowsServer/Pandemic/Binaries/Win64/ue4ss"` | 被用于 [UE4SS Log Clipper](#ue4ss-log-clipper-1) |
295+
| UE4SS_LOG_TO_PATH | Native: undefined<br/>Wine: `"${UE4SS_LOG_SRC_PATH}/logs"` | 被用于 [UE4SS Log Clipper](#ue4ss-log-clipper-1) |
252296

253297
### Entrypoint Params
254298

299+
#### entrypoint_root.sh
300+
301+
| Params | Allowed value | Description |
302+
|-------- |---------------------- |------------------------------------------ |
303+
| $1 | `yes`, `force`, `no` | 用于是否chown `$SRVPATH`, `force`以忽略报错 |
304+
305+
示例:
306+
307+
```sh
308+
-e ENTRYPOINT_ROOT_ARGS="yes"
309+
```
310+
311+
会chown `$SRVPATH`
312+
313+
#### entrypoint.sh
314+
255315
| Params | 合法值 | 描述 |
256316
|-------- |-------------------------- |------------------------------------------------------------------ |
257317
| $1 | `native`, `wine`, `skip` | 用于设置steamcmd的平台类型,`skip`为跳过steamcmd |
258318
| $2 | `yes`, `no` | 用于是否启用[UE4SS Log Clipper](#ue4ss-log-clipper-1)**仅限Wine** |
259-
| $3 | `yes`, `no` | 用于是否[Reset Wine](#reset-wine-1)在服务器启动之前, **仅限Wine** |
319+
| $3 | `yes`, `no` | 用于是否[Reset Wine](#reset-wine-1)在服务器启动之前, **仅限Wine** |
260320
| $4 | `yes`, `no` | 用于是否启用[Log Checker](#log-checker-1) |
261321

262322
示例:
@@ -279,20 +339,42 @@ docker run --name scp5kserver -p 7777:7777/tcp -p 7777:7777/udp -p 27015:27015/t
279339

280340
跳过steamcmd,不启动UE4SS Log Clipper,不Reset Wine,不启动Log Checker
281341

282-
### UE4SS Log Clipper
342+
#### UE4SS Log Clipper
283343

284344
一个简单的脚本,会在每次服务器运行前复制`$UE4SS_LOG_SRC_PATH/UE4SS.log``$UE4SS_LOG_TO_PATH`
285345

286346
日志的命名格式: `$(date +"%Y%m%dT%H%M%S%z").log`
287347

288-
### Reset Wine
348+
#### Reset Wine
289349

290350
一个简单的脚本,会在每次服务器运行前`rm -rf /home/5k/.wine`
291351

292-
### Log Checker
352+
#### Log Checker
293353

294354
一个简单的脚本,会持续监听标准输出(stdout)和标准错误(stderr),如果发现匹配的字符串,就会杀掉服务器
295355

296356
默认匹配字符串:`FOnlineAsyncTaskSteamCreateServer bWasSuccessful: 0`, `SteamSockets API: Error`
297357

298358
你可以在`entrypoint.sh` > `$MATCH_TARGET`修改
359+
360+
## HACK:使用单文件运行多实例
361+
362+
> 如果文件从容器外导入,你可能需要手动更改权限
363+
364+
> 更改`$ENTRYPOINT_ROOT_ARGS` > `$1``force`可能会对权限问题有帮助
365+
366+
> 你必须跳过steamcmd,否则会因为服务器文件在只读文件系统而发生报错
367+
368+
创建一个volume用于存储主要的服务器文件,为每一个容器都以**只读形式**挂载在`$SRVPATH`(参阅[ENVs](#envs-1))
369+
370+
创建一个volume用于存储`Saved`文件夹,以**可写形式**挂载在`Saved`文件夹(一个volume对应一个容器)
371+
372+
**Wine**:`${SRVPATH}/LinuxServer/Pandemic/Saved`
373+
374+
**Native**:`${SRVPATH}/WindowsServer/Pandemic/Saved`
375+
376+
### 关于UE4SS
377+
378+
创建一个volume用于存储`ue4ss`文件夹,以**可写形式**挂载在`ue4ss`文件夹(一个volume对应一个容器)
379+
380+
> 或者你也可以只挂载`./ue4ss/Mods`文件夹

0 commit comments

Comments
 (0)