From 25fd8730a097fffcd8f420e15754da9c8c8321bf Mon Sep 17 00:00:00 2001 From: Manuel Raimann Date: Sat, 10 Feb 2024 12:59:04 +0100 Subject: [PATCH] Add option to reboot even if there are players online --- .env.example | 1 + Dockerfile | 1 + Dockerfile.arm64 | 1 + README.md | 1 + scripts/auto_reboot.sh | 9 +++++++++ 5 files changed, 13 insertions(+) diff --git a/.env.example b/.env.example index bc302b960..63e62c78b 100644 --- a/.env.example +++ b/.env.example @@ -23,6 +23,7 @@ AUTO_UPDATE_ENABLED=false AUTO_UPDATE_CRON_EXPRESSION=0 * * * * AUTO_UPDATE_WARN_MINUTES=30 AUTO_REBOOT_ENABLED=false +AUTO_REBOOT_EVEN_IF_PLAYERS_ONLINE=false AUTO_REBOOT_WARN_MINUTES=5 AUTO_REBOOT_CRON_EXPRESSION=0 0 * * * diff --git a/Dockerfile b/Dockerfile index c077f6b88..7646e4ab2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -66,6 +66,7 @@ ENV PORT= \ AUTO_UPDATE_WARN_MINUTES=30 \ AUTO_REBOOT_ENABLED=false \ AUTO_REBOOT_WARN_MINUTES=5 \ + AUTO_REBOOT_EVEN_IF_PLAYERS_ONLINE=false \ AUTO_REBOOT_CRON_EXPRESSION="0 0 * * *" \ DISCORD_WEBHOOK_URL= \ DISCORD_CONNECT_TIMEOUT=30 \ diff --git a/Dockerfile.arm64 b/Dockerfile.arm64 index d4a568f13..df2d8e2ed 100644 --- a/Dockerfile.arm64 +++ b/Dockerfile.arm64 @@ -86,6 +86,7 @@ ENV PORT= \ AUTO_UPDATE_WARN_MINUTES=30 \ AUTO_REBOOT_ENABLED=false \ AUTO_REBOOT_WARN_MINUTES=5 \ + AUTO_REBOOT_EVEN_IF_PLAYERS_ONLINE=false \ AUTO_REBOOT_CRON_EXPRESSION="0 0 * * *" \ DISCORD_WEBHOOK_URL= \ DISCORD_CONNECT_TIMEOUT=30 \ diff --git a/README.md b/README.md index 63ca9f12d..12dfa64f6 100644 --- a/README.md +++ b/README.md @@ -202,6 +202,7 @@ It is highly recommended you set the following environment values before startin | 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_EVEN_IF_PLAYERS_ONLINE | Restart the Server even if there are players online. | false | true/false | | DISCORD_WEBHOOK_URL | Discord webhook url found after creating a webhook on a discord server | | `https://discord.com/api/webhooks/` | | DISCORD_CONNECT_TIMEOUT | Discord command initial connection timeout | 30 | !0 | | DISCORD_MAX_TIMEOUT | Discord total hook timeout | 30 | !0 | diff --git a/scripts/auto_reboot.sh b/scripts/auto_reboot.sh index 9fa4e0fde..376af7d0a 100644 --- a/scripts/auto_reboot.sh +++ b/scripts/auto_reboot.sh @@ -1,6 +1,15 @@ #!/bin/bash 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) + + if [ "$(echo -n "$players_count" | wc -l)" -gt 0 ]; then + echo "There are ${players_count} players online. Skipping auto reboot." + exit 1 + fi + fi + 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