feat(update): multi instance servers will reboot automatically on update (#2800)

This commit is contained in:
Daniel Gibbs 2020-04-06 21:31:22 +01:00 committed by GitHub
parent 390fc23265
commit ed536eade6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 83 additions and 38 deletions

View File

@ -0,0 +1,19 @@
#!/bin/bash
# LinuxGSM check_last_update.sh function
# Author: Daniel Gibbs
# Website: https://linuxgsm.com
# Description: Checks lock file to see when last update happened.
# Will reboot server if instance not rebooted since update.
if [ -f "${lockdir}/${selfname}-laststart.lock" ]; then
laststart=$(cat "${lockdir}/${selfname}-laststart.lock")
fi
if [ -f "${lockdir}/lastupdate.lock" ]; then
lastupdate=$(cat "${lockdir}/lastupdate.lock")
fi
if [ ! -f "${lockdir}/${selfname}-laststart.lock" ]||[ "${laststart}" -lt "${lastupdate}" ]; then
fn_print_info "${selfname} has not been restarted since last update"
fn_script_log_info "${selfname} has not been restarted since last update"
command_restart.sh
fi

View File

@ -22,13 +22,13 @@ fn_backup_trap(){
fn_print_removed_eol_nl
fn_script_log_info "Backup ${backupname}.tar.gz: REMOVED"
# Remove lock file.
rm -f "${tmpdir:?}/.backup.lock"
rm -f "${lockdir:?}/.backup.lock"
core_exit.sh
}
# Check if a backup is pending or has been aborted using .backup.lock.
fn_backup_check_lockfile(){
if [ -f "${tmpdir}/.backup.lock" ]; then
if [ -f "${lockdir}/.backup.lock" ]; then
fn_print_info_nl "Lock file found: Backup is currently running"
fn_script_log_error "Lock file found: Backup is currently running: ${tmpdir}/.backup.lock"
core_exit.sh
@ -115,9 +115,9 @@ fn_backup_migrate_olddir(){
fn_backup_create_lockfile(){
# Create lockfile.
date '+%s' > "${tmpdir}/.backup.lock"
date '+%s' > "${lockdir}/.backup.lock"
fn_script_log_info "Lockfile generated"
fn_script_log_info "${tmpdir}/.backup.lock"
fn_script_log_info "${lockdir}/.backup.lock"
# trap to remove lockfile on quit.
trap fn_backup_trap INT
}
@ -138,7 +138,7 @@ fn_backup_compression(){
core_exit.sh
fi
tar -czf "${backupdir}/${backupname}.tar.gz" -C "${rootdir}" --exclude "${excludedir}" --exclude "${tmpdir}/.backup.lock" ./.
tar -czf "${backupdir}/${backupname}.tar.gz" -C "${rootdir}" --exclude "${excludedir}" --exclude "${lockdir}/.backup.lock" ./.
local exitcode=$?
if [ ${exitcode} -ne 0 ]; then
fn_print_fail_eol
@ -152,7 +152,7 @@ fn_backup_compression(){
fn_script_log_pass "Backup created: ${backupname}.tar.gz, total size $(du -sh "${backupdir}/${backupname}.tar.gz" | awk '{print $1}')"
fi
# Remove lock file
rm -f "${tmpdir:?}/.backup.lock"
rm -f "${lockdir:?}/.backup.lock"
}
# Clear old backups according to maxbackups and maxbackupdays variables.

View File

@ -11,7 +11,7 @@ local function_selfname=$(basename "$(readlink -f "${BASH_SOURCE[0]}")")
# Trap to remove lockfile on quit.
fn_lockfile_trap(){
# Remove lockfile.
rm -f "${rootdir:?}/${lockselfname}"
rm -f "${lockdir:?}/${selfname}.lock"
# resets terminal. Servers can sometimes mess up the terminal on exit.
reset
fn_print_ok_nl "Closing debug"
@ -90,9 +90,9 @@ fn_script_log_info "Starting debug"
fn_print_ok_nl "Starting debug"
# Create lockfile.
date '+%s' > "${rootdir}/${lockselfname}"
date '+%s' > "${lockdir}/${selfname}.lock"
fn_script_log_info "Lockfile generated"
fn_script_log_info "${rootdir}/${lockselfname}"
fn_script_log_info "${lockdir}/${selfname}.lock"
# trap to remove lockfile on quit.
trap fn_lockfile_trap INT

View File

@ -12,7 +12,7 @@ local function_selfname=$(basename "$(readlink -f "${BASH_SOURCE[0]}")")
fn_monitor_check_lockfile(){
# Monitor does not run it lockfile is not found.
if [ ! -f "${rootdir}/${lockselfname}" ]; then
if [ ! -f "${lockdir}/${selfname}.lock" ]; then
fn_print_dots "Checking lockfile: "
fn_print_checking_eol
fn_script_log_info "Checking lockfile: CHECKING"
@ -26,8 +26,8 @@ fn_monitor_check_lockfile(){
fi
# Fix if lockfile is not unix time or contains letters
if [[ "$(cat "${rootdir}/${lockselfname}")" =~ [A-Za-z] ]]; then
date '+%s' > "${rootdir}/${lockselfname}"
if [[ "$(cat "${lockdir}/${selfname}.lock")" =~ [A-Za-z] ]]; then
date '+%s' > "${lockdir}/${selfname}.lock"
fi
}
@ -108,7 +108,7 @@ for queryattempt in {1..5}; do
fn_script_log_info "Querying port: ${querymethod}: ${ip}:${queryport} : ${queryattempt} : QUERYING"
fn_sleep_time
# querydelay
if [ "$(cat "${rootdir}/${lockselfname}")" -gt "$(date "+%s" -d "${querydelay} mins ago")" ]; then
if [ "$(cat "${lockdir}/${selfname}.lock")" -gt "$(date "+%s" -d "${querydelay} mins ago")" ]; then
fn_print_ok "Querying port: ${querymethod}: ${ip}:${queryport} : ${totalseconds}/${queryattempt}: "
fn_print_delay_eol_nl
fn_script_log_info "Querying port: ${querymethod}: ${ip}:${queryport} : ${queryattempt} : DELAY"
@ -236,6 +236,7 @@ info_parms.sh
# query pre-checks
fn_monitor_check_lockfile
check_last_update.sh
fn_monitor_check_update
fn_monitor_check_session
# Monitor will not continue if session only check.

View File

@ -62,13 +62,16 @@ fn_start_tmux(){
fi
# Create lockfile
date > "${rootdir}/${lockselfname}"
date > "${lockdir}/${selfname}.lock"
cd "${executabledir}" || exit
tmux new-session -d -x "${sessionwidth}" -y "${sessionheight}" -s "${selfname}" "${executable} ${parms}" 2> "${lgsmlogdir}/.${selfname}-tmux-error.tmp"
# Create logfile.
touch "${consolelog}"
# Create last start lock file
date +%s > "${lockdir}/${selfname}-laststart.lock"
# Get tmux version.
tmuxversion=$(tmux -V | sed "s/tmux //" | sed -n '1 p')
# Tmux compiled from source will return "master", therefore ignore it.

View File

@ -241,8 +241,8 @@ fn_print_dots "${servername}"
info_config.sh
fn_stop_pre_check
# Remove lockfile.
if [ -f "${rootdir}/${lockselfname}" ]; then
rm -f "${rootdir:?}/${lockselfname}"
if [ -f "${lockdir}/${selfname}.lock" ]; then
rm -f "${lockdir:?}/${selfname}.lock"
fi
if [ -z "${exitbypass}" ]; then

View File

@ -11,6 +11,7 @@ local function_selfname=$(basename "$(readlink -f "${BASH_SOURCE[0]}")")
fn_print_dots ""
check.sh
logs.sh
check_last_update.sh
if [ "${shortname}" == "ts3" ]; then
update_ts3.sh

View File

@ -188,6 +188,11 @@ functionfile="${FUNCNAME[0]}"
fn_fetch_function
}
check_last_update.sh(){
functionfile="${FUNCNAME[0]}"
fn_fetch_function
}
check_logs.sh(){
functionfile="${FUNCNAME[0]}"
fn_fetch_function
@ -701,6 +706,11 @@ if [ ! -d "${tmpdir}" ]; then
mkdir -p "${tmpdir}"
fi
# Creates lock dir if missing
if [ ! -d "${lockdir}" ]; then
mkdir -p "${lockdir}"
fi
# Calls on-screen messages (bootstrap)
core_messages.sh

View File

@ -41,8 +41,7 @@ if [ "$(find "${lgsmlogdir}"/ -type f -mtime +"${logdays}" | wc -l)" -ne "0" ];
# Setting up counting variables
scriptcount="0" ; consolecount="0" ; gamecount="0" ; srcdscount="0" ; smcount="0" ; ulxcount="0" ; darkrpcount="0" ; legacycount="0"
fn_sleep_time
fn_print_ok_nl "Starting"
fn_print_info_nl "Removing logs older than ${logdays} days"
fn_print_info "Removing logs older than ${logdays} days"
fn_script_log_info "Removing logs older than ${logdays} days"
# Logging logfiles to be removed according to "${logdays}", counting and removing them.
# Script logfiles.
@ -100,6 +99,6 @@ if [ "$(find "${lgsmlogdir}"/ -type f -mtime +"${logdays}" | wc -l)" -ne "0" ];
# Count total amount of files removed.
countlogs=$((scriptcount + consolecount + gamecount + srcdscount + smcount + ulxcount + darkrpcount))
# Job done.
fn_print_ok_nl "Removed ${countlogs} log files"
fn_print_ok "Removed ${countlogs} log files"
fn_script_log "Removed ${countlogs} log files"
fi

View File

@ -108,6 +108,7 @@ fn_update_factorio_compare(){
exitbypass=1
command_start.sh
fi
date +%s > "${lockdir}/lastupdate.lock"
alert="update"
alert.sh
else

View File

@ -167,6 +167,7 @@ fn_update_minecraft_compare(){
exitbypass=1
command_start.sh
fi
date +%s > "${lockdir}/lastupdate.lock"
alert="update"
alert.sh
else

View File

@ -133,6 +133,7 @@ fn_update_minecraft_compare(){
exitbypass=1
command_start.sh
fi
date +%s > "${lockdir}/lastupdate.lock"
alert="update"
alert.sh
else

View File

@ -165,6 +165,7 @@ fn_update_mta_compare(){
exitbypass=1
command_start.sh
fi
date +%s > "${lockdir}/lastupdate.lock"
alert="update"
alert.sh
else

View File

@ -101,6 +101,7 @@ fn_update_mumble_compare(){
exitbypass=1
command_start.sh
fi
date +%s > "${lockdir}/lastupdate.lock"
alert="update"
alert.sh
else

View File

@ -108,6 +108,7 @@ fn_update_steamcmd_compare(){
echo -e "* Branch: ${branch}"
fi
echo -e "https://steamdb.info/app/${appid}/"
echo -en "\n"
fn_script_log_info "Update available"
fn_script_log_info "Local build: ${localbuild}"
fn_script_log_info "Remote build: ${remotebuild}"
@ -128,9 +129,11 @@ fn_update_steamcmd_compare(){
command_stop.sh
exitbypass=1
fn_update_steamcmd_dl
date +%s > "${lockdir}/lastupdate.lock"
exitbypass=1
command_start.sh
fi
alert="update"
alert.sh
else
@ -143,6 +146,7 @@ fn_update_steamcmd_compare(){
echo -e "* Branch: ${branch}"
fi
echo -e "https://steamdb.info/app/${appid}/"
echo -en "\n"
fn_script_log_info "No update available"
fn_script_log_info "Local build: ${localbuild}"
fn_script_log_info "Remote build: ${remotebuild}"
@ -219,6 +223,7 @@ fn_stop_warning(){
# The location where the builds are checked and downloaded.
remotelocation="SteamCMD"
check.sh
if [ "${forceupdate}" == "1" ]; then
# forceupdate bypasses update checks.
check_status.sh
@ -227,10 +232,12 @@ if [ "${forceupdate}" == "1" ]; then
exitbypass=1
command_stop.sh
fn_update_steamcmd_dl
date +%s > "${lockdir}/lastupdate.lock"
exitbypass=1
command_start.sh
else
fn_update_steamcmd_dl
date +%s > "${lockdir}/lastupdate.lock"
fi
else
fn_print_dots "Checking for update"

View File

@ -1,7 +1,7 @@
#!/bin/bash
# Project: Game Server Managers - LinuxGSM
# Author: Daniel Gibbs
# License: MIT License, Copyright (c) 2019 Daniel Gibbs
# License: MIT License, Copyright (c) 2020 Daniel Gibbs
# Purpose: Linux Game Server Management Script
# Contributors: https://linuxgsm.com/contrib
# Documentation: https://docs.linuxgsm.com
@ -25,7 +25,6 @@ shortname="core"
gameservername="core"
rootdir=$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")
selfname=$(basename "$(readlink -f "${BASH_SOURCE[0]}")")
lockselfname=".${selfname}.lock"
lgsmdir="${rootdir}/lgsm"
logdir="${rootdir}/log"
lgsmlogdir="${logdir}/lgsm"
@ -34,6 +33,7 @@ serverfiles="${rootdir}/serverfiles"
functionsdir="${lgsmdir}/functions"
tmpdir="${lgsmdir}/tmp"
datadir="${lgsmdir}/data"
lockdir="${lgsmdir}/lock"
serverlist="${datadir}/serverlist.csv"
serverlistmenu="${datadir}/serverlistmenu.csv"
configdir="${lgsmdir}/config-lgsm"

View File

@ -1,7 +1,7 @@
#!/bin/bash
# Project: Game Server Managers - LinuxGSM
# Author: Daniel Gibbs
# License: MIT License, Copyright (c) 2019 Daniel Gibbs
# License: MIT License, Copyright (c) 2020 Daniel Gibbs
# Purpose: Travis CI Tests: Factorio | Linux Game Server Management Script
# Contributors: https://linuxgsm.com/contrib
# Documentation: https://docs.linuxgsm.com
@ -20,12 +20,11 @@ if [ -f ".dev-debug" ]; then
set -x
fi
version="v19.9.0"
version="v20.1.5"
shortname="fctr"
gameservername="fctrserver"
rootdir=$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")
selfname=$(basename "$(readlink -f "${BASH_SOURCE[0]}")")
lockselfname=".${selfname}.lock"
lgsmdir="${rootdir}/lgsm"
logdir="${rootdir}/log"
lgsmlogdir="${logdir}/lgsm"
@ -34,6 +33,7 @@ serverfiles="${rootdir}/serverfiles"
functionsdir="${lgsmdir}/functions"
tmpdir="${lgsmdir}/tmp"
datadir="${lgsmdir}/data"
lockdir="${lgsmdir}/lock"
serverlist="${datadir}/serverlist.csv"
serverlistmenu="${datadir}/serverlistmenu.csv"
configdir="${lgsmdir}/config-lgsm"
@ -812,7 +812,7 @@ echo -e "Command: ./${gameservername} monitor"
requiredstatus="OFFLINE"
fn_setstatus
fn_print_info_nl "creating lockfile."
date '+%s' > "${rootdir}/${lockselfname}"
date '+%s' > "${lockdir}/${selfname}.lock"
(
exec 5>"${TRAVIS_BUILD_DIR}/dev-debug.log"
BASH_XTRACEFD="5"

View File

@ -1,7 +1,7 @@
#!/bin/bash
# Project: Game Server Managers - LinuxGSM
# Author: Daniel Gibbs
# License: MIT License, Copyright (c) 2019 Daniel Gibbs
# License: MIT License, Copyright (c) 2020 Daniel Gibbs
# Purpose: Travis CI Tests: Just Cause 2 | Linux Game Server Management Script
# Contributors: https://linuxgsm.com/contrib
# Documentation: https://docs.linuxgsm.com
@ -20,12 +20,11 @@ if [ -f ".dev-debug" ]; then
set -x
fi
version="v19.9.0"
version="v20.1.5"
shortname="jc2"
gameservername="jc2server"
rootdir=$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")
selfname=$(basename "$(readlink -f "${BASH_SOURCE[0]}")")
lockselfname=".${selfname}.lock"
lgsmdir="${rootdir}/lgsm"
logdir="${rootdir}/log"
lgsmlogdir="${logdir}/lgsm"
@ -34,6 +33,7 @@ serverfiles="${rootdir}/serverfiles"
functionsdir="${lgsmdir}/functions"
tmpdir="${lgsmdir}/tmp"
datadir="${lgsmdir}/data"
lockdir="${lgsmdir}/lock"
serverlist="${datadir}/serverlist.csv"
serverlistmenu="${datadir}/serverlistmenu.csv"
configdir="${lgsmdir}/config-lgsm"
@ -966,7 +966,7 @@ echo -e "Command: ./${gameservername} monitor"
requiredstatus="OFFLINE"
fn_setstatus
fn_print_info_nl "creating lockfile."
date '+%s' > "${rootdir}/${lockselfname}"
date '+%s' > "${lockdir}/${selfname}.lock"
(
exec 5>"${TRAVIS_BUILD_DIR}/dev-debug.log"
BASH_XTRACEFD="5"

View File

@ -1,7 +1,7 @@
#!/bin/bash
# Project: Game Server Managers - LinuxGSM
# Author: Daniel Gibbs
# License: MIT License, Copyright (c) 2019 Daniel Gibbs
# License: MIT License, Copyright (c) 2020 Daniel Gibbs
# Purpose: Travis CI Tests: Minecraft | Linux Game Server Management Script
# Contributors: https://linuxgsm.com/contrib
# Documentation: https://docs.linuxgsm.com
@ -20,12 +20,11 @@ if [ -f ".dev-debug" ]; then
set -x
fi
version="v19.9.0"
version="v20.1.5"
shortname="mc"
gameservername="mcserver"
rootdir=$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")
selfname=$(basename "$(readlink -f "${BASH_SOURCE[0]}")")
lockselfname=".${selfname}.lock"
lgsmdir="${rootdir}/lgsm"
logdir="${rootdir}/log"
lgsmlogdir="${logdir}/lgsm"
@ -34,6 +33,7 @@ serverfiles="${rootdir}/serverfiles"
functionsdir="${lgsmdir}/functions"
tmpdir="${lgsmdir}/tmp"
datadir="${lgsmdir}/data"
lockdir="${lgsmdir}/lock"
serverlist="${datadir}/serverlist.csv"
serverlistmenu="${datadir}/serverlistmenu.csv"
configdir="${lgsmdir}/config-lgsm"
@ -845,7 +845,7 @@ echo -e "Command: ./${gameservername} monitor"
requiredstatus="OFFLINE"
fn_setstatus
fn_print_info_nl "creating lockfile."
date '+%s' > "${rootdir}/${lockselfname}"
date '+%s' > "${lockdir}/${selfname}.lock"
(
exec 5>"${TRAVIS_BUILD_DIR}/dev-debug.log"
BASH_XTRACEFD="5"

View File

@ -1,7 +1,7 @@
#!/bin/bash
# Project: Game Server Managers - LinuxGSM
# Author: Daniel Gibbs
# License: MIT License, Copyright (c) 2019 Daniel Gibbs
# License: MIT License, Copyright (c) 2020 Daniel Gibbs
# Purpose: Travis CI Tests: Shellcheck | Linux Game Server Management Script
# Contributors: https://github.com/GameServerManagers/LinuxGSM/graphs/contributors
# Documentation: https://docs.linuxgsm.com/

View File

@ -1,7 +1,7 @@
#!/bin/bash
# Project: Game Server Managers - LinuxGSM
# Author: Daniel Gibbs
# License: MIT License, Copyright (c) 2019 Daniel Gibbs
# License: MIT License, Copyright (c) 2020 Daniel Gibbs
# Purpose: Travis CI Tests: Teamspeak 3 | Linux Game Server Management Script
# Contributors: https://linuxgsm.com/contrib
# Documentation: https://docs.linuxgsm.com
@ -20,12 +20,11 @@ if [ -f ".dev-debug" ]; then
set -x
fi
version="v19.9.0"
version="v20.1.5"
shortname="ts3"
gameservername="ts3server"
rootdir=$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")
selfname=$(basename "$(readlink -f "${BASH_SOURCE[0]}")")
lockselfname=".${selfname}.lock"
lgsmdir="${rootdir}/lgsm"
logdir="${rootdir}/log"
lgsmlogdir="${logdir}/lgsm"
@ -34,6 +33,7 @@ serverfiles="${rootdir}/serverfiles"
functionsdir="${lgsmdir}/functions"
tmpdir="${lgsmdir}/tmp"
datadir="${lgsmdir}/data"
lockdir="${lgsmdir}/lock"
serverlist="${datadir}/serverlist.csv"
serverlistmenu="${datadir}/serverlistmenu.csv"
configdir="${lgsmdir}/config-lgsm"
@ -812,7 +812,7 @@ echo -e "Command: ./${gameservername} monitor"
requiredstatus="OFFLINE"
fn_setstatus
fn_print_info_nl "creating lockfile."
date '+%s' > "${rootdir}/${lockselfname}"
date '+%s' > "${lockdir}/${selfname}.lock"
(
exec 5>"${TRAVIS_BUILD_DIR}/dev-debug.log"
BASH_XTRACEFD="5"