From 0390f601c0d0ccd459a96af5686d01e1f925d25d Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Tue, 30 Jan 2024 23:59:11 -0500 Subject: [PATCH] Modified to support PUID/PGID by default --- .env.example | 2 ++ Dockerfile | 3 ++- docker-compose.yml | 3 ++- k8s/deployment.yaml | 3 --- scripts/backup.sh | 4 ++++ scripts/init.sh | 18 ++++++++++++++++-- 6 files changed, 26 insertions(+), 7 deletions(-) diff --git a/.env.example b/.env.example index 66c74eb45..a19f71e7c 100644 --- a/.env.example +++ b/.env.example @@ -1,6 +1,8 @@ TZ="UTC" PLAYERS="16" PORT="8211" +PUID="1000" +PGID="1000" MULTITHREADING="false" COMMUNITY="false" PUBLIC_IP="" diff --git a/Dockerfile b/Dockerfile index d1916abd7..558749eb2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -25,6 +25,8 @@ RUN wget -q "$SUPERCRONIC_URL" \ && ln -s "/usr/local/bin/${SUPERCRONIC}" /usr/local/bin/supercronic ENV PORT= \ + PUID=1000 \ + PGID=1000 \ PLAYERS= \ MULTITHREADING=false \ COMMUNITY=false \ @@ -55,5 +57,4 @@ HEALTHCHECK --start-period=5m \ CMD pgrep "PalServer-Linux" > /dev/null || exit 1 EXPOSE ${PORT} ${RCON_PORT} -USER steam ENTRYPOINT ["/home/steam/server/init.sh"] diff --git a/docker-compose.yml b/docker-compose.yml index d548c41ef..ef5491aae 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,11 +4,12 @@ services: restart: unless-stopped container_name: palworld-server stop_grace_period: 30s # Set to however long you are willing to wait for the container to gracefully stop - user: 1000:1000 ports: - 8211:8211/udp - 27015:27015/udp # Required if you want your server to show up in the community servers tab environment: + - PUID=1000 + - PGID=1000 - PORT=8211 # Optional but recommended - PLAYERS=16 # Optional but recommended - SERVER_PASSWORD="worldofpals" # Optional but recommended diff --git a/k8s/deployment.yaml b/k8s/deployment.yaml index a4db9844a..d94759fb4 100644 --- a/k8s/deployment.yaml +++ b/k8s/deployment.yaml @@ -20,9 +20,6 @@ spec: - name: palworld-server image: thijsvanloef/palworld-server-docker imagePullPolicy: IfNotPresent - securityContext: - runAsUser: 1000 - runAsGroup: 1000 ports: - containerPort: 8211 name: server diff --git a/scripts/backup.sh b/scripts/backup.sh index a4dbe517e..0fd0b6d65 100644 --- a/scripts/backup.sh +++ b/scripts/backup.sh @@ -10,6 +10,10 @@ cd /palworld/Pal/ || exit tar -zcf "$FILE_PATH" "Saved/" +if [ "$(id -u)" -eq 0 ]; then + chown steam:steam "$FILE_PATH" +fi + echo "backup created at $FILE_PATH" if [ "${DELETE_OLD_BACKUPS}" = true ]; then diff --git a/scripts/init.sh b/scripts/init.sh index 0e19c5bcd..2ac9db324 100644 --- a/scripts/init.sh +++ b/scripts/init.sh @@ -1,6 +1,16 @@ #!/bin/bash -if [[ "$(id -u)" -eq 0 ]] || [[ "$(id -g)" -eq 0 ]]; then +if [[ "$(id -u)" -eq 0 ]] && [[ "$(id -g)" -eq 0 ]]; then + if [[ "${PUID}" -ne 0 ]] && [[ "${PGID}" -ne 0 ]]; then + printf "\e[0;32m*****EXECUTING USERMOD*****\e[0m\n" + usermod -o -u "${PUID}" steam + groupmod -o -g "${PGID}" steam + chown -R steam:steam /palworld /home/steam/ + else + printf "\033[31mRunning as root is not supported, please fix your PUID and PGID!\n" + exit 1 + fi +elif [[ "$(id -u)" -eq 0 ]] || [[ "$(id -g)" -eq 0 ]]; then printf "\033[31mRunning as root is not supported, please fix your user!\n" exit 1 fi @@ -19,7 +29,11 @@ term_handler() { trap 'term_handler' SIGTERM -./start.sh & +if [[ "$(id -u)" -eq 0 ]]; then + su steam -c ./start.sh & +else + ./start.sh & +fi # Process ID of su killpid="$!" wait $killpid