Added support for xmllint on start to avoid issues with silent errors
This commit is contained in:
parent
bce8f095fd
commit
eb393896ac
@ -1,6 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
|
||||
echo_rgb() {
|
||||
# Echo a colored string to the terminal based on rgb values
|
||||
#
|
||||
@ -221,9 +220,8 @@ start_server() {
|
||||
|
||||
backup_configs "${server_directory}"
|
||||
|
||||
|
||||
local server_port
|
||||
server_port="$(( START_PORT_RANGE + server_id ))"
|
||||
server_port="$((START_PORT_RANGE + server_id))"
|
||||
|
||||
log "info" "Generating a few required directories in $(important "${server_directory}")"
|
||||
mkdir -p "${server_save_dir}"
|
||||
@ -249,25 +247,37 @@ start_server() {
|
||||
else
|
||||
printf "%s\n" "${REPLY}"
|
||||
fi
|
||||
done < "${server_config}" > "temp-serverconfig.xml"
|
||||
done <"${server_config}" >"temp-serverconfig.xml"
|
||||
|
||||
# Occasionally the closing tag in serverconfig.xml will be missing, this ensures it is there in that scenario
|
||||
if [[ ! "$(tail "temp-serverconfig.xml" -n 1 )" = *"ServerSettings"* ]]; then
|
||||
printf "</ServerSettings>\n" >> "temp-serverconfig.xml"
|
||||
if [[ ! "$(tail "temp-serverconfig.xml" -n 1)" = *"ServerSettings"* ]]; then
|
||||
printf "</ServerSettings>\n" >>"temp-serverconfig.xml"
|
||||
fi
|
||||
|
||||
mv "temp-serverconfig.xml" "${server_config}"
|
||||
|
||||
# xmllint, helps avoiding the random server launch failures for apparently no reason
|
||||
if which xmllint >/dev/null 2>&1; then
|
||||
for xml_file in "${server_directory}"/*.xml; do
|
||||
log "info" "Linting $(important "${xml_file}")..."
|
||||
if ! xmllint "${xml_file}" > /dev/null; then
|
||||
log "error" "Xml parsing error in ${xml_file}, resolve the error and attempt to start again"
|
||||
fi
|
||||
done
|
||||
else
|
||||
log "warning" "$(important "xmllint") not installed or not in PATH, skipping lint check"
|
||||
fi
|
||||
|
||||
log "info" "Starting $(important "${server_name}") located at $(important "${server_directory}") on port $(important "${server_port}")"
|
||||
|
||||
if tmux has-session -t "${server_session_name}" >/dev/null 2>&1; then
|
||||
log "warning" "$(important "${server_name}") is currently running"
|
||||
|
||||
if (( can_kill == 0 )); then
|
||||
if ((can_kill == 0)); then
|
||||
log "info" "Been explicitly permitted to kill, bypassing confirmation"
|
||||
kill_server -s "${server_id}"
|
||||
else
|
||||
if confirmation "Would you like to kill $(important "${server_name}")? (Y/n)" ; then
|
||||
if confirmation "Would you like to kill $(important "${server_name}")? (Y/n)"; then
|
||||
log "info" "Given answer $(important "yes") to kill the server, killing $(important "${server_name}")"
|
||||
kill_server -s "${server_id}"
|
||||
else
|
||||
@ -280,7 +290,7 @@ start_server() {
|
||||
log "info" "Creating new session for $(important "${server_name}") as session $(important "${server_session_name}")"
|
||||
tmux new-session -d -s "${server_session_name}"
|
||||
tmux send-keys \
|
||||
"until ${server_directory}/startserver.sh -configfile=${server_directory}/serverconfig.xml; do
|
||||
"until ${server_directory}/startserver.sh -configfile=${server_directory}/serverconfig.xml; do
|
||||
echo 'Server died with code $?, restarting in 60 seconds...' >&2
|
||||
sleep 60;
|
||||
done" C-m
|
||||
@ -408,7 +418,7 @@ update() {
|
||||
case ${1} in
|
||||
-h | -\? | --help)
|
||||
printf "Usage: %s\n" \
|
||||
"update [OPTIONS]
|
||||
"update [OPTIONS]
|
||||
--server <server id: int> | -s <server id: int>
|
||||
Updates the given server id
|
||||
|
||||
@ -478,7 +488,7 @@ backup() {
|
||||
case ${1} in
|
||||
-h | -\? | --help)
|
||||
printf "Usage: %s\n" \
|
||||
"backup [OPTIONS]
|
||||
"backup [OPTIONS]
|
||||
--server <server id: int> | -s <server id: int>
|
||||
Backups the given server id
|
||||
|
||||
@ -506,7 +516,6 @@ backup() {
|
||||
|
||||
[[ -z "${server_id}" ]] && log "error" "No server id passed" && exit 1
|
||||
|
||||
|
||||
# Kill the server to ensure a smooth backup
|
||||
kill_server -s "${server_id}" >/dev/null 2>&1
|
||||
|
||||
@ -525,11 +534,11 @@ backup() {
|
||||
mkdir -p "${backup_dir}"
|
||||
|
||||
# Do a check if pv is there, pv is used for showing progress
|
||||
if which pv > /dev/null 2>&1; then
|
||||
tar cf - "${server_directory}" -P 2> /dev/null | pv -s "$(du -sb "${server_directory}" | awk '{print $1}')" | gzip > "${backup_full_path}"
|
||||
if which pv >/dev/null 2>&1; then
|
||||
tar cf - "${server_directory}" -P 2>/dev/null | pv -s "$(du -sb "${server_directory}" | awk '{print $1}')" | gzip >"${backup_full_path}"
|
||||
else
|
||||
log "info" "$(important "pv") not installed, not showing progress..."
|
||||
tar czf "${server_directory}" "${backup_full_path}" 2> /dev/null
|
||||
tar czf "${server_directory}" "${backup_full_path}" 2>/dev/null
|
||||
fi
|
||||
}
|
||||
|
||||
@ -540,7 +549,7 @@ list_servers() {
|
||||
case ${1} in
|
||||
-h | -\? | --help)
|
||||
printf "Usage: %s\n" \
|
||||
"list [OPTIONS]
|
||||
"list [OPTIONS]
|
||||
--running | -r
|
||||
Lists the currently running 7 Days To Die Servers
|
||||
|
||||
@ -576,7 +585,7 @@ list_servers() {
|
||||
log "error" "An option must be passed for list, check list -h" &&
|
||||
return 1
|
||||
|
||||
if (( picked_option == 0 )); then
|
||||
if ((picked_option == 0)); then
|
||||
log "debug" "Listing running servers"
|
||||
local tmux_sessions
|
||||
tmux_sessions="$(tmux list-sessions)" >/dev/null 2>&1
|
||||
@ -589,12 +598,12 @@ list_servers() {
|
||||
running_server="$(echo "${REPLY}" | cut -d ":" -f1)"
|
||||
important "${running_server}"
|
||||
fi
|
||||
done <<< "${tmux_sessions}"
|
||||
elif (( picked_option == 1 )); then
|
||||
done <<<"${tmux_sessions}"
|
||||
elif ((picked_option == 1)); then
|
||||
log "debug" "Listing installed servers"
|
||||
while read -r; do
|
||||
important "${BASE_DIR}/${REPLY}"
|
||||
done <<< "$(find "${BASE_DIR}" -name "startserver.sh" | cut -d "/" -f5)"
|
||||
done <<<"$(find "${BASE_DIR}" -name "startserver.sh" | cut -d "/" -f5)"
|
||||
fi
|
||||
}
|
||||
|
||||
@ -626,7 +635,6 @@ usage() {
|
||||
Exposes options to backup 7 Days To Die Servers, pass -h to it for details"
|
||||
}
|
||||
|
||||
|
||||
main() {
|
||||
# Parse input arguments
|
||||
#
|
||||
|
Loading…
Reference in New Issue
Block a user