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

Add save and shutdown functions #398

Closed
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
3 changes: 1 addition & 2 deletions scripts/auto_reboot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ if [ "${RCON_ENABLED,,}" = true ]; then
sleep "1m"
done

rcon-cli -c /home/steam/server/rcon.yaml save
rcon-cli -c /home/steam/server/rcon.yaml "shutdown 1"
shutdown_server
else
echo "Unable to auto reboot, AUTO_REBOOT_WARN_MINUTES is not an integer: ${AUTO_REBOOT_WARN_MINUTES}"
fi
Expand Down
4 changes: 1 addition & 3 deletions scripts/backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ if [ -n "${DISCORD_WEBHOOK_URL}" ]; then
/home/steam/server/discord.sh "Creating backup..." "in-progress" &
fi

if [ "${RCON_ENABLED,,}" = true ]; then
rcon-cli -c /home/steam/server/rcon.yaml save
fi
save_server

DATE=$(date +"%Y-%m-%d_%H-%M-%S")
FILE_PATH="/palworld/backups/palworld-save-${DATE}.tar.gz"
Expand Down
33 changes: 32 additions & 1 deletion scripts/helper_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,35 @@ get_player_count() {
fi
player_list=$(rcon-cli -c /home/steam/server/rcon.yaml "ShowPlayers")
echo -n "${player_list}" | wc -l
}
}

# 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_ENABLED,,}" = true ]; then
rcon-cli -c /home/steam/server/rcon.yaml save
else
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
if [ "${RCON_ENABLED,,}" = true ]; then
# Do not shutdown if not able to save
if save_server; then
rcon-cli -c /home/steam/server/rcon.yaml "shutdown 1"
else
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 @@ -18,10 +18,8 @@ term_handler() {
su steam -c "/home/steam/server/discord.sh '${DISCORD_PRE_SHUTDOWN_MESSAGE}' in-progress" &
fi

if [ "${RCON_ENABLED,,}" = true ]; then
rcon-cli save
rcon-cli "shutdown 1"
else # Does not save
if ! shutdown_server; then
# If it fails then kill the server
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 @@ -61,8 +61,7 @@ if [ -f "$BACKUP_FILE" ]; then

if [ "${RCON_ENABLED}" = true ]; then
printf "\e[0;32m*****SHUTDOWN SERVER*****\e[0m\n"
rcon-cli -c /home/steam/server/rcon.yaml save
rcon-cli -c /home/steam/server/rcon.yaml "shutdown 1"
shutdown_server
else
echo "RCON is not enabled. Please enable RCON to use this feature. Unable to restore backup."
exit 1
Expand Down
2 changes: 1 addition & 1 deletion scripts/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ if [ "$CURRENT_MANIFEST" != "$TARGET_MANIFEST" ]; then
sleep "${AUTO_UPDATE_WARN_MINUTES}m"
fi
backup
rcon-cli -c /home/steam/server/rcon.yaml "shutdown 1"
shutdown_server
else
echo "The Server is up to date!"
fi