From 82b684e376a3a5aee766a5a0c2d7b6626409eb55 Mon Sep 17 00:00:00 2001 From: Vulcan <93451215+trholding@users.noreply.github.com> Date: Tue, 4 Feb 2025 01:28:14 +0530 Subject: [PATCH] tmux support for Linux **tmux Support for Linux** The `run` script with `cos_117.cfg` spawns xterms for consoles, which works well on desktops but not on VPS/servers without X forwarding or for users preferring SSH/shell/mosh. To resolve, this commit adds tmux support via: + run_tmux - Script that manages a cray simulator session. + cos_117_tmux.cfg - Modified config that spawns tmux windows instead of xterms. Benefits: - Organizes cray simulator and consoles as tmux windows in a tmux session. - Allows attaching, detaching, and exiting without stopping the simulator. - Console windows can be scripted to pass input / output for development. Usage: ``` run_tmux start run_tmux attach or execute `run_tmux` and select from menu. ``` Full Usage: ``` Usage: run_tmux {start|stop|restart|kill|attach|status} start - Start the Cray simulator session stop - Stop the Cray simulator session restart - Restart the Cray simulator session kill - Kill the Cray simulator session (unsafe) attach - Attach to the Cray simulator session status - List running Cray simulator and consoles Use keys 'Ctrl b <0 to ...>' to move to specific windows Use keys 'Ctrl b n' to move to the next window Use keys 'Ctrl b p' to move to the previous window Use keys 'Ctrl b d' to detach from the simulator session. ``` Tests: - The script was checked in shellcheck with minimal issues detected. - Tested on Ubuntu 22.04.3 LTS (aarch64) - Tested on Arch Linux (x86_64) --- cos_117_tmux.cfg | 14 +++++++------- tmux_run => run_tmux | 8 ++++---- 2 files changed, 11 insertions(+), 11 deletions(-) rename tmux_run => run_tmux (86%) mode change 100644 => 100755 diff --git a/cos_117_tmux.cfg b/cos_117_tmux.cfg index f5f6857..f4a7dba 100644 --- a/cos_117_tmux.cfg +++ b/cos_117_tmux.cfg @@ -169,7 +169,7 @@ IopClusters { Console { TIChannelIdx 040 TOChannelIdx 041 - NewTerminalCommand "tmux new-window -d -t cray -n cray_{port} '{cmd}'&" + NewTerminalCommand "tmux new-session -d -s cray_{port} -n cray_{port} '{cmd}'&" ConsoleCommandLinux "telnet {host} {port}" ConsoleCommandWindows "putty.exe -load Unicos -telnet -P {port} {host}" MapBackspace yes @@ -179,7 +179,7 @@ IopClusters { Console { TIChannelIdx 042 TOChannelIdx 043 - NewTerminalCommand "tmux new-window -d -t cray -n cray_{port} '{cmd}'&" + NewTerminalCommand "tmux new-session -d -s cray_{port} -n cray_{port} '{cmd}'&" ConsoleCommandLinux "telnet {host} {port}" ConsoleCommandWindows "putty.exe -load Unicos -telnet -P {port} {host}" MapBackspace yes @@ -189,7 +189,7 @@ IopClusters { Console { TIChannelIdx 044 TOChannelIdx 045 - NewTerminalCommand "tmux new-window -d -t cray -n cray_{port} '{cmd}'&" + NewTerminalCommand "tmux new-session -d -s cray_{port} -n cray_{port} '{cmd}'&" ConsoleCommandLinux "telnet {host} {port}" ConsoleCommandWindows "putty.exe -load Unicos -telnet -P {port} {host}" MapBackspace yes @@ -199,7 +199,7 @@ IopClusters { Console { TIChannelIdx 046 TOChannelIdx 047 - NewTerminalCommand "tmux new-window -d -t cray -n cray_{port} '{cmd}'&" + NewTerminalCommand "tmux new-session -d -s cray_{port} -n cray_{port} '{cmd}'&" ConsoleCommandLinux "telnet {host} {port}" ConsoleCommandWindows "putty.exe -load Unicos -telnet -P {port} {host}" MapBackspace yes @@ -275,7 +275,7 @@ IopClusters { Console { TIChannelIdx 042 TOChannelIdx 043 - NewTerminalCommand "tmux new-window -d -t cray -n cray_{port} '{cmd}'&" + NewTerminalCommand "tmux new-session -d -s cray_{port} -n cray_{port} '{cmd}'&" ConsoleCommandLinux "telnet {host} {port}" ConsoleCommandWindows "putty.exe -load Unicos -telnet -P {port} {host}" MapBackspace yes @@ -297,7 +297,7 @@ IopClusters { Console { TIChannelIdx 042 TOChannelIdx 043 - NewTerminalCommand "tmux new-window -d -t cray -n cray_{port} '{cmd}'&" + NewTerminalCommand "tmux new-session -d -s cray_{port} -n cray_{port} '{cmd}'&" ConsoleCommandLinux "telnet {host} {port}" ConsoleCommandWindows "putty.exe -load Unicos -telnet -P {port} {host}" MapBackspace yes @@ -441,7 +441,7 @@ IopClusters { Console { TIChannelIdx 042 TOChannelIdx 043 - NewTerminalCommand "tmux new-window -d -t cray -n cray_{port} '{cmd}'&" + NewTerminalCommand "tmux new-session -d -s cray_{port} -n cray_{port} '{cmd}'&" ConsoleCommandLinux "telnet {host} {port}" ConsoleCommandWindows "putty.exe -load Unicos -telnet -P {port} {host}" MapBackspace yes diff --git a/tmux_run b/run_tmux old mode 100644 new mode 100755 similarity index 86% rename from tmux_run rename to run_tmux index 7a87207..fa53a4d --- a/tmux_run +++ b/run_tmux @@ -1,7 +1,6 @@ #!/bin/sh PATH=$PATH:simulator/_bin/linux_release -# Usage message usage() { cat << EOF @@ -53,8 +52,10 @@ cray_is_up() { start_cray() { if cray_is_up; then msg "running"; else mkdir -p dump disk tape - tmux new-session -d -s cray - #space for future tmux hooks here + tmux new-session -d -s cray + # Simplify the hooks, they could be error prone + tmux set-hook -t cray -g session-created 'run-shell "tmux list-sessions -F '#{session_name}' | grep '^cray_' | sort | while read -r session; do tmux move-window -s $session:0 -t cray:; done; tmux move-window -s cray:$(tmux list-windows -t cray | grep -n 'cray_sim' | cut -d: -f1) -t cray:0"' + tmux set-hook -t cray -g window-linked 'run-shell "tmux list-windows -t cray -F \"#{window_index}\" | awk '\''$1 != \"0\" {print \"tmux rename-window -t \" $1 \" console_\" NR-1}'\'' | bash"' tmux send-keys -t cray 'cray_sim cos_117_tmux.cfg' C-m msg "started" help @@ -96,7 +97,6 @@ restart_cray() { # Attach to the cray simulator session attach_cray() { if cray_is_up; then tmux attach-session -t cray; else msg "not_up"; fi } - # Display status of cray simulator session and consoles status_cray() { if cray_is_up; then