Kaynağa Gözat

fix(monitor): anchor tmux session checks to avoid matching other instances (#4989)

* fix(monitor): anchor tmux session checks to avoid matching other instances

The monitor's session migration checks used unanchored pgrep/pkill
patterns. With multiple instances under one user where one session name
is a prefix of another (e.g. vhserver and vhserver-2), the shorter
instance's "old type tmux session" check matched the other instance's
concurrently running pgrep command line, causing spurious restarts
whenever both monitors ran at the same time.

Anchor the patterns to the start of the command line and require the
session name to be followed by a space or end of line.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(monitor): drop code comment

---------

Co-authored-by: yourfate <2371889-youRFate@users.noreply.gitlab.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Daniel Gibbs <me@danielgibbs.co.uk>
yourfate 1 hafta önce
ebeveyn
işleme
6cf5aa3ed3
1 değiştirilmiş dosya ile 4 ekleme ve 4 silme
  1. 4 4
      lgsm/modules/command_monitor.sh

+ 4 - 4
lgsm/modules/command_monitor.sh

@@ -211,23 +211,23 @@ fn_monitor_check_session() {
 		command_restart.sh
 		core_exit.sh
 	# Check for tmux pids with the same tmux session and socket names. This will reduce issues with migration to release v23.5.0. #4296
-	elif [ "$(pgrep -fc -u "${USER}" "tmux -L ${sessionname} new-session -d -x ${sessionwidth} -y ${sessionheight} -s ${sessionname}")" != "0" ]; then
+	elif [ "$(pgrep -fc -u "${USER}" "^tmux -L ${sessionname} new-session -d -x ${sessionwidth} -y ${sessionheight} -s ${sessionname}( |$)")" != "0" ]; then
 		fn_print_error "Checking session: PIDS with the same tmux session and socket names are running"
 		fn_print_error_eol_nl
 		fn_script_log_error "Checking session: ERROR"
 		fn_script_log_error "Checking session: PIDS with the same tmux session and socket names are running"
 		fn_script_log_error "Checking session: Killing session with the socketname name ${sessionname} and session name ${sessionname}"
-		pkill -f "tmux -L ${sessionname} new-session -d -x ${sessionwidth} -y ${sessionheight} -s ${sessionname}"
+		pkill -f "^tmux -L ${sessionname} new-session -d -x ${sessionwidth} -y ${sessionheight} -s ${sessionname}( |$)"
 		command_restart.sh
 		core_exit.sh
 	# Check for tmux pids that are using the old type of tmux session. This will reduce issues with migration to release v23.5.0. #4296
-	elif [ "$(pgrep -fc -u "${USER}" "tmux new-session -d -x ${sessionwidth} -y ${sessionheight} -s ${sessionname}")" != "0" ]; then
+	elif [ "$(pgrep -fc -u "${USER}" "^tmux new-session -d -x ${sessionwidth} -y ${sessionheight} -s ${sessionname}( |$)")" != "0" ]; then
 		fn_print_error "Checking session: PIDS with old type tmux session are running"
 		fn_print_error_eol_nl
 		fn_script_log_error "Checking session: ERROR"
 		fn_script_log_error "Checking session: PIDS with old type tmux session are running"
 		fn_script_log_error "Checking session: Killing session with the session name ${sessionname}"
-		pkill -f "tmux new-session -d -x ${sessionwidth} -y ${sessionheight} -s ${sessionname}"
+		pkill -f "^tmux new-session -d -x ${sessionwidth} -y ${sessionheight} -s ${sessionname}( |$)"
 		command_restart.sh
 		core_exit.sh
 	elif [ "${status}" != "0" ]; then