Skip to content

Commit

Permalink
Merge pull request #349 from Luatan/auto-update-no-delay
Browse files Browse the repository at this point in the history
Update server without delay if nobody is connected
  • Loading branch information
thijsvanloef authored Feb 11, 2024
2 parents 0498271 + 26d5c15 commit 49a118d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ It is highly recommended you set the following environment values before startin
| 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 |
| AUTO_UPDATE_WARN_MINUTES | How long to wait to update the server, after the player were informed. (This will be ignored, if no Players are connected) | 30 | !0 |
| AUTO_REBOOT_CRON_EXPRESSION | Setting affects frequency of automatic updates. | 0 0 \* \* \* | Needs a Cron-Expression - See [Configuring Automatic Backups with Cron](#configuring-automatic-reboots-with-cron) |
| AUTO_REBOOT_ENABLED | Enables automatic reboots | false | true/false |
| AUTO_REBOOT_WARN_MINUTES | How long to wait to reboot the server, after the player were informed. | 5 | !0 |
Expand Down
6 changes: 4 additions & 2 deletions scripts/auto_reboot.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#!/bin/bash
# shellcheck source=/dev/null
source "/home/steam/server/helper_functions.sh"

if [ "${RCON_ENABLED,,}" = true ]; then
if [ "${AUTO_REBOOT_EVEN_IF_PLAYERS_ONLINE,,}" != true ]; then
players_count=$(rcon-cli -c /home/steam/server/rcon.yaml showplayers)
players_count=$(get_player_count)

if [ "$(echo -n "$players_count" | wc -l)" -gt 0 ]; then
if [ "$players_count" -gt 0 ]; then
echo "There are ${players_count} players online. Skipping auto reboot."
exit 1
fi
Expand Down
13 changes: 13 additions & 0 deletions scripts/helper_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,16 @@ isExecutable() {
fi
return "$return_val"
}

# Checks how many players are currently connected
# Outputs 0 if RCON is not enabled
# Outputs the player count if rcon is enabled
get_player_count() {
local player_list
if [ "${RCON_ENABLED,,}" != true ]; then
echo 0
return 0
fi
player_list=$(rcon-cli -c /home/steam/server/rcon.yaml "ShowPlayers")
echo -n "${player_list}" | wc -l
}
27 changes: 16 additions & 11 deletions scripts/update.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/bin/bash
# shellcheck source=/dev/null
source "/home/steam/server/helper_functions.sh"

if [ "${UPDATE_ON_BOOT}" = false ]; then
echo "Update on Boot needs to be enabled for auto updating"
Expand Down Expand Up @@ -32,22 +34,25 @@ if [ -z "$TARGETBUILD" ]; then
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
if [ -n "${DISCORD_WEBHOOK_URL}" ]; then
/home/steam/server/discord.sh "Server will update in ${AUTO_UPDATE_WARN_MINUTES} minutes" "info" &
fi
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
if [ "${RCON_ENABLED,,}" != true ]; then
echo "An update is available however auto updating without rcon is not supported"
if [ -n "${DISCORD_WEBHOOK_URL}" ]; then
/home/steam/server/discord.sh "An update is available however auto updating without rcon is not supported" "warn"
fi
exit 0
fi
echo "New Build was found. Updating the server from $CURRENTBUILD to $TARGETBUILD."
rm /palworld/steamapps/appmanifest_2394010.acf

if [ "$(get_player_count)" -gt 0 ]; then
if [ -n "${DISCORD_WEBHOOK_URL}" ]; then
/home/steam/server/discord.sh "Server will update in ${AUTO_UPDATE_WARN_MINUTES} minutes" "info" &
fi
rcon-cli -c /home/steam/server/rcon.yaml "broadcast Server_will_update_in_${AUTO_UPDATE_WARN_MINUTES}_Minutes"
sleep "${AUTO_UPDATE_WARN_MINUTES}m"
fi
backup
rcon-cli -c /home/steam/server/rcon.yaml "shutdown 1"
else
echo "The Server is up to date!"
fi

0 comments on commit 49a118d

Please sign in to comment.