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

Added shutdown and save functions #412

Merged
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,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/<webhook_id>` |
Expand Down
3 changes: 1 addition & 2 deletions scripts/auto_reboot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ if [[ "${AUTO_REBOOT_WARN_MINUTES}" =~ ^[0-9]+$ ]]; then
broadcast_command "The Server will reboot in ${i} minutes"
sleep "1m"
done
RCON save
RCON "shutdown 1"
shutdown_server
exit 0
fi

Expand Down
2 changes: 1 addition & 1 deletion scripts/backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
27 changes: 27 additions & 0 deletions scripts/helper_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,30 @@ broadcast_command() {
fi
return "$return_val"
}

# 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"
}
6 changes: 2 additions & 4 deletions scripts/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 1 addition & 2 deletions scripts/restore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down