diff --git a/Dockerfile b/Dockerfile index 21a55e18c..acaf6c779 100644 --- a/Dockerfile +++ b/Dockerfile @@ -42,11 +42,15 @@ ENV PORT= \ TZ=UTC \ SERVER_DESCRIPTION= \ BACKUP_ENABLED=true \ - BACKUP_CRON_EXPRESSION="0 0 * * *" + BACKUP_CRON_EXPRESSION="0 0 * * *" \ + AUTO_UPDATE_ENABLED=false \ + AUTO_UPDATE_CRON_EXPRESSION="0 * * * *" \ + AUTO_UPDATE_WARN_MINUTES=30 COPY ./scripts/* /home/steam/server/ -RUN chmod +x /home/steam/server/init.sh /home/steam/server/start.sh /home/steam/server/backup.sh && \ - mv /home/steam/server/backup.sh /usr/local/bin/backup +RUN chmod +x /home/steam/server/init.sh /home/steam/server/start.sh /home/steam/server/backup.sh /home/steam/server/update.sh && \ + mv /home/steam/server/backup.sh /usr/local/bin/backup && \ + mv /home/steam/server/update.sh /usr/local/bin/update WORKDIR /home/steam/server diff --git a/README.md b/README.md index eb05d26c7..eb582f3ce 100644 --- a/README.md +++ b/README.md @@ -177,6 +177,9 @@ It is highly recommended you set the following environment values before startin | BACKUP_ENABLED | Enables automatic backups | true | true/false | | DELETE_OLD_BACKUPS | Delete backups after a certain number of days | false | true/false | | OLD_BACKUP_DAYS | How many days to keep backups | 30 | any positive integer | +| AUTO_UPDATE_CRON_EXPRESSION | Setting affects frequency of automatic updates. | 0 \* \* \* \* | Needs a Cron-Expression - See [Configuring Automatic Backups with Cron](#configuring-automatic-backups-with-cron) | +| AUTO_UPDATE_ENABLED | Enables automatic updates | false | true/false | +| AUTO_UPDATE_WARN_MINUTES | How long to wait to update the server, after the player were informed. | 30 | !0 | *highly recommended to set @@ -260,6 +263,32 @@ BACKUP_CRON_EXPRESSION is a cron expression, in a Cron-Expression you define an Set BACKUP_CRON_EXPRESSION to change the default schedule. Example Usage: If BACKUP_CRON_EXPRESSION to `0 2 * * *`, the backup script will run every day at 2:00 AM. +## Configuring Automatic Updates with Cron + +To be able to use automatic Updates with this Server the following environment variables **have** to be set to `true`: + +* RCON_ENABLED +* UPDATE_ON_BOOT + +> [!IMPORTANT] +> +> If docker restart is not set to policy `always` or `unless-stopped` then the server will shutdown and will need to be +> manually restarted. +> +> The example docker run command and docker compose file in [How to Use](#how-to-use) already use the needed policy + +Set AUTO_UPDATE_ENABLED enable or disable automatic backups (Default is disabled) + +AUTO_UPDATE_CRON_EXPRESSION is a cron expression, in a Cron-Expression you define an interval for when to run jobs. + +> [!TIP] +> This image uses Supercronic for crons +> see [supercronic](https://github.com/aptible/supercronic#crontab-format) +> or +> [Crontab Generat](https://crontab-generator.org). + +Set AUTO_UPDATE_CRON_EXPRESSION to change the default schedule. + ## Editing Server Settings ### With Environment Variables diff --git a/scripts/start.sh b/scripts/start.sh index 40edf2ff8..5ef45017a 100644 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -289,10 +289,19 @@ if [ -n "${RCON_PORT}" ]; then sed -i "s/RCONPort=[0-9]*/RCONPort=$RCON_PORT/" /palworld/Pal/Saved/Config/LinuxServer/PalWorldSettings.ini fi +rm -f "/home/steam/server/crontab" if [ "${BACKUP_ENABLED}" = true ]; then echo "BACKUP_ENABLED=${BACKUP_ENABLED}" - echo "$BACKUP_CRON_EXPRESSION bash /usr/local/bin/backup" > "/home/steam/server/crontab" + echo "$BACKUP_CRON_EXPRESSION bash /usr/local/bin/backup" >> "/home/steam/server/crontab" +fi + +if [ "${AUTO_UPDATE_ENABLED}" = true ] && [ "${UPDATE_ON_BOOT}" = true ]; then + echo "AUTO_UPDATE_ENABLED=${AUTO_UPDATE_ENABLED}" + echo "$AUTO_UPDATE_CRON_EXPRESSION bash /usr/local/bin/update" >> "/home/steam/server/crontab" +fi + +if { [ "${AUTO_UPDATE_ENABLED}" = true ] && [ "${UPDATE_ON_BOOT}" = true ]; } || [ "${BACKUP_ENABLED}" = true ]; then supercronic "/home/steam/server/crontab" & fi diff --git a/scripts/update.sh b/scripts/update.sh new file mode 100644 index 000000000..c523c4c71 --- /dev/null +++ b/scripts/update.sh @@ -0,0 +1,38 @@ +#!/bin/bash + +if [ "${UPDATE_ON_BOOT}" = false ]; then + echo "Update on Boot needs to be enabled for auto updating" + exit 0 +fi + +temp_file=$(mktemp) +http_code=$(curl https://api.steamcmd.net/v1/info/2394010 --output "$temp_file" --silent --location --write-out "%{http_code}") + +CURRENTBUILD=$(awk '/buildid/{ print $2 }' < /palworld/steamapps/appmanifest_2394010.acf) +TARGETBUILD=$(grep -P '"public": {"buildid": "\d+"' -o <"$temp_file" | sed -r 's/.*("[0-9]+")$/\1/') +rm "$temp_file" + +if [ "$http_code" -ne 200 ]; then + echo "There was a problem reaching the Steam api. Unable to check for updates!" + exit 1 +fi + +if [ -z "$TARGETBUILD" ]; then + echo "The server response does not contain the expected BuildID. Unable to check for updates!" + exit 1 +fi + +if [ "$CURRENTBUILD" != "$TARGETBUILD" ]; then + echo "New Build was found. Updating the server from $CURRENTBUILD to $TARGETBUILD." + if [ "${RCON_ENABLED}" = true ]; then + rm /palworld/steamapps/appmanifest_2394010.acf + rcon-cli -c /home/steam/server/rcon.yaml "broadcast The_Server_will_update_in_${AUTO_UPDATE_WARN_MINUTES}_Minutes" + sleep "${AUTO_UPDATE_WARN_MINUTES}m" + backup + rcon-cli -c /home/steam/server/rcon.yaml "shutdown 1" + else + echo "An update is available however auto updating without rcon is not supported" + fi +else + echo "The Server is up to date!" +fi \ No newline at end of file