Преглед изворни кода

feat: improve uniqueness tmux session name (#3081)

* Fixed uniqueness constraint on session names by adding port to tmux sesssions. Removed content constraint from session name by avoiding grep regex

Co-authored-by: jason <1569551+j4s0n@users.noreply.github.com>
Daniel Gibbs пре 5 година
родитељ
комит
990edfd775

+ 5 - 1
lgsm/functions/check_status.sh

@@ -7,4 +7,8 @@
 
 functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
 
-status=$(tmux list-sessions -F "#{session_name}" 2>/dev/null | grep -Ecx "^${sessionname}")
+if [ "$(tmux list-sessions -F "#{session_name}" 2>/dev/null)" == "${sessionname}${port}" ]; then
+		status=1;
+else
+		status=0;
+fi

+ 1 - 1
lgsm/functions/command_console.sh

@@ -41,7 +41,7 @@ check_status.sh
 if [ "${status}" != "0" ]; then
 	fn_print_ok_nl "Accessing console"
 	fn_script_log_pass "Console accessed"
-	tmux attach-session -t "${sessionname}"
+	tmux attach-session -t "${sessionname}${port}"
 	fn_print_ok_nl "Closing console"
 	fn_script_log_pass "Console closed"
 else

+ 3 - 3
lgsm/functions/command_start.sh

@@ -36,7 +36,7 @@ fn_start_teamspeak3(){
 # Used to allow update to detect JK2MV server version.
 fn_start_jk2(){
 	fn_start_tmux
-	tmux send -t "${sessionname}" version ENTER > /dev/null 2>&1
+	tmux send -t "${sessionname}${port}" version ENTER > /dev/null 2>&1
 }
 
 fn_start_tmux(){
@@ -72,7 +72,7 @@ fn_start_tmux(){
 	# Create lockfile
 	date '+%s' > "${lockdir}/${selfname}.lock"
 	cd "${executabledir}" || exit
-	tmux new-session -d -x "${sessionwidth}" -y "${sessionheight}" -s "${sessionname}" "${executable} ${parms}" 2> "${lgsmlogdir}/.${selfname}-tmux-error.tmp"
+	tmux new-session -d -x "${sessionwidth}" -y "${sessionheight}" -s "${sessionname}${port}" "${executable} ${parms}" 2> "${lgsmlogdir}/.${selfname}-tmux-error.tmp"
 
 	# Create logfile.
 	touch "${consolelog}"
@@ -130,7 +130,7 @@ fn_start_tmux(){
 			echo -e ""
 			echo -e "Command"
 			echo -e "================================="
-			echo -e "tmux new-session -d -s \"${sessionname}\" \"${executable} ${parms}\"" | tee -a "${lgsmlog}"
+			echo -e "tmux new-session -d -s \"${sessionname} ${port}\" \"${executable} ${parms}\"" | tee -a "${lgsmlog}"
 			echo -e ""
 			echo -e "Error"
 			echo -e "================================="

+ 1 - 1
lgsm/functions/command_stop.sh

@@ -15,7 +15,7 @@ fn_stop_graceful_ctrlc(){
 	fn_print_dots "Graceful: CTRL+c"
 	fn_script_log_info "Graceful: CTRL+c"
 	# Sends quit.
-	tmux send-keys -t "${sessionname}" C-c  > /dev/null 2>&1
+	tmux send-keys -t "${sessionname}${port}" C-c  > /dev/null 2>&1
 	# Waits up to 30 seconds giving the server time to shutdown gracefuly.
 	for seconds in {1..30}; do
 		check_status.sh

+ 1 - 1
lgsm/functions/info_distro.sh

@@ -9,7 +9,7 @@ functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
 
 ### Game Server pid
 if [ "${status}" == "1" ]; then
-	gameserverpid=$(tmux list-sessions -F "#{session_name} #{pane_pid}" | grep "^${sessionname} " | awk '{print $NF}')
+	gameserverpid=$(tmux list-sessions -F "#{session_name} #{pane_pid}" | grep "^${sessionname}${port}" | awk '{print $NF}')
 fi
 ### Distro information