Showing posts with label Tmux runbook. Show all posts
Showing posts with label Tmux runbook. Show all posts

Wednesday, 12 August 2026

Tmux Runbook

 Step 1: Install Tmux on the Server

SSH into your RunPod instance and run the following commands to update the package manager and install tmux: 
bash
# Update package lists
apt-get update

# Install tmux
apt-get install -y tmux
Step 2: Start a Persistent Session
Always launch a named session before starting any long-running command. Naming the session makes it easy to track and re-enter.
bash
# Syntax: tmux new -s <session_name>
tmux new -s training_session
Step 3: Execute and Detach
Run your script normally inside the tmux window.
  1. Start your process:
    bash
    python3 train.py --epochs 100
    

  2. Disconnect safely (Detach):
    To leave the script running in the background and return to your regular server terminal, press this exact key sequence:
    • Press and hold Ctrl + B at the same time.
    • Release both keys.
    • Press D on your keyboard. 
You will see a message like [detached (from session training_session)]. You can now safely close your terminal or close your laptop; the script will not stop. 

Step 4: Reconnect and Monitor
If your connection drops, or if you want to check your progress hours later:
  1. SSH back into your RunPod instance.
  2. List active sessions to verify it is still running:
    bash
    tmux ls
    

  3. Re-attach to your session:
    bash
    # Syntax: tmux attach -t <session_name>
    tmux attach -t training_session
    


Step 5: Clean Up
Once your script finishes running completely, you should close the session to free up server resources.
  • Option A (Inside the session): Type exit and press Enter.
  • Option B (Outside the session): Run tmux kill-session -t training_session.

Cheat Sheet Reference
GoalKey / Command
Install Tmuxapt-get install -y tmux
Start Named Sessiontmux new -s <name>
List All Sessionstmux ls
Detach from SessionCtrl + B then D
Re-attach to Sessiontmux attach -t <name>
Kill/Delete Sessiontmux kill-session -t <name>