Skip to content

Commit

Permalink
Merge pull request #347 from raimannma/main
Browse files Browse the repository at this point in the history
Prevent reboot if there are players online
  • Loading branch information
thijsvanloef authored Feb 11, 2024
2 parents b7e04bc + 25fd873 commit e1add5e
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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 * * *

Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
1 change: 1 addition & 0 deletions Dockerfile.arm64
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/<webhook_id>` |
| DISCORD_CONNECT_TIMEOUT | Discord command initial connection timeout | 30 | !0 |
| DISCORD_MAX_TIMEOUT | Discord total hook timeout | 30 | !0 |
Expand Down
9 changes: 9 additions & 0 deletions scripts/auto_reboot.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit e1add5e

Please sign in to comment.