From a2e35decd9aeead9a7f7c4883be6dc936aabacbf Mon Sep 17 00:00:00 2001 From: luatan Date: Sat, 10 Feb 2024 17:13:23 +0100 Subject: [PATCH 1/6] refactor and remove delay if nobody is connected --- scripts/update.sh | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/scripts/update.sh b/scripts/update.sh index 614597a74..e8965ecb5 100644 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -32,22 +32,26 @@ 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 + + PLAYERLIST=$(rcon-cli -c /home/steam/server/rcon.yaml "ShowPlayers") + if [ "$(echo -n "$PLAYERLIST" | wc -l)" -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 From 47e255badefc3c319c22fbf0f03bab1dd916c517 Mon Sep 17 00:00:00 2001 From: luatan Date: Sat, 10 Feb 2024 17:42:45 +0100 Subject: [PATCH 2/6] add note to readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 63ca9f12d..f45c720d1 100644 --- a/README.md +++ b/README.md @@ -198,7 +198,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 | From 90825c93bd0eda7f62225d7f22e3844492fbdb01 Mon Sep 17 00:00:00 2001 From: luatan Date: Sun, 11 Feb 2024 12:30:16 +0100 Subject: [PATCH 3/6] add helper function get_player_count --- scripts/auto_reboot.sh | 6 ++++-- scripts/helper_functions.sh | 11 +++++++++++ scripts/update.sh | 5 +++-- 3 files changed, 18 insertions(+), 4 deletions(-) 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..273b3e4e2 100644 --- a/scripts/helper_functions.sh +++ b/scripts/helper_functions.sh @@ -65,3 +65,14 @@ isExecutable() { fi return "$return_val" } + +# Checks how many players are currently connected +# Returns 0 if RCON is not enabled +# Returns the player count if rcon is enabled +get_player_count() { + if [ "${RCON_ENABLED,,}" != true ]; then + return 0 + fi + PLAYERLIST=$(rcon-cli -c /home/steam/server/rcon.yaml "ShowPlayers") + return "$(echo -n "$PLAYERLIST" | wc -l)" +} \ No newline at end of file diff --git a/scripts/update.sh b/scripts/update.sh index e8965ecb5..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" @@ -42,8 +44,7 @@ if [ "$CURRENTBUILD" != "$TARGETBUILD" ]; then echo "New Build was found. Updating the server from $CURRENTBUILD to $TARGETBUILD." rm /palworld/steamapps/appmanifest_2394010.acf - PLAYERLIST=$(rcon-cli -c /home/steam/server/rcon.yaml "ShowPlayers") - if [ "$(echo -n "$PLAYERLIST" | wc -l)" -gt 0 ]; then + 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 From f182a50ac71234df3d4f18e2cd7609cbdd9e8709 Mon Sep 17 00:00:00 2001 From: luatan Date: Sun, 11 Feb 2024 13:00:36 +0100 Subject: [PATCH 4/6] fix helper function --- scripts/helper_functions.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/helper_functions.sh b/scripts/helper_functions.sh index 273b3e4e2..b5a5c11c5 100644 --- a/scripts/helper_functions.sh +++ b/scripts/helper_functions.sh @@ -71,8 +71,8 @@ isExecutable() { # Returns the player count if rcon is enabled get_player_count() { if [ "${RCON_ENABLED,,}" != true ]; then - return 0 + echo 0 fi - PLAYERLIST=$(rcon-cli -c /home/steam/server/rcon.yaml "ShowPlayers") - return "$(echo -n "$PLAYERLIST" | wc -l)" + player_list=$(rcon-cli -c /home/steam/server/rcon.yaml "ShowPlayers") + echo -n "${player_list}" | wc -l } \ No newline at end of file From 2bea0955839267016c75d6039667abf81dabc6bd Mon Sep 17 00:00:00 2001 From: luatan Date: Sun, 11 Feb 2024 13:01:25 +0100 Subject: [PATCH 5/6] change function docs --- scripts/helper_functions.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/helper_functions.sh b/scripts/helper_functions.sh index b5a5c11c5..5a6531da6 100644 --- a/scripts/helper_functions.sh +++ b/scripts/helper_functions.sh @@ -67,8 +67,8 @@ isExecutable() { } # Checks how many players are currently connected -# Returns 0 if RCON is not enabled -# Returns the player count if rcon is enabled +# Outputs 0 if RCON is not enabled +# Outputs the player count if rcon is enabled get_player_count() { if [ "${RCON_ENABLED,,}" != true ]; then echo 0 From 6c93d02822911457f550af5ae4e20edeeeae0d68 Mon Sep 17 00:00:00 2001 From: luatan Date: Sun, 11 Feb 2024 14:03:58 +0100 Subject: [PATCH 6/6] add local var and missing return --- scripts/helper_functions.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/helper_functions.sh b/scripts/helper_functions.sh index 5a6531da6..606655d9a 100644 --- a/scripts/helper_functions.sh +++ b/scripts/helper_functions.sh @@ -70,8 +70,10 @@ isExecutable() { # 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