Skip to content

Commit 9d699ee

Browse files
committed
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.
1 parent a9a0744 commit 9d699ee

File tree

2 files changed

+55
-11
lines changed

2 files changed

+55
-11
lines changed

lgsm/functions/core_steamcmd.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,14 @@ fn_check_steamcmd_user() {
3232
# Anonymous user is set if steamuser is missing.
3333
if [ -z "${steamuser}" ]; then
3434
if [ -d "${lgsmlogdir}" ]; then
35-
fn_script_log_info "Using anonymous Steam login"
35+
fn_script_log_info "Login to SteamCMD as: anonymous"
3636
fi
3737
steamuser="anonymous"
3838
steampass=''
39+
else
40+
if [ -d "${lgsmlogdir}" ]; then
41+
fn_script_log_info "Login to SteamCMD as: ${steamuser}"
42+
fi
3943
fi
4044
}
4145

lgsm/modules/command_monitor.sh

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@ moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
1212
fn_firstcommand_set
1313

1414
fn_monitor_check_lockfile() {
15-
# Monitor does not run it lockfile is not found.
15+
# Monitor does not run if lockfile is not found.
1616
if [ ! -f "${lockdir}/${selfname}.lock" ]; then
1717
fn_print_dots "Checking lockfile: "
1818
fn_print_checking_eol
1919
fn_script_log_info "Checking lockfile: CHECKING"
20+
fn_monitor_check_update
21+
fn_monitor_check_backup
22+
fn_monitor_check_debug
2023
fn_print_error "Checking lockfile: No lockfile found: "
2124
fn_print_error_eol_nl
2225
fn_script_log_error "Checking lockfile: No lockfile found: ERROR"
@@ -32,19 +35,55 @@ fn_monitor_check_lockfile() {
3235
fi
3336
}
3437

35-
fn_monitor_check_update() {
36-
# Monitor will check if update is already running.
37-
if [ "$(pgrep "${selfname} update" | wc -l)" != "0" ]; then
38-
fn_print_dots "Checking active updates: "
38+
fn_monitor_check_backup() {
39+
# Monitor will check if backup is running.
40+
if [ "$(pgrep "${selfname} backup" | wc -l)" != "0" ] || [ "$(pgrep "${selfname} b" | wc -l)" != "0" ]; then
41+
fn_print_info_nl "Checking lockfile: LinuxGSM is currently running a backup: "
42+
fn_print_info_eol
43+
fn_script_log_info "Checking lockfile: LinuxGSM is currently running a backup"
44+
core_exit.sh
45+
fi
46+
}
47+
48+
fn_monitor_check_debug() {
49+
# Monitor will check if backup is running.
50+
if [ "$(pgrep -fc "${selfname} backup")" != "0" ] || [ "$(pgrep -fc "${selfname} b")" != "0" ]; then
51+
fn_print_info_nl "Checking lockfile: LinuxGSM is currently in debug mode: "
52+
fn_print_info_eol
53+
fn_script_log_pass "Checking lockfile: LinuxGSM is currently in debug mode"
54+
core_exit.sh
55+
fi
56+
}
57+
58+
fn_monitor_check_install() {
59+
# Monitor will check if update is running.
60+
if [ "$(pgrep -fc "${selfname} install")" != "0" ] || [ "$(pgrep -fc "${selfname} i")" != "0" ] || [ "$(pgrep -fc "${selfname} auto-install")" != "0" ] || [ "$(pgrep -fc "${selfname} ai")" != "0" ]; then
61+
fn_print_dots "Checking for installer: "
3962
fn_print_checking_eol
40-
fn_script_log_info "Checking active updates: CHECKING"
41-
fn_print_error_nl "Checking active updates: SteamCMD is currently checking for updates: "
42-
fn_print_error_eol
43-
fn_script_log_error "Checking active updates: SteamCMD is currently checking for updates: ERROR"
63+
fn_script_log_info "Checking for installer: CHECKING"
64+
fn_print_info_nl "Checking for installer: LinuxGSM is currently installing: "
65+
fn_print_info_eol
66+
fn_script_log_pass "Checking for installer: LinuxGSM is currently installing"
4467
core_exit.sh
4568
fi
4669
}
4770

71+
fn_monitor_check_update() {
72+
# Monitor will check if an update is running.
73+
if [ "$(pgrep -fc "${selfname} update")" != "0" ] || [ "$(pgrep -fc "${selfname} u")" != "0" ] || [ "$(pgrep -fc "${selfname} validate")" != "0" ] || [ "$(pgrep -fc "${selfname} v")" != "0" ]; then
74+
# Specific check for docker. Will ignore the command watch -n 1800 ./csgoserver update
75+
if [ "$(pgrep -fc "n*${selfname} update")" != "0" ]; then
76+
fn_print_dots "Checking active updates: "
77+
fn_print_checking_eol
78+
fn_script_log_info "Checking active updates: CHECKING"
79+
fn_print_info_nl "Checking active updates: SteamCMD is currently checking for updates: "
80+
fn_print_info_eol
81+
fn_script_log_pass "Checking active updates: SteamCMD is currently checking for updates"
82+
core_exit.sh
83+
fi
84+
fi
85+
}
86+
4887
fn_monitor_check_session() {
4988
fn_print_dots "Checking session: "
5089
fn_print_checking_eol
@@ -223,13 +262,14 @@ fn_monitor_loop() {
223262
}
224263

225264
monitorflag=1
265+
# Dont do any monitoring or checks if installer is running.
266+
fn_monitor_check_install
226267
check.sh
227268
core_logs.sh
228269
info_game.sh
229270

230271
# query pre-checks
231272
fn_monitor_check_lockfile
232-
fn_monitor_check_update
233273
fn_monitor_check_session
234274
# Monitor will not continue if session only check.
235275
if [ "${querymode}" != "1" ]; then

0 commit comments

Comments
 (0)