diff --git a/README.md b/README.md index a44a5dc2d..625ea10cf 100644 --- a/README.md +++ b/README.md @@ -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 | diff --git a/scripts/auto_reboot.sh b/scripts/auto_reboot.sh index 376af7d0a..313df8b4c 100644 --- a/scripts/auto_reboot.sh +++ b/scripts/auto_reboot.sh @@ -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 diff --git a/scripts/helper_functions.sh b/scripts/helper_functions.sh index 2386a77a6..606655d9a 100644 --- a/scripts/helper_functions.sh +++ b/scripts/helper_functions.sh @@ -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 +} \ No newline at end of file diff --git a/scripts/update.sh b/scripts/update.sh index 614597a74..8eb6ba302 100644 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -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" @@ -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 \ No newline at end of file