Skip to content

Commit 51ad60e

Browse files
fix: Set TERM=screen for all non-interactive tmux calls (#4860)
When connected to a server via ssh, and the server doesn't have the proper terminfo, tmux will fail with 'unsupported terminal' errors. These errors are not surfaced by the scripts, e.g. details, start, stop, so they result in either silent failures or don't work at all. e.g. `./mcserver details` on my server showed 0% CPU, 0% Memory, and STOPPED for the server status when the server was actually running. This was because the tmux calls to get this info failed. The root cause of this was that I was connected to my server via kitty, a terminal emulator that my server did not have terminfo for. This can be resolved via running `infocmp -x xterm-kitty | ssh YOUR-SERVER -- tic -x -` and replacing `xterm-kitty` with whatever is appropriate, or by setting TERM=xterm-256color in the ssh config, but that is not obvious to do when presented with silent failures. This commit sets TERM=screen for all non-interactive tmux calls, which resolves the issue. Note that the `console` command does not set this, as that is an interactive shell, and the user's terminfo should be passed. Co-authored-by: Daniel Gibbs <me@danielgibbs.co.uk>
1 parent 6bcb856 commit 51ad60e

6 files changed

Lines changed: 15 additions & 15 deletions

File tree

lgsm/modules/check_status.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77

88
moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
99

10-
status=$(tmux -L "${socketname}" list-sessions -F "#{session_name}" 2> /dev/null | grep -Ecx "^${sessionname}")
10+
status=$(TERM=screen tmux -L "${socketname}" list-sessions -F "#{session_name}" 2> /dev/null | grep -Ecx "^${sessionname}")

lgsm/modules/command_send.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ if [ "${status}" != "0" ]; then
2727
echo ""
2828
fn_print_dots "Sending command to console: \"${commandtosend}\""
2929
fn_print_ok_nl "Sending command to console: \"${commandtosend}\""
30-
tmux -L "${socketname}" send-keys -t "${sessionname}" "${commandtosend}" ENTER
30+
TERM=screen tmux -L "${socketname}" send-keys -t "${sessionname}" "${commandtosend}" ENTER
3131
fn_script_log_pass "Command \"${commandtosend}\" sent to console"
3232
else
3333
fn_print_error_nl "Unable to send command to console. Server not running"

lgsm/modules/command_start.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ fn_firstcommand_set
1515
# Used to allow update to detect JK2MV server version.
1616
fn_start_jk2() {
1717
fn_start_tmux
18-
tmux -L "${socketname}" end -t "${sessionname}" version ENTER > /dev/null 2>&1
18+
TERM=screen tmux -L "${socketname}" end -t "${sessionname}" version ENTER > /dev/null 2>&1
1919
}
2020

2121
fn_start_tmux() {
@@ -67,7 +67,7 @@ fn_start_tmux() {
6767
cd "${executabledir}" || exit
6868
fi
6969

70-
tmux -L "${socketname}" new-session -d -x "${sessionwidth}" -y "${sessionheight}" -s "${sessionname}" "${preexecutable} ${executable} ${startparameters}" 2> "${lgsmlogdir}/.${selfname}-tmux-error.tmp"
70+
TERM=screen tmux -L "${socketname}" new-session -d -x "${sessionwidth}" -y "${sessionheight}" -s "${sessionname}" "${preexecutable} ${executable} ${startparameters}" 2> "${lgsmlogdir}/.${selfname}-tmux-error.tmp"
7171

7272
# Create logfile.
7373
touch "${consolelog}"
@@ -82,9 +82,9 @@ fn_start_tmux() {
8282
if [ "${consolelogging}" == "on" ] || [ -z "${consolelogging}" ]; then
8383
# timestamp will break mcb update check.
8484
if [ "${logtimestamp}" == "on" ] && [ "${shortname}" != "mcb" ]; then
85-
tmux -L "${socketname}" pipe-pane -o -t "${sessionname}" "exec bash -c \"cat | $addtimestamp\" >> '${consolelog}'"
85+
TERM=screen tmux -L "${socketname}" pipe-pane -o -t "${sessionname}" "exec bash -c \"cat | $addtimestamp\" >> '${consolelog}'"
8686
else
87-
tmux -L "${socketname}" pipe-pane -o -t "${sessionname}" "exec cat >> '${consolelog}'"
87+
TERM=screen tmux -L "${socketname}" pipe-pane -o -t "${sessionname}" "exec cat >> '${consolelog}'"
8888
fi
8989
else
9090
echo -e "Console logging disabled in settings" >> "${consolelog}"

lgsm/modules/command_stop.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ fn_stop_graceful_ctrlc() {
1515
fn_print_dots "Graceful: CTRL+c"
1616
fn_script_log_info "Graceful: CTRL+c"
1717
# Sends CTRL+c.
18-
tmux -L "${socketname}" send-keys -t "${sessionname}" C-c > /dev/null 2>&1
18+
TERM=screen tmux -L "${socketname}" send-keys -t "${sessionname}" C-c > /dev/null 2>&1
1919
# Waits up to 30 seconds giving the server time to shutdown gracefully.
2020
for seconds in {1..30}; do
2121
check_status.sh
@@ -47,7 +47,7 @@ fn_stop_graceful_cmd() {
4747
fn_print_dots "Graceful: sending \"${1}\""
4848
fn_script_log_info "Graceful: sending \"${1}\""
4949
# Sends specific stop command.
50-
tmux -L "${socketname}" send -t "${sessionname}" ENTER "${1}" ENTER > /dev/null 2>&1
50+
TERM=screen tmux -L "${socketname}" send -t "${sessionname}" ENTER "${1}" ENTER > /dev/null 2>&1
5151
# Waits up to ${seconds} seconds giving the server time to shutdown gracefully.
5252
for ((seconds = 1; seconds <= ${2}; seconds++)); do
5353
check_status.sh
@@ -79,7 +79,7 @@ fn_stop_graceful_goldsrc() {
7979
fn_print_dots "Graceful: sending \"quit\""
8080
fn_script_log_info "Graceful: sending \"quit\""
8181
# sends quit
82-
tmux -L "${socketname}" send -t "${sessionname}" quit ENTER > /dev/null 2>&1
82+
TERM=screen tmux -L "${socketname}" send -t "${sessionname}" quit ENTER > /dev/null 2>&1
8383
# Waits 3 seconds as goldsrc servers restart with the quit command.
8484
for seconds in {1..3}; do
8585
fn_sleep_time_1
@@ -289,10 +289,10 @@ fn_stop_graceful_avorion() {
289289
fn_print_dots "Graceful: /save /stop"
290290
fn_script_log_info "Graceful: /save /stop"
291291
# Sends /save.
292-
tmux -L "${socketname}" send-keys -t "${sessionname}" /save ENTER > /dev/null 2>&1
292+
TERM=screen tmux -L "${socketname}" send-keys -t "${sessionname}" /save ENTER > /dev/null 2>&1
293293
fn_sleep_time_5
294294
# Sends /quit.
295-
tmux -L "${socketname}" send-keys -t "${sessionname}" /stop ENTER > /dev/null 2>&1
295+
TERM=screen tmux -L "${socketname}" send-keys -t "${sessionname}" /stop ENTER > /dev/null 2>&1
296296
# Waits up to 30 seconds giving the server time to shutdown gracefully.
297297
for seconds in {1..30}; do
298298
check_status.sh
@@ -351,7 +351,7 @@ fn_stop_tmux() {
351351
fn_print_dots "${servername}"
352352
fn_script_log_info "tmux kill-session: ${sessionname}: ${servername}"
353353
# Kill tmux session.
354-
tmux -L "${socketname}" kill-session -t "${sessionname}" > /dev/null 2>&1
354+
TERM=screen tmux -L "${socketname}" kill-session -t "${sessionname}" > /dev/null 2>&1
355355
fn_sleep_time_1
356356
check_status.sh
357357
if [ "${status}" == "0" ]; then

lgsm/modules/info_distro.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
1111

1212
### Game Server pid
1313
if [ "${status}" == "1" ]; then
14-
gameserverpid="$(tmux -L "${socketname}" list-sessions -F "#{session_name} #{pane_pid}" | grep "^${sessionname} " | awk '{print $NF}')"
14+
gameserverpid="$(TERM=screen tmux -L "${socketname}" list-sessions -F "#{session_name} #{pane_pid}" | grep "^${sessionname} " | awk '{print $NF}')"
1515
if [ "${engine}" == "source" ]; then
1616
srcdslinuxpid="$(pgrep -P "${gameserverpid}" -x srcds_linux 2> /dev/null | head -n 1)"
1717
elif [ "${engine}" == "goldsrc" ]; then

lgsm/modules/update_xnt.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ fn_update_localbuild() {
2020
check_status.sh
2121
# Send version command to Xonotic server.
2222
if [ "${status}" != "0" ]; then
23-
tmux -L "${socketname}" send-keys -t "${sessionname}" "version" C-m > /dev/null 2>&1
23+
TERM=screen tmux -L "${socketname}" send-keys -t "${sessionname}" "version" C-m > /dev/null 2>&1
2424
fn_sleep_time_1
2525
else
2626
exitbypass=1
2727
command_start.sh
2828
fn_firstcommand_reset
2929
exitbypass=1
3030
fn_sleep_time_5
31-
tmux -L "${socketname}" send-keys -t "${sessionname}" "version" C-m > /dev/null 2>&1
31+
TERM=screen tmux -L "${socketname}" send-keys -t "${sessionname}" "version" C-m > /dev/null 2>&1
3232
exitbypass=1
3333
command_stop.sh
3434
unset exitbypass

0 commit comments

Comments
 (0)