Skip to content

Commit 8cd16ac

Browse files
committed
fix: make pgrep unique
- Refactored the code to use `pgrep -fcx` instead of `pgrep -fc` for checking process counts. - Updated print statements to provide more informative messages. - Renamed some variables for clarity. - Added newlines after printing information.
1 parent 20f5e8d commit 8cd16ac

File tree

1 file changed

+34
-34
lines changed

1 file changed

+34
-34
lines changed

lgsm/modules/command_monitor.sh

+34-34
Original file line numberDiff line numberDiff line change
@@ -26,69 +26,69 @@ fn_monitor_check_monitoring() {
2626
}
2727

2828
fn_monitor_check_install() {
29-
if [ "$(pgrep -fc -u "${USER}" "${selfname} install")" != "0" ] || [ "$(pgrep -fc -u "${USER}" "${selfname} i")" != "0" ] || [ "$(pgrep -fc -u "${USER}" "${selfname} auto-install")" != "0" ] || [ "$(pgrep -fc -u "${USER}" "${selfname} ai")" != "0" ]; then
29+
if [ "$(pgrep -fc -u "${USER}" "/bin/bash ./${selfname} install")" != "0" ] || [ "$(pgrep -fcx -u "${USER}" "/bin/bash ./${selfname} i")" != "0" ] || [ "$(pgrep -fcx -u "${USER}" "/bin/bash ./${selfname} auto-install")" != "0" ] || [ "$(pgrep -fcx -u "${USER}" "/bin/bash ./${selfname} ai")" != "0" ]; then
3030
fn_print_dots "Checking installer: "
3131
fn_print_checking_eol
3232
fn_script_log_info "Checking installer: CHECKING"
33-
fn_print_info "Checking installer: Installer is : "
34-
fn_print_info_eol
33+
fn_print_info "Checking installer: LinuxGSM is installing: "
34+
fn_print_info_eol_nl
3535
fn_script_log_pass "Checking installer: LinuxGSM is installing"
3636
core_exit.sh
3737
fi
3838
}
3939

4040
fn_monitor_check_debug() {
41-
if [ "$(pgrep -fc -u "${USER}" "${selfname} debug")" != "0" ] || [ "$(pgrep -fc -u "${USER}" "${selfname} d")" != "0" ]; then
41+
if [ "$(pgrep -fcx -u "${USER}" "/bin/bash ./${selfname} debug")" != "0" ] || [ "$(pgrep -fcx -u "${USER}" "/bin/bash ./${selfname} d")" != "0" ]; then
4242
fn_print_dots "Checking debug: "
4343
fn_print_checking_eol
4444
fn_print_info "Checking debug: Debug is running: "
45-
fn_print_info_eol
45+
fn_print_info_eol_nl
4646
fn_script_log_pass "Checking debug: Debug is running"
4747
core_exit.sh
4848
fi
4949
}
5050

51-
fn_monitor_check_starting(){
51+
fn_monitor_check_starting() {
5252
# Remove stale lockfile.
5353
if [ -f "${lockdir}/${selfname}-starting.lock" ]; then
5454
if [ "$(find "${lockdir}/${selfname}-starting.lock" -mmin +5)" ]; then
5555
fn_print_dots "Checking start: "
5656
fn_print_checking_eol
5757
fn_print_warn "Checking start: Removing stale lockfile: "
58-
fn_print_warn_eol
58+
fn_print_warn_eol_nl
5959
fn_script_log_warn "Checking start: Removing stale lockfile"
6060
rm -f "${lockdir:?}/${selfname}-starting.lock"
6161
fi
6262
fi
6363

64-
if [ -f "${lockdir}/${selfname}-starting.lock" ] && [[ "$(pgrep -fc -u "${USER}" "${selfname} start")" != "0" || "$(pgrep -fc -u "${USER}" "${selfname} s")" != "0" ]]; then
64+
if [ -f "${lockdir}/${selfname}-starting.lock" ] && [[ "$(pgrep -fcx -u "${USER}" "/bin/bash ./${selfname} start")" != "0" || "$(pgrep -fcx -u "${USER}" "/bin/bash ./${selfname} s")" != "0" ]]; then
6565
fn_print_dots "Checking start: "
6666
fn_print_checking_eol
6767
fn_print_info "Checking start: LinuxGSM is starting: "
68-
fn_print_info_eol
68+
fn_print_info_eol_nl
6969
fn_script_log_info "Checking backup: LinuxGSM is starting"
7070
core_exit.sh
7171
fi
7272
}
7373

74-
fn_monitor_check_stopping(){
74+
fn_monitor_check_stopping() {
7575
# Remove stale lockfile.
7676
if [ -f "${lockdir}/${selfname}-stopping.lock" ]; then
7777
if [ "$(find "${lockdir}/${selfname}-stopping.lock" -mmin +5)" ]; then
7878
fn_print_dots "Checking stop: "
7979
fn_print_checking_eol
8080
fn_print_warn "Checking stop: Removing stale lockfile: "
81-
fn_print_warn_eol
81+
fn_print_warn_eol_nl
8282
fn_script_log_warn "Checking stop: Removing stale lockfile"
8383
rm -f "${lockdir:?}/${selfname}-stopping.lock"
8484
fi
8585
fi
8686

87-
if [ -f "${lockdir}/${selfname}-stopping.lock" ] && [[ "$(pgrep -fc -u "${USER}" "${selfname} stop")" != "0" || "$(pgrep -fc -u "${USER}" "${selfname} s")" != "0" ]]; then
87+
if [ -f "${lockdir}/${selfname}-stopping.lock" ] && [[ "$(pgrep -fcx -u "${USER}" "/bin/bash ./${selfname} stop")" != "0" || "$(pgrep -fcx -u "${USER}" "/bin/bash ./${selfname} s")" != "0" ]]; then
8888
fn_print_dots "Checking stop: "
8989
fn_print_checking_eol
9090
fn_print_info "Checking stop: LinuxGSM is stopping: "
91-
fn_print_info_eol
91+
fn_print_info_eol_nl
9292
fn_script_log_info "Checking backup: LinuxGSM is stopping"
9393
core_exit.sh
9494
fi
@@ -107,11 +107,11 @@ fn_monitor_check_backup() {
107107
fi
108108
fi
109109

110-
if [ -f "${lockdir}/backup.lock" ] && [[ "$(pgrep -fc -u "${USER}" "${selfname} backup")" != "0" || "$(pgrep -fc -u "${USER}" "${selfname} b")" != "0" ]]; then
110+
if [ -f "${lockdir}/backup.lock" ] && [[ "$(pgrep -fcx -u "${USER}" "/bin/bash ./${selfname} backup")" != "0" || "$(pgrep -fcx -u "${USER}" "/bin/bash ./${selfname} b")" != "0" ]]; then
111111
fn_print_dots "Checking backup: "
112112
fn_print_checking_eol
113113
fn_print_info "Checking backup: Backup is running: "
114-
fn_print_info_eol
114+
fn_print_info_eol_nl
115115
fn_script_log_info "Checking backup: Backup is running"
116116
core_exit.sh
117117
fi
@@ -124,38 +124,38 @@ fn_monitor_check_update() {
124124
fn_print_dots "Checking update: "
125125
fn_print_checking_eol
126126
fn_print_warn "Checking update: Removing stale lockfile: "
127-
fn_print_warn_eol
127+
fn_print_warn_eol_nl
128128
fn_script_log_warn "Checking update: Removing stale lockfile"
129129
rm -f "${lockdir:?}/update.lock"
130130
fi
131131
fi
132132

133-
if [ -f "${lockdir}/update.lock" ] && [[ "$(pgrep -fc -u "${USER}" "${selfname} update")" != "0" || "$(pgrep -fc -u "${USER}" "${selfname} validate")" != "0" || "$(pgrep -fc -u "${USER}" "${selfname} v")" != "0" || "$(pgrep -fc force-update "${USER}" "${selfname} fu")" != "0" ]]; then
133+
if [ -f "${lockdir}/update.lock" ] && [[ "$(pgrep -fcx -u "${USER}" "/bin/bash ./${selfname} update")" != "0" || "$(pgrep -fcx -u "${USER}" "/bin/bash ./${selfname} validate")" != "0" || "$(pgrep -fcx -u "${USER}" "/bin/bash ./${selfname} v")" != "0" || "$(pgrep -fc force-update "${USER}" "/bin/bash ./${selfname} fu")" != "0" ]]; then
134134
fn_print_dots "Checking update: "
135135
fn_print_checking_eol
136136
fn_print_info "Checking update: LinuxGSM is updating the game server: "
137-
fn_print_info_eol
137+
fn_print_info_eol_nl
138138
fn_script_log_pass "Checking update: LinuxGSM is updating the game server"
139139
core_exit.sh
140140
fi
141141
}
142142

143143
# Source engine games may display a messages to indicate the server needs restarting.
144-
fn_monitor_check_update_source(){
145-
if [ -f "${consolelogdir}/${selfname}-console.log" ] && [ "${engine}" == "source" ]; then
146-
if grep -q "Your server needs to be restarted in order to receive the latest update." "${consolelogdir}/${selfname}-console.log"; then
147-
fn_print_dots "Checking update: "
148-
fn_print_checking_eol
149-
fn_script_log_info "Checking update: CHECKING"
150-
fn_print_ok "Checking update: "
151-
fn_print_ok_eol_nl
152-
fn_script_log_info "Checking update: Monitor is restarting ${selfname} to apply update"
153-
alert="restart"
154-
alert.sh
155-
command_restart.sh
156-
core_exit.sh
157-
fi
158-
fi
144+
fn_monitor_check_update_source() {
145+
if [ -f "${consolelogdir}/${selfname}-console.log" ] && [ "${engine}" == "source" ]; then
146+
if grep -q "Your server needs to be restarted in order to receive the latest update." "${consolelogdir}/${selfname}-console.log"; then
147+
fn_print_dots "Checking update: "
148+
fn_print_checking_eol
149+
fn_script_log_info "Checking update: CHECKING"
150+
fn_print_ok "Checking update: "
151+
fn_print_ok_eol_nl
152+
fn_script_log_info "Checking update: Monitor is restarting ${selfname} to apply update"
153+
alert="restart"
154+
alert.sh
155+
command_restart.sh
156+
core_exit.sh
157+
fi
158+
fi
159159
}
160160

161161
fn_monitor_check_session() {
@@ -166,7 +166,7 @@ fn_monitor_check_session() {
166166
sessionwidth="80"
167167
sessionheight="23"
168168
# Check for PIDS with identical tmux sessions running.
169-
if [ "$(pgrep -fc "tmux -L ${socketname} new-session -d -x ${sessionwidth} -y ${sessionheight} -s ${sessionname}")" -ge "2" ]; then
169+
if [ "$(pgrep -fcx "tmux -L ${socketname} new-session -d -x ${sessionwidth} -y ${sessionheight} -s ${sessionname}")" -ge "2" ]; then
170170
fn_print_error "Checking session: "
171171
fn_print_error_eol_nl
172172
fn_script_log_error "Checking session: ERROR"

0 commit comments

Comments
 (0)