Skip to content

Commit df2bf83

Browse files
authored
Improve logging, organize (#5)
* Improve logging, reorganize s6-overlay structure * Update packages in README.md * Remove leftover debugging messages in swat4_startup.sh
1 parent 27a9a15 commit df2bf83

File tree

21 files changed

+1106
-73
lines changed

21 files changed

+1106
-73
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2023 Kevin Moore
3+
Copyright (c) 2024 MisterCalvin
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ services:
1818
image: ghcr.io/mistercalvin/swat4-server-docker:latest
1919
container_name: swat4-server-docker
2020
environment:
21+
TZ: America/New_York
2122
PUID: 1000 # Optional: Set the UID for the user inside the container; Default: 1000
2223
PGID: 1000 # Optional: Set the GID for the user inside the container; Default: 1000
2324
CONTENT_VERSION: SWAT4 # Required: Choose SWAT4, TSS, or enter the name of your mod folder (case-sensitive); Default: SWAT4
@@ -36,7 +37,7 @@ services:
3637
QUICK_ROUND_RESET: False # Optional: If true, the server will perform a quick reset in between rounds on the same map, if false, the server will do a full SwitchLevel between rounds; Default: False
3738
ADDITIONAL_ARGS: # Optional: Comma-separated list of additional arguments to modify; Default: unset
3839
volumes:
39-
- /path/to/your/gamefiles:/container/swat4
40+
- /path/to/your/gamefile:/container/swat4
4041
- swat4-wine:/container/.wine
4142
ports:
4243
- 10480-10483:10480-10483/udp
@@ -55,6 +56,7 @@ docker run -d \
5556
--name=swat4-server-docker \
5657
-e PUID="1000" \
5758
-e PGID="1000" \
59+
-e TZ="America/New_York" \
5860
-e CONTENT_VERSION="SWAT4" \
5961
-e SERVER_NAME="A SWAT 4 Docker Server" \
6062
-e SERVER_PASSWORD="" \
@@ -74,7 +76,7 @@ docker run -d \
7476
-v /path/to/gamefiles/:/container/swat4 \
7577
-v swat4-wine:/container/.wine \
7678
--restart unless-stopped \
77-
git.sbotnas.io/kevin/swat4-server-docker:latest
79+
ghcr.io/mistercalvin/swat4-server-docker:latest
7880
```
7981

8082
## Server Ports
@@ -105,7 +107,9 @@ SERVER_NAME="[c=0000ff][u][b]A SWAT 4 Docker Server[\u][\b]"
105107
#### Using ADDITIONAL_ARGS
106108
Most common options such as Server name, password, admin password, etc., have been exposed as environment variables for convenience. If you would like to modify an option not exposed, you can use ADDITIONAL_ARGS. For example, if you wanted to disable showing teammate names and disable respawns, you would add the following to your docker-compose.yml or docker run command:
107109

108-
> ADDITIONAL_ARGS="bShowTeammateNames=False,bNoRespawn=True"
110+
```
111+
ADDITIONAL_ARGS="bShowTeammateNames=False,bNoRespawn=True"
112+
```
109113

110114
For a list other options, take a look at your `SwatGUIState.ini`, located in `GAME_DIR/System/`.
111115

@@ -134,19 +138,21 @@ Please note this does not change file permissions on the mounted volume (`/conta
134138
| 11-99 Enhancement | <a href="https://www.moddb.com/mods/11-99-enhancement-mod/downloads/11-99-enhancement-mod-v13" target="_blank">1.3</a> |
135139

136140
## Building
137-
If you intend to build the Dockerfile yourself, I have not pinned the packages as Alpine does not keep old packages. At the time of writing (2024/04/18) I have built and tested the container with the following package versions:
138-
139-
| Package | Version |
140-
|-------------------------|--------------|
141-
| i386/alpine | 3.19.1 |
142-
| wine (**x86_64 only**) | 9.0-r0 |
143-
| hangover-wine (**arm64 only**) | 9.5-r0 |
144-
| xvfb-run | 1.20.10.3-r1 |
145-
| findutils | 4.9.0-r5 |
146-
| shadow | 4.14.2-r0 |
147-
| wget | 1.24.5-r0 |
148-
| s6-overlay | 3.1.6.2 |
149-
141+
If you intend to build the Dockerfile yourself, I have not pinned the packages as Alpine does not keep old packages. At the time of writing (2024/06/24) I have built and tested the container with the following package versions:
142+
143+
| Package | Version |
144+
| ------------------------------ | ------------ |
145+
| alpine | 3.20.1 |
146+
| wine (**i386 only**) | 9.0-r0 |
147+
| hangover-wine (**arm64 only**) | 9.5-r0 |
148+
| bash | 5.2.26-r0 |
149+
| tzdata | 2024a-r1 |
150+
| shadow | 4.15.1-r0 |
151+
| wget | 1.36.1 |
152+
| figlet | 2.2.5-r3 |
153+
| xvfb-run | 1.20.10.3-r2 |
154+
| findutils | 4.9.0-r5 |
155+
| s6-overlay | 3.1.6.2 |
150156

151157
## ARM64 Support
152158
This container has been adapted for use on ARM64 processors by utilizing the project <a href="https://github.com/AndreRH/hangover" target="_blank">AndreRH/hangover</a>. ARM64 support is experimental and was only tested on a Raspberry Pi 4, you may experience additional bugs.

build/Dockerfile.arm64

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1-
FROM arm64v8/alpine
1+
FROM arm64v8/alpine as builder
2+
RUN apk add --no-cache gcc musl-dev pcre-dev
3+
COPY ./simple_logger.c /src/
4+
WORKDIR /src
5+
RUN gcc -o simple_logger simple_logger.c /usr/lib/libpcre.a -static
6+
7+
FROM --platform=aarch64 arm64v8/alpine
8+
9+
ARG CONTAINER_MAJOR_VERSION=1
10+
ARG CONTAINER_MINOR_VERSION=1
11+
ARG CONTAINER_PATCH=1
212

313
ARG S6_OVERLAY_VERSION=3.1.6.2
414
ARG ARCH=aarch64
@@ -28,12 +38,15 @@ ENV \
2838
PGID="1000" \
2939
S6_VERBOSITY="0" \
3040
S6_CMD_WAIT_FOR_SERVICES_MAXTIME="0" \
31-
CONTAINER_DEBUG="0"
41+
CONTAINER_DEBUG="0" \
42+
TZ=""
3243

3344
RUN apk add --no-cache 'xvfb-run' \
3445
'findutils' \
3546
'shadow' \
3647
'bash' \
48+
'tzdata' \
49+
'figlet' \
3750
'dpkg' \
3851
'wget' && \
3952
apk add --no-cache --repository=https://dl-cdn.alpinelinux.org/alpine/edge/testing hangover-wine && \
@@ -52,11 +65,14 @@ RUN apk add --no-cache 'xvfb-run' \
5265
mkdir -m 760 /container && \
5366
addgroup --gid $PGID wine && \
5467
adduser --uid $PUID --home /container --disabled-password --no-create-home --shell /bin/false --ingroup wine wine && \
68+
touch /container/.CONTAINER_VERSION && \
69+
echo "${CONTAINER_MAJOR_VERSION}.${CONTAINER_MINOR_VERSION}.${CONTAINER_PATCH}" > /container/.CONTAINER_VERSION && \
5570
chown -R wine:wine /container
5671

5772
WORKDIR /container/swat4
5873

5974
COPY ./root /
75+
COPY --from=builder /src/simple_logger /usr/local/bin/simple_logger
6076

6177
EXPOSE 10480-10483/udp
6278

@@ -67,5 +83,5 @@ LABEL \
6783
org.opencontainers.image.title="SWAT 4 Docker" \
6884
org.opencontainers.image.description="Docker container for running a SWAT 4 Dedicated Server" \
6985
org.opencontainers.image.source=https://github.com/MisterCalvin/swat4-server-docker \
70-
org.opencontainers.image.version="1.1" \
86+
org.opencontainers.image.version="${CONTAINER_MAJOR_VERSION}.${CONTAINER_MINOR_VERSION}.${CONTAINER_PATCH}" \
7187
org.opencontainers.image.licenses=MIT

build/Dockerfile.i386

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1-
FROM i386/alpine
1+
FROM i386/alpine as builder
2+
RUN apk add --no-cache gcc musl-dev pcre-dev
3+
COPY ./simple_logger.c /src/
4+
WORKDIR /src
5+
RUN gcc -o simple_logger simple_logger.c /usr/lib/libpcre.a -static
6+
7+
FROM --platform=386 i386/alpine
8+
9+
ARG CONTAINER_MAJOR_VERSION=1
10+
ARG CONTAINER_MINOR_VERSION=1
11+
ARG CONTAINER_PATCH=1
212

313
ARG S6_OVERLAY_VERSION=3.1.6.2
414
ARG ARCH=x86_64
@@ -27,14 +37,17 @@ ENV \
2737
PGID="1000" \
2838
S6_VERBOSITY="0" \
2939
S6_CMD_WAIT_FOR_SERVICES_MAXTIME="0" \
30-
CONTAINER_DEBUG="0"
40+
CONTAINER_DEBUG="0" \
41+
TZ=""
3142

3243
RUN apk add --no-cache \
3344
'wine' \
3445
'xvfb-run' \
3546
'findutils' \
3647
'shadow' \
3748
'bash' \
49+
'tzdata' \
50+
'figlet' \
3851
'wget' && \
3952
mkdir /tmp/SWAT4 /tmp/TSS /tmp/build/ && \
4053
wget -q -nc --show-progress --progress=bar:force:noscroll --no-hsts -O /tmp/SWAT4/Engine.dll --user-agent=Mozilla --content-disposition -E -c "https://raw.githubusercontent.com/sergeii/swat-patches/master/swat4stats-masterserver/1.1/Engine.dll" && \
@@ -46,14 +59,16 @@ RUN apk add --no-cache \
4659
rm -rf /tmp/build/ && \
4760
apk --purge del wget && \
4861
mkdir -m 760 /container && \
49-
# wineboot -i && \
5062
addgroup --gid $PGID wine && \
5163
adduser --uid $PUID --home /container --disabled-password --no-create-home --shell /bin/false --ingroup wine wine && \
64+
touch /container/.CONTAINER_VERSION && \
65+
echo "${CONTAINER_MAJOR_VERSION}.${CONTAINER_MINOR_VERSION}.${CONTAINER_PATCH}" > /container/.CONTAINER_VERSION && \
5266
chown -R wine:wine /container
5367

5468
WORKDIR /container/swat4
5569

5670
COPY ./root /
71+
COPY --from=builder /src/simple_logger /usr/local/bin/simple_logger
5772

5873
EXPOSE 10480-10483/udp
5974

@@ -63,5 +78,5 @@ LABEL \
6378
org.opencontainers.image.title="SWAT 4 Docker" \
6479
org.opencontainers.image.description="Docker container for running a SWAT 4 Dedicated Server" \
6580
org.opencontainers.image.source=https://github.com/MisterCalvin/swat4-server-docker \
66-
org.opencontainers.image.version="1.1" \
81+
org.opencontainers.image.version="${CONTAINER_MAJOR_VERSION}.${CONTAINER_MINOR_VERSION}.${CONTAINER_PATCH}" \
6782
org.opencontainers.image.licenses=MIT
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/command/with-contenv bash
2+
3+
source /usr/bin/debug.sh
4+
5+
echo -e ""
6+
figlet -f ansi_shadow.flf "SWAT4"
7+
echo "A Docker container by MisterCalvin (v$(cat "/container/.CONTAINER_VERSION")) | discord.sbotnas.io"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
oneshot
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
exec simple_logger -o -l "/container/swat4/swat4-container.log" "bootloader" "false" /etc/s6-overlay/s6-rc.d/bootloader/run 2>&1
Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,29 @@
11
#!/command/with-contenv bash
22

3-
PUID=${PUID:-1000}
4-
PGID=${PGID:-1000}
3+
source /usr/bin/debug.sh
4+
5+
check_and_chown() {
6+
local dir=$1
7+
local uid=$(stat -c "%u" $dir)
8+
local gid=$(stat -c "%g" $dir)
9+
10+
if [ "$uid" != "$PUID" ] || [ "$gid" != "$PGID" ]; then
11+
echo "Changing ownership of $dir to $PUID:$PGID"
12+
chown -R "$PUID:$PGID" $dir
13+
fi
14+
}
515

616
if [ ! "$PUID" = "1000" ] || [ ! "$PGID" = "1000" ]; then
7-
echo "New UID/GID specified, modifying current container user"
8-
echo "Please note - this does not change file permissions on the mounted volume! This will only chown /container and /container/.wine to the specified UID/GID"
9-
echo "If the server is crashing or refusing to boot, check file permissions on the host mount!"
10-
groupmod --gid "$PGID" wine
11-
usermod --uid "$PUID" --gid "$PGID" wine
12-
chown "$PUID:$PGID" /container
17+
echo "New UID/GID specified, modifying current container user"
18+
echo "This will change file permissions on the mounted volume!"
19+
groupmod --gid "$PGID" wine
20+
usermod --uid "$PUID" --gid "$PGID" wine
21+
22+
# Ensure the root container directory is owned by wine user
23+
chown "$PUID:$PGID" /container
1324
fi
1425

15-
chown -R $PUID:$PGID /container/.wine
26+
# Check and change ownership recursively if necessary
27+
check_and_chown "/container"
28+
check_and_chown "/container/swat4"
29+
check_and_chown "/container/.wine"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
/etc/s6-overlay/s6-rc.d/init-user/run
1+
exec simple_logger -l "/container/swat4/swat4-container.log" "init-user" "true" /etc/s6-overlay/s6-rc.d/init-user/run 2>&1
Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
#!/command/with-contenv bash
22

3+
source /usr/bin/debug.sh
4+
35
if [ -z "$(ls -A /container/.wine)" ]; then
4-
echo "Generating Wine prefix, it may take between 1-2 minutes before the server boots. Please be patient, this should be quicker on subsequent runs."
5-
if [[ "$CONTAINER_DEBUG" -eq 1 ]]; then
6-
wineboot -i 2>&1
7-
else
8-
wineboot -i 2>&1 | grep -v -e "starting Box64 based box64cpu.dll" -e "Hangover currently has issues with some ACM modules, disabling"
9-
fi
10-
fi
6+
echo "Initializing wine prefix, this may take a minute or two on slower systems. Be patient, this will be quicker on subsequent runs."
7+
wineboot -u 2>&1
8+
fi
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
/etc/s6-overlay/s6-rc.d/init-wine-prefix/run
1+
exec simple_logger -l "/container/swat4/swat4-container.log" "init-wine-prefix" "false" /etc/s6-overlay/s6-rc.d/init-wine-prefix/run 2>&1
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
#!/command/execlineb -P
2-
s6-setuidgid wine
3-
"/usr/bin/swat4.sh"
1+
#!/bin/sh
2+
exec simple_logger -l "/container/swat4/swat4-container.log" "swat4-server" "true" s6-setuidgid wine /usr/bin/swat4_startup.sh 2>&1

build/root/usr/bin/debug.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
if [ "$CONTAINER_DEBUG" = "1" ]; then
4+
export PS4=' Line ${LINENO}: '
5+
set -x
6+
fi

build/root/usr/bin/filter.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
BEGIN FILTERS
2+
starting Box64 based box64cpu.dll
3+
Hangover currently has issues with some ACM modules, disabling
4+
END FILTERS
5+
6+
BEGIN ANONYMIZE
7+
(?<=Password=)[\w[$&+,:;=?@#|'<>.^*()%!-]+(?=\/g)
8+
(?<=\-n\s\').+?(?=\')
9+
END ANONYMIZE

build/root/usr/bin/swat4.sh renamed to build/root/usr/bin/swat4_startup.sh

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
#!/command/with-contenv bash
2-
## File: SWAT 4 Docker Script - swat4.sh
2+
## File: SWAT 4 Docker Script - swat4_startup.sh
33
## Author: Kevin Moore <admin@sbotnas.io>
44
## Created: 2023/07/11
5-
## Modified: 2024/04/17
5+
## Modified: 2024/05/13
66
## License: MIT License
7+
exec 2>&1
8+
source /usr/bin/debug.sh
9+
710
GAME_DIR=/container/swat4
811
NEW_SWAT4_ENGINEDLL=$(md5sum < /tmp/SWAT4/Engine.dll)
912
NEW_TSS_ENGINEDLL=$(md5sum < /tmp/TSS/Engine.dll)
1013
OLD_SWAT4_ENGINEDLL=$(md5sum < "$GAME_DIR/Content/System/Engine.dll")
1114
OLD_TSS_ENGINEDLL=$(md5sum < "$GAME_DIR/ContentExpansion/System/Engine.dll")
1215

13-
case $(echo "$CONTENT_VERSION" | tr '[:lower:]' '[:upper:]') in
16+
case "${CONTENT_VERSION}" in
1417
"SWAT4"|0)
1518
CONTENT_PATH=Content
1619
CONTENT_VERSION="SWAT 4"
@@ -24,7 +27,7 @@ case $(echo "$CONTENT_VERSION" | tr '[:lower:]' '[:upper:]') in
2427

2528
"$CONTENT_VERSION")
2629
CONTENT_PATH=$CONTENT_VERSION
27-
MOD_SYSTEM_FOLDER=$(find "$GAME_DIR/$CONTENT_VERSION" -type d -name System) 2> /dev/null || { echo "Cannot find Mod folder $GAME_DIR/$CONTENT_VERSION! Check that it exists, and that CONTENT_VERSION is set correctly!"; exit 1; }
30+
MOD_SYSTEM_FOLDER=$(find "$GAME_DIR/$CONTENT_PATH" -type d -name System) 2> /dev/null || { echo "Cannot find Mod folder $GAME_DIR/$CONTENT_PATH! Check that it exists, and that CONTENT_VERSION is set correctly!"; exit 1; }
2831
MOD_GAME_VERSION=$(find "$MOD_SYSTEM_FOLDER" -iregex '.*Swat4X?.ini' -type f -printf "%f")
2932

3033
case $MOD_GAME_VERSION in
@@ -48,7 +51,7 @@ esac
4851

4952
SwatGUIState=$(find "$GAME_DIR/$CONTENT_PATH/System" -type f -iname SwatGUIState.ini -printf "%f" -quit | grep .) && SwatGUIState="$GAME_DIR/$CONTENT_PATH/System/$SwatGUIState" || { echo "Cannot find $GAME_DIR/$CONTENT_VERSION/System/SwatGUIState.ini"; exit 1; }
5053

51-
case $(echo "$GAME_TYPE" | tr '[:lower:]' '[:upper:]') in
54+
case "${GAME_TYPE^^}" in
5255
"BARRICADED SUSPECTS")
5356
GAME_TYPE=MPM_BarricadedSuspects
5457
sed -i "s/^GameType=.*$/GameType=$GAME_TYPE/g" "$SwatGUIState"
@@ -197,18 +200,6 @@ if [ -f "$SERVER_BINARY.log" ]; then
197200
mv "$SERVER_BINARY.log" "$SERVER_BINARY.old.log"
198201
fi
199202

200-
echo -e "███████╗██╗ ██╗ █████╗ ████████╗ ██╗ ██╗"
201-
echo "██╔════╝██║ ██║██╔══██╗╚══██╔══╝ ██║ ██║"
202-
echo "███████╗██║ █╗ ██║███████║ ██║ ███████║"
203-
echo "╚════██║██║███╗██║██╔══██║ ██║ ╚════██║"
204-
echo "███████║╚███╔███╔╝██║ ██║ ██║ ██║"
205-
echo "╚══════╝ ╚══╝╚══╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝"
206-
echo "A Docker container by MisterCalvin | discord.sbotnas.io"
207-
208203
echo "Starting $CONTENT_VERSION Server, it may take up to 30 seconds before you see any logs"
209204

210-
if [ "$CONTAINER_DEBUG" = "1" ]; then
211-
xvfb-run wine "$GAME_DIR/${CONTENT_PATH_MOD:-$CONTENT_PATH/System/}$SERVER_BINARY.exe" "${MAPLIST[0]}" & tail -F "$SERVER_BINARY.log" 2> /dev/null
212-
else
213-
wine_wrapper.sh "$GAME_DIR/${CONTENT_PATH_MOD:-$CONTENT_PATH/System/}$SERVER_BINARY.exe" "${MAPLIST[0]}" &> /dev/null & tail -F "$SERVER_BINARY.log" 2> /dev/null
214-
fi
205+
xvfb-run wine "$GAME_DIR/${CONTENT_PATH_MOD:-$CONTENT_PATH/System/}$SERVER_BINARY.exe" "${MAPLIST[0]}" & tail -F "$SERVER_BINARY.log" 2> /dev/null

build/root/usr/bin/wine_wrapper.sh

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)