Browse Source

refactor: improve lockfile checking and add backup and debug mode checks

The code changes refactor the `fn_monitor_check_lockfile` function to include additional checks for backup and debug modes. The new functions `fn_monitor_check_backup` and `fn_monitor_check_debug` are added to handle these checks. Additionally, the `fn_monitor_check_install` function is introduced to check if an installation is currently running. The existing check for active updates in the `fn_monitor_check_update` function is also improved.

These changes enhance the monitoring functionality by providing more comprehensive checks for different scenarios, ensuring that the monitor does not run when certain conditions are met.
pull/4257/head
Daniel Gibbs 2 years ago
parent
commit
9d699ee36d
  1. 6
      lgsm/functions/core_steamcmd.sh
  2. 60
      lgsm/modules/command_monitor.sh

6
lgsm/functions/core_steamcmd.sh

@ -32,10 +32,14 @@ fn_check_steamcmd_user() {
# Anonymous user is set if steamuser is missing.
if [ -z "${steamuser}" ]; then
if [ -d "${lgsmlogdir}" ]; then
fn_script_log_info "Using anonymous Steam login"
fn_script_log_info "Login to SteamCMD as: anonymous"
fi
steamuser="anonymous"
steampass=''
else
if [ -d "${lgsmlogdir}" ]; then
fn_script_log_info "Login to SteamCMD as: ${steamuser}"
fi
fi
}

60
lgsm/modules/command_monitor.sh

@ -12,11 +12,14 @@ moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
fn_firstcommand_set
fn_monitor_check_lockfile() {
# Monitor does not run it lockfile is not found.
# Monitor does not run if lockfile is not found.
if [ ! -f "${lockdir}/${selfname}.lock" ]; then
fn_print_dots "Checking lockfile: "
fn_print_checking_eol
fn_script_log_info "Checking lockfile: CHECKING"
fn_monitor_check_update
fn_monitor_check_backup
fn_monitor_check_debug
fn_print_error "Checking lockfile: No lockfile found: "
fn_print_error_eol_nl
fn_script_log_error "Checking lockfile: No lockfile found: ERROR"
@ -32,19 +35,55 @@ fn_monitor_check_lockfile() {
fi
}
fn_monitor_check_update() {
# Monitor will check if update is already running.
if [ "$(pgrep "${selfname} update" | wc -l)" != "0" ]; then
fn_print_dots "Checking active updates: "
fn_monitor_check_backup() {
# Monitor will check if backup is running.
if [ "$(pgrep "${selfname} backup" | wc -l)" != "0" ] || [ "$(pgrep "${selfname} b" | wc -l)" != "0" ]; then
fn_print_info_nl "Checking lockfile: LinuxGSM is currently running a backup: "
fn_print_info_eol
fn_script_log_info "Checking lockfile: LinuxGSM is currently running a backup"
core_exit.sh
fi
}
fn_monitor_check_debug() {
# Monitor will check if backup is running.
if [ "$(pgrep -fc "${selfname} backup")" != "0" ] || [ "$(pgrep -fc "${selfname} b")" != "0" ]; then
fn_print_info_nl "Checking lockfile: LinuxGSM is currently in debug mode: "
fn_print_info_eol
fn_script_log_pass "Checking lockfile: LinuxGSM is currently in debug mode"
core_exit.sh
fi
}
fn_monitor_check_install() {
# Monitor will check if update is running.
if [ "$(pgrep -fc "${selfname} install")" != "0" ] || [ "$(pgrep -fc "${selfname} i")" != "0" ] || [ "$(pgrep -fc "${selfname} auto-install")" != "0" ] || [ "$(pgrep -fc "${selfname} ai")" != "0" ]; then
fn_print_dots "Checking for installer: "
fn_print_checking_eol
fn_script_log_info "Checking active updates: CHECKING"
fn_print_error_nl "Checking active updates: SteamCMD is currently checking for updates: "
fn_print_error_eol
fn_script_log_error "Checking active updates: SteamCMD is currently checking for updates: ERROR"
fn_script_log_info "Checking for installer: CHECKING"
fn_print_info_nl "Checking for installer: LinuxGSM is currently installing: "
fn_print_info_eol
fn_script_log_pass "Checking for installer: LinuxGSM is currently installing"
core_exit.sh
fi
}
fn_monitor_check_update() {
# Monitor will check if an update is running.
if [ "$(pgrep -fc "${selfname} update")" != "0" ] || [ "$(pgrep -fc "${selfname} u")" != "0" ] || [ "$(pgrep -fc "${selfname} validate")" != "0" ] || [ "$(pgrep -fc "${selfname} v")" != "0" ]; then
# Specific check for docker. Will ignore the command watch -n 1800 ./csgoserver update
if [ "$(pgrep -fc "n*${selfname} update")" != "0" ]; then
fn_print_dots "Checking active updates: "
fn_print_checking_eol
fn_script_log_info "Checking active updates: CHECKING"
fn_print_info_nl "Checking active updates: SteamCMD is currently checking for updates: "
fn_print_info_eol
fn_script_log_pass "Checking active updates: SteamCMD is currently checking for updates"
core_exit.sh
fi
fi
}
fn_monitor_check_session() {
fn_print_dots "Checking session: "
fn_print_checking_eol
@ -223,13 +262,14 @@ fn_monitor_loop() {
}
monitorflag=1
# Dont do any monitoring or checks if installer is running.
fn_monitor_check_install
check.sh
core_logs.sh
info_game.sh
# query pre-checks
fn_monitor_check_lockfile
fn_monitor_check_update
fn_monitor_check_session
# Monitor will not continue if session only check.
if [ "${querymode}" != "1" ]; then

Loading…
Cancel
Save