Skip to content

Commit

Permalink
Merge pull request #3 from jsknnr/dev
Browse files Browse the repository at this point in the history
graceful shutdown and add switch for game mode
  • Loading branch information
jsknnr authored May 31, 2024
2 parents d29a590 + 81bcfb6 commit d8e88e0
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 14 deletions.
25 changes: 16 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,25 @@ The processes within the container do **NOT** run as root. Everything runs as th

### Ports

| Port | Protocol | Default |
| ---- | -------- | ------- |
| Game Port | UDP | 27050 |
| Query Port | UDP | 27051 |
Game ports are arbitrary. You can use which ever values you want above 1000. Make sure that you are port forwarding (DNAT) correctly to your instance and that firewall rules are set correctly.

| Port | Description | Protocol | Default |
| ---- | ----------- | -------- | --------|
| Game Port | Port for client connections, should be value above 1000 | UDP | 27050 |
| Query Port | Port for server browser queries, should be a value above 1000 | UDP | 27051 |

### Environment Variables

| Name | Description | Default | Required |
| ---- | ----------- | ------- | -------- |
| SERVER_NAME | Name for the Server | Enshrouded Containerized | False |
| GAME_MODE | Set server to either 'pve' or 'pvp' | None | True |
| SERVER_PASSWORD | Password for the server | None | False |
| ADMIN_PASSWORD | Password for GM admin on server | AdminPleaseChangeMe | False |
| SERVER_LEVEL | Level for server to load. Currently there is only 1 so no need to change | Level01_Main | False |
| GAME_PORT | Port for server connections | 27050 | False |
| QUERY_PORT | Port for steam query of server | 27051 | False |
| SERVER_SLOTS | Number of slots for connections (Max 70) | 70 | False |
| SERVER_SLOTS | Number of slots for connections (Max 50) | 50 | False |
| LISTEN_ADDRESS | IP address for server to listen on | 0.0.0.0 | False |

### Docker
Expand All @@ -43,7 +46,8 @@ docker run \
--publish 27050:27050/udp \
--publish 27051:27051/udp \
--env=SERVER_NAME='Soulmask Containerized Server' \
--env=SERVER_SLOTS=70 \
--env=GAME_MODE='pve' \
--env=SERVER_SLOTS=50 \
--env=SERVER_PASSWORD='PleaseChangeMe' \
--env=ADMIN_PASSWORD='AdminPleaseChangeMe' \
--env=GAME_PORT=27050 \
Expand Down Expand Up @@ -86,11 +90,12 @@ volumes:
default.env file:
```properties
SERVER_NAME="Soulmask Containerized"
GAME_MODE="pve"
SERVER_PASSWORD="ChangeMePlease"
ADMIN_PASSWORD="AdminChangeMePlease"
GAME_PORT="27050"
QUERY_PORT="27051"
SERVER_SLOTS="70"
SERVER_SLOTS="50"
LISTEN_ADDRESS="0.0.0.0"
```

Expand All @@ -107,7 +112,8 @@ podman run \
--publish 27050:27050/udp \
--publish 27051:27051/udp \
--env=SERVER_NAME='Soulmask Containerized Server' \
--env=SERVER_SLOTS=70 \
--env=GAME_MODE='pve' \
--env=SERVER_SLOTS=50 \
--env=SERVER_PASSWORD='PleaseChangeMe' \
--env=ADMIN_PASSWORD='AdminPleaseChangeMe' \
--env=GAME_PORT=27050 \
Expand All @@ -128,11 +134,12 @@ Volume=soulmask-persistent-data:/home/steam/soulmask
PublishPort=27050-27051:27050-27051/udp
ContainerName=soulmask-server
Environment=SERVER_NAME="Soulmask Containerized"
Environment=GAME_MODE="pve"
Environment=SERVER_PASSWORD="ChangeMePlease"
Environment=ADMIN_PASSWORD="AdminChangeMePlease"
Environment=GAME_PORT="27050"
Environment=QUERY_PORT="27051"
Environment=SERVER_SLOTS="70"
Environment=SERVER_SLOTS="50"
Environment=LISTEN_ADDRESS="0.0.0.0"

[Service]
Expand Down
3 changes: 2 additions & 1 deletion container/Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ ENV STEAM_APP_ID "3017300"

ENV GAME_PORT "27050"
ENV QUERY_PORT "27051"
ENV SERVER_SLOTS "70"
ENV SERVER_SLOTS "50"
ENV LISTEN_ADDRESS "0.0.0.0"
ENV SERVER_LEVEL "Level01_Main"

Expand All @@ -27,6 +27,7 @@ RUN groupadd -g ${CONTAINER_GID} steam \
curl \
lib32gcc-s1 \
locales \
procps \
&& echo 'LANG="en_US.UTF-8"' > /etc/default/locale \
&& echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen \
&& locale-gen \
Expand Down
49 changes: 46 additions & 3 deletions container/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ timestamp () {
date +"%Y-%m-%d %H:%M:%S,%3N"
}

# Function to handle shutdown when sigterm is recieved
shutdown () {
echo ""
echo "$(timestamp) INFO: Recieved SIGTERM, shutting down gracefully"
kill -2 $soulmask_pid
tail --pid=$soulmask_pid -f /dev/null
echo "$(timestamp) INFO: Shutdown complete"
}

# Set our trap
trap 'shutdown' TERM

# Set vars established during image build
IMAGE_VERSION=$(cat /home/steam/image_version)
MAINTAINER=$(cat /home/steam/image_maintainer)
Expand All @@ -28,6 +40,17 @@ if [ -z "$SERVER_PASSWORD" ]; then
echo "$(timestamp) WARN: SERVER_PASSWORD not set, server will be open to the public"
fi

if [ -z "$GAME_MODE" ]; then
echo "$(timestamp) ERROR: GAME_MODE not set, must be 'pve' or 'pvp'"
exit 1
else
echo $GAME_MODE
if [ "$GAME_MODE" != "pve" ] && [ "$GAME_MODE" != "pvp" ]; then
echo "$(timestamp) ERROR: GAME_MODE must be either 'pve' or 'pvp'"
exit 1
fi
fi

# Check for proper save permissions
echo "$(timestamp) INFO: Validating data directory filesystem permissions"
if ! touch "${SOULMASK_PATH}/test"; then
Expand All @@ -53,9 +76,9 @@ fi

# Build launch arguments
echo "$(timestamp) INFO: Constructing launch arguments"
LAUNCH_ARGS="${SERVER_LEVEL} -server -SILENT -SteamServerName=${SERVER_NAME} -MaxPlayers=${SERVER_SLOTS} -backup=900 -saving=600 -log -UTF8Output -MULTIHOME=${LISTEN_ADDRESS} -Port=${GAME_PORT} -QueryPort=${QUERY_PORT} -online=Steam -forcepassthrough -adminpsw=${ADMIN_PASSWORD}"
LAUNCH_ARGS="${SERVER_LEVEL} -server -SILENT -SteamServerName=${SERVER_NAME} -${GAME_MODE} -MaxPlayers=${SERVER_SLOTS} -backup=900 -saving=600 -log -UTF8Output -MULTIHOME=${LISTEN_ADDRESS} -Port=${GAME_PORT} -QueryPort=${QUERY_PORT} -online=Steam -forcepassthrough -adminpsw=${ADMIN_PASSWORD}"

if [ -n "${SERVER_PSASWORD}" ]; then
if [ -n "${SERVER_PASSWORD}" ]; then
LAUNCH_ARGS="${LAUNCH_ARGS} -PSW=${SERVER_PASSWORD}"
fi

Expand All @@ -73,6 +96,7 @@ echo "
echo "$(timestamp) INFO: Launching Soulmask"
echo "--------------------------------------------------------------------------------"
echo "Server Name: ${SERVER_NAME}"
echo "Game Mode: ${GAME_MODE}"
echo "Server Level: ${SERVER_LEVEL}"
echo "Server Password: ${SERVER_PASSWORD}"
echo "Admin Password: ${ADMIN_PASSWORD}"
Expand All @@ -85,4 +109,23 @@ echo ""
echo ""

# Launch Soulmask
${SOULMASK_PATH}/WSServer.sh ${LAUNCH_ARGS}
${SOULMASK_PATH}/WSServer.sh ${LAUNCH_ARGS} &

# Capture Soulmask server start script pid
init_pid=$!

# Capture Soulmask server binary pid
timeout=0
while [ $timeout -lt 11 ]; do
if ps -e | grep "WSServer-Linux"; then
soulmask_pid=$(ps -e | grep "WSServer-Linux" | awk '{print $1}')
break
elif [ $timeout -eq 10 ]; then
echo "$(timestamp) ERROR: Timed out waiting for WSServer-Linux to be running"
exit 1
fi
sleep 6
((timeout++))
done

wait $init_pid
2 changes: 2 additions & 0 deletions helm/templates/depolyment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ spec:
env:
- name: SERVER_NAME
value: {{ .Values.config.serverName | quote }}
- name: GAME_MODE
value: {{ .Values.config.gameMode | quote }}
- name: SERVER_PASSWORD
value: {{ .Values.config.serverPassword | quote }}
- name: ADMIN_PASSWORD
Expand Down
3 changes: 2 additions & 1 deletion helm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ volumes:

config:
serverName: "Soulmask Containerized"
gameMode: "pve"
serverLevel: "Level01_Main"
serverPassword: ""
adminPassword: ""
gamePort: 27050
queryPort: 27051
serverSlots: 70
serverSlots: 50
listenAddress: 0.0.0.0

0 comments on commit d8e88e0

Please sign in to comment.