Skip to content
Will Kibbe edited this page Aug 30, 2023 · 4 revisions

Why are we using tmux?

tmux is used in RHEL labs to facilitate the preservation of the terminal between steps in Instruqt. Without tmux, the user's terminal would be cleared when they proceed to the next step.

Attaching to tmux sessions in Instruqt

The presence of tmux only affects the terminal tab. Configure it in the tabs section of the assignment file like this :

- title: Terminal
  type: terminal
  hostname: rhel
  cmd: tmux attach-session -t "rhel-session" > /dev/null 2>&1

How should we configure tmux?

In the setup-rhel script for each lab, include the following section

#set up tmux so it has to restart itself whenever the system reboots

#step 1: make a script
tee ~/startup-tmux.sh << EOF
TMUX='' tmux new-session -d -s 'rhel-session' > /dev/null 2>&1
tmux set -g pane-border-status top
tmux setw -g pane-border-format ' #{pane_index} #{pane_current_command}'
tmux set -g mouse on
tmux set mouse on
tmux unbind -n MouseDown3Pane
EOF

#step 2: make it executable
chmod +x ~/startup-tmux.sh
#step 3: use cron to execute 
echo "@reboot ~/startup-tmux.sh" | crontab -

#step 4: start tmux for the lab
~/startup-tmux.sh

Why is the script set up this way?

  1. First, we create a script called startup-tmux.sh. This allows us to configure tmux in a predictable way.
  2. In the script we create, we set the following settings
TMUX='' tmux new-session -d -s 'rhel-session' > /dev/null 2>&1 # create a new session called rhel-session
tmux set -g pane-border-status top # format the appearance of our tmux pane
tmux setw -g pane-border-format ' #{pane_index} #{pane_current_command}' # format the appearance of our tmux pane
tmux set -g mouse on # enable mouse mode to facilitate scrolling within tmux
tmux set mouse on # enable mouse mode to facilitate scrolling within tmux
tmux unbind -n MouseDown3Pane # disable tmux's mapping for the right click button on the mouse because it is not necessary and interferes with the user's ability to paste commands into the lab environment
  1. After creating the script and making it executable, we use this command to tell Cron to run the script every time the system reboots. This allows the user to run the reboot command in the lab without breaking it. Without cron, if the user were to run reboot, the tmux session would not restart and the lab would break.
echo "@reboot ~/startup-tmux.sh" | crontab -
  1. Finally, we run the script at the beginning of the lab to configure the lab environment.