Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update server without delay if nobody is connected #349

Merged
merged 7 commits into from
Feb 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,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 |
Expand Down
6 changes: 4 additions & 2 deletions scripts/auto_reboot.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
13 changes: 13 additions & 0 deletions scripts/helper_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,16 @@ isExecutable() {
fi
return "$return_val"
}

# Checks how many players are currently connected
# 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
}
27 changes: 16 additions & 11 deletions scripts/update.sh
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -32,22 +34,25 @@ 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

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
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