From 81bcfb6b747a6f0bf9400400ca8da03e3e60548a Mon Sep 17 00:00:00 2001 From: John Skinner Date: Fri, 31 May 2024 10:59:05 -0500 Subject: [PATCH] graceful shutdown and add switch for game mode --- README.md | 25 ++++++++++------- container/Containerfile | 3 ++- container/entrypoint.sh | 49 +++++++++++++++++++++++++++++++--- helm/templates/depolyment.yaml | 2 ++ helm/values.yaml | 3 ++- 5 files changed, 68 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 9e667f1..7dbd787 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 \ @@ -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" ``` @@ -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 \ @@ -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] diff --git a/container/Containerfile b/container/Containerfile index 41721b0..0e249f3 100644 --- a/container/Containerfile +++ b/container/Containerfile @@ -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" @@ -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 \ diff --git a/container/entrypoint.sh b/container/entrypoint.sh index dac5202..c5e76c5 100755 --- a/container/entrypoint.sh +++ b/container/entrypoint.sh @@ -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) @@ -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 @@ -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 @@ -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}" @@ -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 diff --git a/helm/templates/depolyment.yaml b/helm/templates/depolyment.yaml index c4d98c8..03b7829 100644 --- a/helm/templates/depolyment.yaml +++ b/helm/templates/depolyment.yaml @@ -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 diff --git a/helm/values.yaml b/helm/values.yaml index 664c09e..c25b903 100644 --- a/helm/values.yaml +++ b/helm/values.yaml @@ -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