From 44f03f5c3c0e13647e7cac19b414a3d724205a28 Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Mon, 19 Feb 2024 19:22:08 -0500 Subject: [PATCH 1/2] Added shutdown and save functions --- scripts/auto_reboot.sh | 3 +-- scripts/backup.sh | 2 +- scripts/helper_functions.sh | 27 +++++++++++++++++++++++++++ scripts/init.sh | 6 ++---- scripts/restore.sh | 3 +-- 5 files changed, 32 insertions(+), 9 deletions(-) diff --git a/scripts/auto_reboot.sh b/scripts/auto_reboot.sh index 13f1de424..12e7fac0a 100644 --- a/scripts/auto_reboot.sh +++ b/scripts/auto_reboot.sh @@ -25,8 +25,7 @@ if [[ "${AUTO_REBOOT_WARN_MINUTES}" =~ ^[0-9]+$ ]]; then RCON "broadcast The_Server_will_reboot_in_${i}_Minutes" sleep "1m" done - RCON save - RCON "shutdown 1" + shutdown_server exit 0 fi diff --git a/scripts/backup.sh b/scripts/backup.sh index 119ffa126..87d09e0d8 100644 --- a/scripts/backup.sh +++ b/scripts/backup.sh @@ -4,7 +4,7 @@ source "/home/steam/server/helper_functions.sh" DiscordMessage "Creating backup..." "in-progress" if [ "${RCON_ENABLED,,}" = true ]; then - RCON save + save_server fi DATE=$(date +"%Y-%m-%d_%H-%M-%S") diff --git a/scripts/helper_functions.sh b/scripts/helper_functions.sh index 41921f1c7..34b4ae444 100644 --- a/scripts/helper_functions.sh +++ b/scripts/helper_functions.sh @@ -134,6 +134,33 @@ RCON() { rcon-cli -c /home/steam/server/rcon.yaml "$args" } +# Saves the server +# Returns 0 if it saves +# Returns 1 if it is not able to save +save_server() { + local return_val=0 + if ! RCON save; then + return_val=1 + fi + return "$return_val" +} + +# Saves then shutdowns the server +# Returns 0 if it is shutdown +# Returns 1 if it is not able to be shutdown +shutdown_server() { + local return_val=0 + # Do not shutdown if not able to save + if save_server; then + if ! RCON "DoExit"; then + return_val=1 + fi + else + return_val=1 + fi + return "$return_val" +} + # Helper Functions for installation & updates # shellcheck source=/dev/null source "/home/steam/server/helper_install.sh" \ No newline at end of file diff --git a/scripts/init.sh b/scripts/init.sh index 0c03448e9..5094a87a1 100644 --- a/scripts/init.sh +++ b/scripts/init.sh @@ -28,10 +28,8 @@ mkdir -p /palworld/backups term_handler() { DiscordMessage "${DISCORD_PRE_SHUTDOWN_MESSAGE}" "in-progress" - if [ "${RCON_ENABLED,,}" = true ]; then - RCON save - RCON "shutdown 1" - else # Does not save + if ! shutdown_server; then + # Does not save kill -SIGTERM "$(pidof PalServer-Linux-Test)" fi diff --git a/scripts/restore.sh b/scripts/restore.sh index 9f4bac15b..3b432e6ec 100644 --- a/scripts/restore.sh +++ b/scripts/restore.sh @@ -63,8 +63,7 @@ if [ -f "$BACKUP_FILE" ]; then if [ "${RCON_ENABLED}" = true ]; then LogAction "Shutting Down Server" - RCON save - RCON "shutdown 1" + shutdown_server else LogWarn "RCON is not enabled. Please enable RCON to use this feature. Unable to restore backup." exit 1 From 332f2ee9c9b0e01b41ad3c149a82516ea3c69854 Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Mon, 19 Feb 2024 19:47:39 -0500 Subject: [PATCH 2/2] Updated readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b947e7fec..426874b18 100644 --- a/README.md +++ b/README.md @@ -222,10 +222,10 @@ 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. (This will be ignored, if no Players are connected) | 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 | Integer | | 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 | +| AUTO_REBOOT_WARN_MINUTES | How long to wait to reboot the server, after the player were informed. | 5 | Integer | | AUTO_REBOOT_EVEN_IF_PLAYERS_ONLINE | Restart the Server even if there are players online. | false | true/false | | TARGET_MANIFEST_ID | Locks game version to corespond with Manfiest ID from Steam Download Depot. | | See [Manifest ID Table](#locking-specific-game-version) | | DISCORD_WEBHOOK_URL | Discord webhook url found after creating a webhook on a discord server | | `https://discord.com/api/webhooks/` |