Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cron update #209

Merged
merged 28 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
d34204a
add update check script
Luatan Jan 29, 2024
6328abf
add script and created env variables
Luatan Jan 29, 2024
bbf89ba
added another cronjob
Luatan Jan 29, 2024
bdfacf0
add update check script
Luatan Jan 29, 2024
a373601
add script and created env variables
Luatan Jan 29, 2024
0a9b13e
added another cronjob
Luatan Jan 29, 2024
182c866
Merge branch 'cron-update' of https://github.com/Luatan/palworld-serv…
Luatan Jan 29, 2024
74959bf
change default value to 30
Luatan Jan 29, 2024
a6364d4
default is disabled because real world test is missing
Luatan Jan 29, 2024
c3483fe
added description and env variables
Luatan Jan 29, 2024
8715740
fix linting
Luatan Jan 29, 2024
411fa4e
Apply suggestions from code review
Luatan Jan 29, 2024
1691357
changed env variables
Luatan Jan 29, 2024
8ec566d
clarification about restarting the container
Luatan Jan 29, 2024
56a7486
Update scripts/update.sh
Luatan Jan 29, 2024
4d6a5b5
remove crontab on every restart and fixed env var
Luatan Jan 29, 2024
71d7107
do not update if Targetbuild is empty
Luatan Jan 29, 2024
c12cc67
update environment variables in docs
Luatan Jan 29, 2024
65291c8
Merge branch 'cron-update' of https://github.com/Luatan/palworld-serv…
Luatan Jan 29, 2024
90a7177
Update README.md
Luatan Jan 29, 2024
582a715
Remove extra spaces
Luatan Jan 29, 2024
b73dabf
Set the default value to false in Readme.md
Luatan Jan 29, 2024
b72faba
Removed quotes from UPDATE_ON_BOOT check
Luatan Jan 29, 2024
9ec6350
changed AUTO_UPDATE_CRON_EXPRESSION default value to hourly
Luatan Jan 30, 2024
3ebb81f
Merge branch 'cron-update' of https://github.com/Luatan/palworld-serv…
Luatan Jan 30, 2024
4fb73aa
check server response and react accordingly
Luatan Jan 30, 2024
4d222b1
Add missing bracket
Luatan Jan 30, 2024
9ed95d3
fix linting
thijsvanloef Jan 31, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@
| 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 0 \* \* \* | Needs a Cron-Expression - See [Configuring Automatic Backups with Cron](#configuring-automatic-backups-with-cron) |
Luatan marked this conversation as resolved.
Show resolved Hide resolved
| AUTO_UPDATE_ENABLED | Enables automatic updates | true | true/false |
Luatan marked this conversation as resolved.
Show resolved Hide resolved
| AUTO_UPDATE_WARN_MINUTES | How long to wait to update the server, after the player were informed. | 30 | !0 |

*highly recommended to set

Expand Down Expand Up @@ -260,6 +263,32 @@
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
Luatan marked this conversation as resolved.
Show resolved Hide resolved

> [!IMPORTANT]
>

Check failure on line 274 in README.md

View workflow job for this annotation

GitHub Actions / Lint - Markdown

Trailing spaces

README.md:274:2 MD009/no-trailing-spaces Trailing spaces [Expected: 0 or 2; Actual: 1] https://github.com/DavidAnson/markdownlint/blob/v0.33.0/doc/md009.md
> If docker restart is not set to policy `always` or `unless-stopped` then the server will shutdown and will need to be
> manually restarted.

Check failure on line 276 in README.md

View workflow job for this annotation

GitHub Actions / Lint - Markdown

Trailing spaces

README.md:276:22 MD009/no-trailing-spaces Trailing spaces [Expected: 0 or 2; Actual: 1] https://github.com/DavidAnson/markdownlint/blob/v0.33.0/doc/md009.md
>

Check failure on line 277 in README.md

View workflow job for this annotation

GitHub Actions / Lint - Markdown

Trailing spaces

README.md:277:2 MD009/no-trailing-spaces Trailing spaces [Expected: 0 or 2; Actual: 1] https://github.com/DavidAnson/markdownlint/blob/v0.33.0/doc/md009.md
> The example docker run command and docker compose file in [How to Use](#how-to-use) already use the needed policy
Luatan marked this conversation as resolved.
Show resolved Hide resolved

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
Expand Down
11 changes: 10 additions & 1 deletion scripts/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Luatan marked this conversation as resolved.
Show resolved Hide resolved
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

Expand Down
24 changes: 24 additions & 0 deletions scripts/update.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

if [ "${UPDATE_ON_BOOT}" = false ]; then
echo "Update on Boot needs to be enabled for auto updating"
exit 1
fi

CURRENTBUILD=$(awk '/buildid/{ print $2 }' < /palworld/steamapps/appmanifest_2394010.acf)
TARGETBUILD=$(curl https://api.steamcmd.net/v1/info/2394010 --silent | grep -P '"public": {"buildid": "\d+"' -o | sed -r 's/.*("[0-9]+")$/\1/')

if [ -n "$TARGETBUILD" ] && [ "$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!"
Luatan marked this conversation as resolved.
Show resolved Hide resolved
fi
Loading