DevOps Patterns
These are tmux workflows for real server administration, designed for reliability and repeatability.
Core Idea
Tmux's value in DevOps comes from three things: persistent sessions, multi-pane visibility, and scriptable workspace setup.
Pattern 1: Server Health Dashboard
Monitor a server's health from a single tmux session:
~/bin/healthdash.sh
#!/bin/bash
SESSION="health"
tmux has-session -t "$SESSION" 2>/dev/null && tmux attach -t "$SESSION" && exit
tmux new -s "$SESSION" -n "overview" -d
# Split into 4 panes
tmux split-window -h -t "$SESSION:overview"
tmux split-window -v -t "$SESSION:overview.0"
tmux split-window -v -t "$SESSION:overview.1"
tmux select-layout -t "$SESSION:overview" tiled
# Pane assignments
tmux send-keys -t "$SESSION:overview.0" "htop" Enter
tmux send-keys -t "$SESSION:overview.1" "watch -n 3 df -h" Enter
tmux send-keys -t "$SESSION:overview.2" "watch -n 3 free -h" Enter
tmux send-keys -t "$SESSION:overview.3" "tail -f /var/log/syslog" Enter
tmux attach -t "$SESSION"
Pattern 2: Zero-Downtime Deployment
A deployment session with role-isolated panes:
~/bin/deploy.sh
#!/bin/bash
SESSION="deploy"
APP="/srv/myapp"
tmux has-session -t "$SESSION" 2>/dev/null && tmux attach -t "$SESSION" && exit
tmux new -s "$SESSION" -n "deploy" -d
# Layout: deploy left, service status + logs right
tmux split-window -h -t "$SESSION:deploy"
tmux split-window -v -t "$SESSION:deploy.1"
tmux send-keys -t "$SESSION:deploy.0" "cd $APP && echo 'Ready to deploy'" Enter
tmux send-keys -t "$SESSION:deploy.1" "watch systemctl status myapp.service" Enter
tmux send-keys -t "$SESSION:deploy.2" "tail -f $APP/logs/app.log" Enter
tmux select-pane -t "$SESSION:deploy.0"
tmux attach -t "$SESSION"
Pattern 3: Incident Response Workspace
When something is on fire, open a structured incident session:
~/bin/incident.sh
#!/bin/bash
SESSION="incident-$(date +%Y%m%d-%H%M)"
tmux new -s "$SESSION" -n "triage" -d
# Window 2: logs
tmux new-window -t "$SESSION" -n "logs"
tmux split-window -v -t "$SESSION:logs"
# Window 3: database
tmux new-window -t "$SESSION" -n "db"
# Start tools
tmux send-keys -t "$SESSION:triage" "htop" Enter
tmux send-keys -t "$SESSION:logs.0" "journalctl -f -u myapp.service" Enter
tmux send-keys -t "$SESSION:logs.1" "tail -f /var/log/nginx/error.log" Enter
tmux select-window -t "$SESSION:triage"
tmux attach -t "$SESSION"
Naming the session with a timestamp creates an automatic audit trail:
tmux ls
# incident-20260407-1522: 3 windows (created...)
Pattern 4: Multi-Server SSH in Panes
Open SSH connections to multiple servers in split panes:
~/bin/multiserver.sh
#!/bin/bash
SESSION="servers"
SERVERS=("web01" "web02" "db01" "cache01")
tmux has-session -t "$SESSION" 2>/dev/null && tmux attach -t "$SESSION" && exit
# First server in new session
tmux new -s "$SESSION" -n "${SERVERS[0]}" -d
tmux send-keys -t "$SESSION:${SERVERS[0]}" "ssh ${SERVERS[0]}" Enter
# Rest as new windows
for SERVER in "${SERVERS[@]:1}"; do
tmux new-window -t "$SESSION" -n "$SERVER"
tmux send-keys -t "$SESSION:$SERVER" "ssh $SERVER" Enter
done
tmux select-window -t "$SESSION:${SERVERS[0]}"
tmux attach -t "$SESSION"
Pattern 5: Long-Running Job Monitoring
For jobs that take hours:
#!/bin/bash
SESSION="longrun"
tmux has-session -t "$SESSION" 2>/dev/null && tmux attach -t "$SESSION" && exit
tmux new -s "$SESSION" -d
# Window for the job itself
tmux send-keys -t "$SESSION" "time rsync -avz /data /backup 2>&1 | tee /var/log/backup.log" Enter
# Second window for monitoring progress
tmux new-window -t "$SESSION" -n "monitor"
tmux send-keys -t "$SESSION:monitor" "tail -f /var/log/backup.log" Enter
tmux select-window -t "$SESSION:0"
tmux attach -t "$SESSION"
Workflow Summary
| Pattern | Window Count | Pane Layout |
|---|---|---|
| Health dashboard | 1 | 2x2 tiled |
| Zero-downtime deploy | 1 | main-vertical |
| Incident response | 3 | separate windows |
| Multi-server SSH | N (one per server) | single panes |
| Long-running job | 2 | single panes |