Browse Source

fix(tmux): force tmux to create a new trmux server instance for each game instance to avoid sharing same pid.

pull/3767/head
cclecle 4 years ago
parent
commit
4e73aa4fc5
  1. 2
      lgsm/functions/check_status.sh
  2. 2
      lgsm/functions/command_console.sh
  3. 2
      lgsm/functions/command_send.sh
  4. 10
      lgsm/functions/command_start.sh
  5. 12
      lgsm/functions/command_stop.sh
  6. 2
      lgsm/functions/info_distro.sh

2
lgsm/functions/check_status.sh

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

2
lgsm/functions/command_console.sh

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

2
lgsm/functions/command_send.sh

@ -26,7 +26,7 @@ if [ "${status}" != "0" ]; then
fi fi
echo "" echo ""
fn_print_dots "Sending command to console: \"${commandtosend}\"" fn_print_dots "Sending command to console: \"${commandtosend}\""
tmux send-keys -t "${servicename}" "${commandtosend}" ENTER tmux -L "${sessionname}" send-keys -t "${servicename}" "${commandtosend}" ENTER
fn_print_ok_nl "Sending command to console: \"${commandtosend}\"" fn_print_ok_nl "Sending command to console: \"${commandtosend}\""
fn_script_log_pass "Command \"${commandtosend}\" sent to console" fn_script_log_pass "Command \"${commandtosend}\" sent to console"
else else

10
lgsm/functions/command_start.sh

@ -36,7 +36,7 @@ fn_start_teamspeak3(){
# Used to allow update to detect JK2MV server version. # Used to allow update to detect JK2MV server version.
fn_start_jk2(){ fn_start_jk2(){
fn_start_tmux fn_start_tmux
tmux send -t "${sessionname}" version ENTER > /dev/null 2>&1 tmux -L "${sessionname}" send -t "${sessionname}" version ENTER > /dev/null 2>&1
} }
fn_start_tmux(){ fn_start_tmux(){
@ -79,7 +79,7 @@ fn_start_tmux(){
cd "${executabledir}" || exit cd "${executabledir}" || exit
fi fi
tmux new-session -d -x "${sessionwidth}" -y "${sessionheight}" -s "${sessionname}" "${preexecutable} ${executable} ${startparameters}" 2> "${lgsmlogdir}/.${selfname}-tmux-error.tmp" tmux -L "${sessionname}" new-session -d -x "${sessionwidth}" -y "${sessionheight}" -s "${sessionname}" "${preexecutable} ${executable} ${startparameters}" 2> "${lgsmlogdir}/.${selfname}-tmux-error.tmp"
# Create logfile. # Create logfile.
touch "${consolelog}" touch "${consolelog}"
@ -92,7 +92,7 @@ fn_start_tmux(){
fn_script_log "tmux version: master (user compiled)" fn_script_log "tmux version: master (user compiled)"
echo -e "tmux version: master (user compiled)" >> "${consolelog}" echo -e "tmux version: master (user compiled)" >> "${consolelog}"
if [ "${consolelogging}" == "on" ]||[ -z "${consolelogging}" ]; then if [ "${consolelogging}" == "on" ]||[ -z "${consolelogging}" ]; then
tmux pipe-pane -o -t "${sessionname}" "exec cat >> '${consolelog}'" tmux -L "${sessionname}" pipe-pane -o -t "${sessionname}" "exec cat >> '${consolelog}'"
fi fi
elif [ -n "${tmuxv}" ]; then elif [ -n "${tmuxv}" ]; then
# tmux pipe-pane not supported in tmux versions < 1.6. # tmux pipe-pane not supported in tmux versions < 1.6.
@ -108,7 +108,7 @@ fn_start_tmux(){
Currently installed: $(tmux -V)" > "${consolelog}" Currently installed: $(tmux -V)" > "${consolelog}"
# Console logging enable or not set. # Console logging enable or not set.
elif [ "${consolelogging}" == "on" ]||[ -z "${consolelogging}" ]; then elif [ "${consolelogging}" == "on" ]||[ -z "${consolelogging}" ]; then
tmux pipe-pane -o -t "${sessionname}" "exec cat >> '${consolelog}'" tmux -L "${sessionname}" pipe-pane -o -t "${sessionname}" "exec cat >> '${consolelog}'"
fi fi
else else
echo -e "Unable to detect tmux version" >> "${consolelog}" echo -e "Unable to detect tmux version" >> "${consolelog}"
@ -133,7 +133,7 @@ fn_start_tmux(){
echo -e "" echo -e ""
echo -e "Command" echo -e "Command"
echo -e "=================================" echo -e "================================="
echo -e "tmux new-session -d -s \"${sessionname}\" \"${preexecutable} ${executable} ${startparameters}\"" | tee -a "${lgsmlog}" echo -e "tmux -L \"${sessionname}\" new-session -d -s \"${sessionname}\" \"${preexecutable} ${executable} ${startparameters}\"" | tee -a "${lgsmlog}"
echo -e "" echo -e ""
echo -e "Error" echo -e "Error"
echo -e "=================================" echo -e "================================="

12
lgsm/functions/command_stop.sh

@ -15,7 +15,7 @@ fn_stop_graceful_ctrlc(){
fn_print_dots "Graceful: CTRL+c" fn_print_dots "Graceful: CTRL+c"
fn_script_log_info "Graceful: CTRL+c" fn_script_log_info "Graceful: CTRL+c"
# Sends quit. # Sends quit.
tmux send-keys -t "${sessionname}" C-c > /dev/null 2>&1 tmux -L "${sessionname}" send-keys -t "${sessionname}" C-c > /dev/null 2>&1
# Waits up to 30 seconds giving the server time to shutdown gracefuly. # Waits up to 30 seconds giving the server time to shutdown gracefuly.
for seconds in {1..30}; do for seconds in {1..30}; do
check_status.sh check_status.sh
@ -43,7 +43,7 @@ fn_stop_graceful_cmd(){
fn_print_dots "Graceful: sending \"${1}\"" fn_print_dots "Graceful: sending \"${1}\""
fn_script_log_info "Graceful: sending \"${1}\"" fn_script_log_info "Graceful: sending \"${1}\""
# Sends specific stop command. # Sends specific stop command.
tmux send -t "${sessionname}" ENTER "${1}" ENTER > /dev/null 2>&1 tmux -L "${sessionname}" send -t "${sessionname}" ENTER "${1}" ENTER > /dev/null 2>&1
# Waits up to ${seconds} seconds giving the server time to shutdown gracefully. # Waits up to ${seconds} seconds giving the server time to shutdown gracefully.
for ((seconds=1; seconds<=${2}; seconds++)); do for ((seconds=1; seconds<=${2}; seconds++)); do
check_status.sh check_status.sh
@ -71,7 +71,7 @@ fn_stop_graceful_goldsrc(){
fn_print_dots "Graceful: sending \"quit\"" fn_print_dots "Graceful: sending \"quit\""
fn_script_log_info "Graceful: sending \"quit\"" fn_script_log_info "Graceful: sending \"quit\""
# sends quit # sends quit
tmux send -t "${sessionname}" quit ENTER > /dev/null 2>&1 tmux -L "${sessionname}" send -t "${sessionname}" quit ENTER > /dev/null 2>&1
# Waits 3 seconds as goldsrc servers restart with the quit command. # Waits 3 seconds as goldsrc servers restart with the quit command.
for seconds in {1..3}; do for seconds in {1..3}; do
sleep 1 sleep 1
@ -184,10 +184,10 @@ fn_stop_graceful_avorion(){
fn_print_dots "Graceful: /save /stop" fn_print_dots "Graceful: /save /stop"
fn_script_log_info "Graceful: /save /stop" fn_script_log_info "Graceful: /save /stop"
# Sends /save. # Sends /save.
tmux send-keys -t "${sessionname}" /save ENTER > /dev/null 2>&1 tmux -L "${sessionname}" send-keys -t "${sessionname}" /save ENTER > /dev/null 2>&1
sleep 5 sleep 5
# Sends /quit. # Sends /quit.
tmux send-keys -t "${sessionname}" /stop ENTER > /dev/null 2>&1 tmux -L "${sessionname}" send-keys -t "${sessionname}" /stop ENTER > /dev/null 2>&1
# Waits up to 30 seconds giving the server time to shutdown gracefuly. # Waits up to 30 seconds giving the server time to shutdown gracefuly.
for seconds in {1..30}; do for seconds in {1..30}; do
check_status.sh check_status.sh
@ -238,7 +238,7 @@ fn_stop_tmux(){
fn_print_dots "${servername}" fn_print_dots "${servername}"
fn_script_log_info "tmux kill-session: ${sessionname}: ${servername}" fn_script_log_info "tmux kill-session: ${sessionname}: ${servername}"
# Kill tmux session. # Kill tmux session.
tmux kill-session -t "${sessionname}" > /dev/null 2>&1 tmux -L "${sessionname}" kill-session -t "${sessionname}" > /dev/null 2>&1
sleep 0.5 sleep 0.5
check_status.sh check_status.sh
if [ "${status}" == "0" ]; then if [ "${status}" == "0" ]; then

2
lgsm/functions/info_distro.sh

@ -10,7 +10,7 @@ functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
### Game Server pid ### Game Server pid
if [ "${status}" == "1" ]; then if [ "${status}" == "1" ]; then
gameserverpid="$(tmux list-sessions -F "#{session_name} #{pane_pid}" | grep "^${sessionname} " | awk '{print $NF}')" gameserverpid="$(tmux -L "${sessionname}" list-sessions -F "#{session_name} #{pane_pid}" | grep "^${sessionname} " | awk '{print $NF}')"
if [ "${engine}" == "source" ]; then if [ "${engine}" == "source" ]; then
srcdslinuxpid="$(ps -ef | grep -v grep | grep "${gameserverpid}" | grep srcds_linux | awk '{print $2}')" srcdslinuxpid="$(ps -ef | grep -v grep | grep "${gameserverpid}" | grep srcds_linux | awk '{print $2}')"
elif [ "${engine}" == "goldsrc" ]; then elif [ "${engine}" == "goldsrc" ]; then

Loading…
Cancel
Save