From ffd238fde345170f4503e1aaa9a07a952ccd5342 Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Thu, 1 Feb 2024 19:12:09 -0500 Subject: [PATCH 01/10] Added auto reboot --- Dockerfile | 7 +++++-- scripts/auto_reboot.sh | 19 +++++++++++++++++++ scripts/start.sh | 8 +++++++- 3 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 scripts/auto_reboot.sh diff --git a/Dockerfile b/Dockerfile index 40d18c98d..5edc5c6dd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -47,10 +47,13 @@ ENV PORT= \ BACKUP_CRON_EXPRESSION="0 0 * * *" \ AUTO_UPDATE_ENABLED=false \ AUTO_UPDATE_CRON_EXPRESSION="0 * * * *" \ - AUTO_UPDATE_WARN_MINUTES=30 + AUTO_UPDATE_WARN_MINUTES=30 \ + AUTO_REBOOT_ENABLED=false \ + AUTO_REBOOT_WARN_MINUTES=5 \ + AUTO_REBOOT_CRON_EXPRESSION="0 3 * * *" COPY ./scripts/* /home/steam/server/ -RUN chmod +x /home/steam/server/init.sh /home/steam/server/start.sh /home/steam/server/backup.sh /home/steam/server/update.sh && \ +RUN chmod +x /home/steam/server/*.sh && \ mv /home/steam/server/backup.sh /usr/local/bin/backup && \ mv /home/steam/server/update.sh /usr/local/bin/update diff --git a/scripts/auto_reboot.sh b/scripts/auto_reboot.sh new file mode 100644 index 000000000..e0ce4867b --- /dev/null +++ b/scripts/auto_reboot.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +if [ "${RCON_ENABLED}" = true ]; then + if [ -z "${AUTO_REBOOT_WARN_MINUTES}" ]; then + echo "Unable to auto reboot, AUTO_REBOOT_WARN_MINUTES is empty." + elif [[ "${AUTO_REBOOT_WARN_MINUTES}" =~ ^[0-9]+$ ]]; then + for ((i = "${AUTO_REBOOT_WARN_MINUTES}" ; i > 0 ; i--)); do + rcon-cli -c /home/steam/server/rcon.yaml "broadcast The_Server_will_reboot_in_${AUTO_REBOOT_WARN_MINUTES}_Minutes" + sleep "${i}m" + done + + rcon-cli -c /home/steam/server/rcon.yaml save + rcon-cli -c /home/steam/server/rcon.yaml "shutdown 1" + else + echo "Unable to auto reboot, AUTO_REBOOT_WARN_MINUTES is not an integer: ${AUTO_REBOOT_WARN_MINUTES}" + fi +else + echo "Unable to reboot. RCON is required." +fi diff --git a/scripts/start.sh b/scripts/start.sh index ab86d3b5f..1ccd6b78d 100644 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -312,7 +312,13 @@ if [ "${AUTO_UPDATE_ENABLED}" = true ] && [ "${UPDATE_ON_BOOT}" = true ]; then 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 +if [ "${AUTO_REBOOT_ENABLED}" = true ] && [ "${RCON_ENABLED}" = true ]; then + echo "AUTO_REBOOT_ENABLED=${AUTO_REBOOT_ENABLED}" + echo "$AUTO_REBOOT_CRON_EXPRESSION bash /home/steam/server/auto_reboot.sh" >> "/home/steam/server/crontab" +fi + +if { [ "${AUTO_UPDATE_ENABLED}" = true ] && [ "${UPDATE_ON_BOOT}" = true ]; } || [ "${BACKUP_ENABLED}" = true ] || \ + [ "${AUTO_REBOOT_ENABLED}" = true ]; then supercronic "/home/steam/server/crontab" & fi From d6027864d82459ffd952ed1ccab02a9b628592f0 Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Thu, 1 Feb 2024 19:33:58 -0500 Subject: [PATCH 02/10] Changed default reboot to midnight --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 5edc5c6dd..963f15a8f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -50,7 +50,7 @@ ENV PORT= \ AUTO_UPDATE_WARN_MINUTES=30 \ AUTO_REBOOT_ENABLED=false \ AUTO_REBOOT_WARN_MINUTES=5 \ - AUTO_REBOOT_CRON_EXPRESSION="0 3 * * *" + AUTO_REBOOT_CRON_EXPRESSION="0 0 * * *" COPY ./scripts/* /home/steam/server/ RUN chmod +x /home/steam/server/*.sh && \ From 5dc6da8c98d6477e9bd3753c9e1ba5f58a6eb134 Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Thu, 1 Feb 2024 19:37:12 -0500 Subject: [PATCH 03/10] Updated readme --- README.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/README.md b/README.md index 9e3dc048e..297b2d742 100644 --- a/README.md +++ b/README.md @@ -181,6 +181,9 @@ It is highly recommended you set the following environment values before startin | 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_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 | *highly recommended to set @@ -290,6 +293,30 @@ AUTO_UPDATE_CRON_EXPRESSION is a cron expression, in a Cron-Expression you defin Set AUTO_UPDATE_CRON_EXPRESSION to change the default schedule. +## Configuring Automatic Reboots with Cron + +To be able to use automatic reboots with this server RCON_ENABLED enabled. + +> [!IMPORTANT] +> +> If docker restart is not set to policy `always` or `unless-stopped` then the server will shutdown and will need to be +> manually restarted. +> +> The example docker run command and docker compose file in [How to Use](#how-to-use) already use the needed policy + +Set AUTO_REBOOT_ENABLED enable or disable automatic backups (Default is disabled) + +AUTO_REBOOT_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_REBOOT_CRON_EXPRESSION to change the set the schedule, default is everynight at midnight according to the +timezone set with TZ + ## Editing Server Settings ### With Environment Variables From af4a63a747f53d79601c7e19dc94c37dda77e8fc Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Thu, 1 Feb 2024 19:53:22 -0500 Subject: [PATCH 04/10] Changed total sleep from N(N+1)/2 to N --- scripts/auto_reboot.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/auto_reboot.sh b/scripts/auto_reboot.sh index e0ce4867b..b348769c3 100644 --- a/scripts/auto_reboot.sh +++ b/scripts/auto_reboot.sh @@ -6,7 +6,7 @@ if [ "${RCON_ENABLED}" = true ]; then elif [[ "${AUTO_REBOOT_WARN_MINUTES}" =~ ^[0-9]+$ ]]; then for ((i = "${AUTO_REBOOT_WARN_MINUTES}" ; i > 0 ; i--)); do rcon-cli -c /home/steam/server/rcon.yaml "broadcast The_Server_will_reboot_in_${AUTO_REBOOT_WARN_MINUTES}_Minutes" - sleep "${i}m" + sleep "1m" done rcon-cli -c /home/steam/server/rcon.yaml save From d10599a9bd24ff41bddb048040b4cdf3b1663d50 Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Thu, 1 Feb 2024 19:56:35 -0500 Subject: [PATCH 05/10] Fixed reboot message to show coutndown --- scripts/auto_reboot.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/auto_reboot.sh b/scripts/auto_reboot.sh index b348769c3..e536567cc 100644 --- a/scripts/auto_reboot.sh +++ b/scripts/auto_reboot.sh @@ -5,7 +5,7 @@ if [ "${RCON_ENABLED}" = true ]; then echo "Unable to auto reboot, AUTO_REBOOT_WARN_MINUTES is empty." elif [[ "${AUTO_REBOOT_WARN_MINUTES}" =~ ^[0-9]+$ ]]; then for ((i = "${AUTO_REBOOT_WARN_MINUTES}" ; i > 0 ; i--)); do - rcon-cli -c /home/steam/server/rcon.yaml "broadcast The_Server_will_reboot_in_${AUTO_REBOOT_WARN_MINUTES}_Minutes" + rcon-cli -c /home/steam/server/rcon.yaml "broadcast The_Server_will_reboot_in_${i}_Minutes" sleep "1m" done From b4c7fd097b9c34d8c6865600c255be9703a30667 Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Thu, 1 Feb 2024 20:05:00 -0500 Subject: [PATCH 06/10] Fixed linting error --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 297b2d742..2967abf80 100644 --- a/README.md +++ b/README.md @@ -315,7 +315,7 @@ AUTO_REBOOT_CRON_EXPRESSION is a cron expression, in a Cron-Expression you defin > [Crontab Generat](https://crontab-generator.org). Set AUTO_REBOOT_CRON_EXPRESSION to change the set the schedule, default is everynight at midnight according to the -timezone set with TZ +timezone set with TZ ## Editing Server Settings From 92b435620c0d30003eb9b157135522ee708d63d3 Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Thu, 1 Feb 2024 23:43:50 -0500 Subject: [PATCH 07/10] Corrected generat to generator --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2967abf80..bb51cad05 100644 --- a/README.md +++ b/README.md @@ -262,7 +262,7 @@ BACKUP_CRON_EXPRESSION is a cron expression, in a Cron-Expression you define an > This image uses Supercronic for crons > see [supercronic](https://github.com/aptible/supercronic#crontab-format) > or -> [Crontab Generat](https://crontab-generator.org). +> [Crontab Generator](https://crontab-generator.org). 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. From a4877aeb66db1e6a86df5101c51d765a96650d84 Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Thu, 1 Feb 2024 23:50:08 -0500 Subject: [PATCH 08/10] Updated .env.example --- .env.example | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/.env.example b/.env.example index 2d4fb71fe..4e545584d 100644 --- a/.env.example +++ b/.env.example @@ -15,7 +15,16 @@ UPDATE_ON_BOOT=true RCON_ENABLED=true RCON_PORT=25575 QUERY_PORT=27015 - +BACKUP_ENABLED=true +DELETE_OLD_BACKUPS=false +OLD_BACKUP_DAYS=30 +BACKUP_CRON_EXPRESSION="0 0 * * *" +AUTO_UPDATE_ENABLED=false +AUTO_UPDATE_CRON_EXPRESSION="0 * * * *" +AUTO_UPDATE_WARN_MINUTES=30 +AUTO_REBOOT_ENABLED=false +AUTO_REBOOT_WARN_MINUTES=5 +AUTO_REBOOT_CRON_EXPRESSION="0 0 * * *" DIFFICULTY=None DAYTIME_SPEEDRATE=1.000000 From 7a8cb3eb90cfbae6021d905829058536f718944f Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Fri, 2 Feb 2024 03:22:07 -0500 Subject: [PATCH 09/10] Changed to case insensitive boolean --- scripts/auto_reboot.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/auto_reboot.sh b/scripts/auto_reboot.sh index e536567cc..9fa4e0fde 100644 --- a/scripts/auto_reboot.sh +++ b/scripts/auto_reboot.sh @@ -1,6 +1,6 @@ #!/bin/bash -if [ "${RCON_ENABLED}" = true ]; then +if [ "${RCON_ENABLED,,}" = true ]; then if [ -z "${AUTO_REBOOT_WARN_MINUTES}" ]; then echo "Unable to auto reboot, AUTO_REBOOT_WARN_MINUTES is empty." elif [[ "${AUTO_REBOOT_WARN_MINUTES}" =~ ^[0-9]+$ ]]; then From b568c1ba0fbf39b6b3c61d4cba74853d2545ad28 Mon Sep 17 00:00:00 2001 From: Thijs van Loef <58031337+thijsvanloef@users.noreply.github.com> Date: Fri, 2 Feb 2024 10:14:01 +0100 Subject: [PATCH 10/10] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index dd37132a1..3e38efc1f 100644 --- a/README.md +++ b/README.md @@ -307,7 +307,7 @@ AUTO_REBOOT_CRON_EXPRESSION is a cron expression, in a Cron-Expression you defin > This image uses Supercronic for crons > see [supercronic](https://github.com/aptible/supercronic#crontab-format) > or -> [Crontab Generat](https://crontab-generator.org). +> [Crontab Generator](https://crontab-generator.org). Set AUTO_REBOOT_CRON_EXPRESSION to change the set the schedule, default is everynight at midnight according to the timezone set with TZ