Terminal User Interface (TUI)
Terminal User Interface (TUI)
Cbox Init includes a modern, k9s-style terminal user interface for interactive process management. The TUI provides real-time monitoring, process control, and configuration management without leaving your terminal.
Overview
Features:
- 📊 Real-time process status monitoring
- ⌨️ Keyboard-driven interface (Vim-style navigation)
- 🔄 Start, stop, restart, and scale processes interactively
- ➕ Add new processes via interactive wizard
- 📝 View process logs with tail functionality
- 🔌 Dual connectivity (Unix socket + TCP)
- 🔒 Automatic connection fallback and security
Quick Start
# Local connection (auto-detects Unix socket, falls back to TCP)
./cbox-init tui
# Explicit TCP connection
./cbox-init tui --url http://localhost:9180
# Remote connection with authentication
./cbox-init tui --url http://remote-host:9180 --auth your-secret-token
# TLS connection
./cbox-init tui --url https://remote-host:9180 --auth your-secret-token
Connection Modes
The TUI supports two connection modes with intelligent auto-detection:
Unix Socket (Local, Preferred)
Advantages:
- 🔒 Secure: File permissions control access (0600 = owner-only)
- ⚡ Fast: No network stack overhead
- 🎯 Simple: No authentication required (filesystem handles it)
Auto-detected paths (priority order):
/var/run/cbox-init.sock/tmp/cbox-init.sock/run/cbox-init.sock
Configuration:
global:
api_enabled: true
api_socket: "/var/run/cbox-init.sock"
TCP (Remote, Fallback)
Advantages:
- 🌐 Remote access: Connect from anywhere
- 🔐 Optional TLS: Encrypted connections
- 🛡️ ACL support: IP-based filtering
- 🔑 Authentication: Bearer token auth
Configuration:
global:
api_enabled: true
api_port: 9180
# Optional: Authentication
api_auth: "your-secret-token"
# Optional: TLS
api_tls:
enabled: true
cert_file: "/etc/cbox-init/server.crt"
key_file: "/etc/cbox-init/server.key"
# Optional: IP ACL
api_acl:
allow: ["127.0.0.1", "10.0.0.0/8"]
deny: []
Auto-Detection Logic
The TUI automatically tries connection methods in this order:
- ✅ Unix socket (each path in priority order)
- If socket exists and accessible → Use Unix socket
- ⏭️ TCP fallback (if no socket found)
- Falls back to TCP connection
Example:
# TUI tries:
# 1. /var/run/cbox-init.sock → Found! Using Unix socket
# OR
# 1. /var/run/cbox-init.sock → Not found
# 2. /tmp/cbox-init.sock → Not found
# 3. /run/cbox-init.sock → Not found
# 4. http://localhost:9180 → Fallback to TCP
Keyboard Shortcuts
Process List View
| Key | Action | Description |
|---|---|---|
↑/↓ or j/k |
Navigate | Move selection up/down in process list |
a |
Add Process | Open interactive process creation wizard |
r |
Restart | Restart selected process |
s |
Stop | Stop selected process |
x |
Start | Start selected process |
+ or = |
Scale Up | Open scale dialog (increase instances) |
- |
Scale Down | Open scale dialog (decrease instances) |
Enter |
View Logs | Open log viewer for selected process |
? |
Help | Show keyboard shortcuts help screen |
q or Esc |
Quit | Exit TUI |
Add Process Wizard
| Key | Action | Description |
|---|---|---|
Tab or Enter |
Next Step | Move to next wizard step |
Shift+Tab |
Previous Step | Go back to previous step |
Esc |
Cancel | Cancel wizard and return to process list |
Ctrl+W |
Add Item | Add command part, environment variable, etc. |
Ctrl+D |
Remove Item | Remove selected item from list |
↑/↓ |
Select Option | Navigate dropdown options |
Log Viewer
| Key | Action | Description |
|---|---|---|
↑/↓ or j/k |
Scroll | Scroll through log lines |
g |
Go to Top | Jump to beginning of logs |
G |
Go to Bottom | Jump to end of logs (tail mode) |
Esc or q |
Back | Return to process list |
Process Management
Start/Stop/Restart
Interactive control:
- Navigate to process with
↑/↓orj/k - Press:
xto start a stopped processsto stop a running processrto restart a running process
- Confirmation dialog appears
- Press
Enterto confirm orEscto cancel
Visual feedback:
- ✅ Success: Green toast notification
- ❌ Error: Red toast notification with error message
- ⏳ In Progress: Status indicator updates in real-time
Scaling Processes
Increase/decrease instances:
- Navigate to process
- Press
+(scale up) or-(scale down) - Scale dialog appears with:
- Current desired instances
- Current actual instances
- Input field for new desired count
- Enter new value and press
Enter - Process supervisor adjusts instances automatically
Example:
Process: queue-worker
Current: 3 instances running
Action: Press '+' → Enter '5' → Press Enter
Result: 2 new instances spawned (total: 5)
Add Process Wizard
The interactive wizard guides you through creating a new process configuration.
Wizard Steps
Step 1: Process Name
┌─ Add New Process (1/6) ─────────────────────────┐
│ Process Name │
│ ┌──────────────────────────────────────────────┐ │
│ │ queue-worker-notifications │ │
│ └──────────────────────────────────────────────┘ │
│ │
│ Enter unique process identifier (lowercase) │
└──────────────────────────────────────────────────┘
Step 2: Command
┌─ Add New Process (2/6) ─────────────────────────┐
│ Command │
│ ┌──────────────────────────────────────────────┐ │
│ │ php │ │
│ │ artisan │ │
│ │ queue:work │ │
│ │ --queue=notifications │ │
│ │ --tries=3 │ │
│ └──────────────────────────────────────────────┘ │
│ │
│ Ctrl+W: Add part Ctrl+D: Remove selected │
└──────────────────────────────────────────────────┘
Step 3: Scale (Instances)
┌─ Add New Process (3/6) ─────────────────────────┐
│ Number of Instances │
│ ┌──────────────────────────────────────────────┐ │
│ │ 2 │ │
│ └──────────────────────────────────────────────┘ │
│ │
│ How many instances to run (1-100) │
└──────────────────────────────────────────────────┘
Step 4: Restart Policy
┌─ Add New Process (4/6) ─────────────────────────┐
│ Restart Policy │
│ ┌──────────────────────────────────────────────┐ │
│ │ ▶ always │ │
│ │ on-failure │ │
│ │ never │ │
│ └──────────────────────────────────────────────┘ │
│ │
│ ↑/↓: Select Enter: Confirm │
└──────────────────────────────────────────────────┘
Step 5: Priority
┌─ Add New Process (5/6) ─────────────────────────┐
│ Startup Priority │
│ ┌──────────────────────────────────────────────┐ │
│ │ 40 │ │
│ └──────────────────────────────────────────────┘ │
│ │
│ Lower numbers start first (1-100) │
└──────────────────────────────────────────────────┘
Step 6: Preview & Confirm
┌─ Add New Process (6/6) ─────────────────────────┐
│ Preview Configuration │
│ │
│ Name: queue-worker-notifications │
│ Command: ["php", "artisan", "queue:work", │
│ "--queue=notifications", "--tries=3"] │
│ Scale: 2 │
│ Restart: always │
│ Priority: 40 │
│ │
│ Press Enter to create, Esc to cancel │
└──────────────────────────────────────────────────┘
Post-Creation
After confirmation:
- TUI calls API:
POST /api/v1/processeswith wizard data - Process is created in configuration
- TUI automatically calls:
POST /api/v1/config/saveto persist - Process list refreshes showing new process
- New process starts automatically (if enabled)
Process Status Display
Status Indicators
NAME STATUS INSTANCES RESTARTS UPTIME MEMORY CPU
php-fpm ✓ running 2/2 0 2h30m15s 256MB 2.5%
nginx ✓ running 1/1 0 2h30m10s 64MB 0.8%
horizon ✓ running 1/1 1 15m30s 128MB 5.2%
queue-default ✓ running 3/3 0 2h30m05s 384MB 12.1%
queue-emails ✗ stopped 0/2 5 - - -
Status symbols:
- ✓
running- Process is active and healthy - ✗
stopped- Process is not running - ⚠
starting- Process is initializing - ⏸
stopping- Graceful shutdown in progress - ⚠
unhealthy- Health checks failing
Instance format: actual/desired
2/2- All desired instances running1/2- Scale drift detected (1 running, 2 desired)0/2- Process stopped or failed to start
Configuration Requirements
Minimum requirements to use TUI:
global:
# Enable API server
api_enabled: true
# Choose connection method:
# Option 1: Unix socket (local, recommended)
api_socket: "/var/run/cbox-init.sock"
# Option 2: TCP (remote access)
api_port: 9180
# Optional: Authentication (TCP only)
api_auth: "your-secret-token"
Full example with security:
global:
api_enabled: true
api_port: 9180
api_socket: "/var/run/cbox-init.sock"
# Authentication (TCP only, socket uses file permissions)
api_auth: "${CBOX_INIT_API_TOKEN}"
# TLS for remote access
api_tls:
enabled: true
cert_file: "/etc/cbox-init/tls/server.crt"
key_file: "/etc/cbox-init/tls/server.key"
# IP ACL for additional security
api_acl:
allow: ["127.0.0.1", "10.0.0.0/8"]
deny: []
Security Considerations
Unix Socket Security
File permissions:
# Recommended: Owner-only access (0600)
chmod 600 /var/run/cbox-init.sock
chown cbox:cbox /var/run/cbox-init.sock
# Verify permissions
ls -la /var/run/cbox-init.sock
# Output: srw------- 1 cbox cbox 0 Nov 24 10:00 cbox-init.sock
Access control:
- Unix socket access controlled by filesystem permissions
- No authentication required (filesystem handles it)
- Recommended for local TUI access on production servers
TCP Security
Best practices:
- Always use TLS for remote connections
- Enable authentication with strong tokens
- Use IP ACL to restrict source IPs
- Rotate tokens regularly
- Monitor API access via logs
Production example:
global:
api_enabled: true
api_port: 9180
api_auth: "${CBOX_INIT_API_TOKEN}" # Load from env
api_tls:
enabled: true
cert_file: "/etc/cbox-init/tls/server.crt"
key_file: "/etc/cbox-init/tls/server.key"
api_acl:
allow: ["10.0.0.0/8"] # VPN network only
deny: []
Troubleshooting
TUI Won't Connect
Error: Failed to connect to Cbox Init API
Solutions:
-
Check API is enabled:
global: api_enabled: true -
Verify cbox-init is running:
ps aux | grep cbox-init -
Check socket exists (local):
ls -la /var/run/cbox-init.sock # Should show: srw------- 1 user user 0 ... cbox-init.sock -
Test TCP connection (remote):
curl http://localhost:9180/api/v1/health # Should return: {"status":"healthy"} -
Check authentication:
# If api_auth is set, token required curl -H "Authorization: Bearer your-token" \ http://localhost:9180/api/v1/processes
Permission Denied on Unix Socket
Error: Permission denied: /var/run/cbox-init.sock
Solutions:
-
Check socket permissions:
ls -la /var/run/cbox-init.sock -
Add user to socket owner group:
sudo usermod -a -G cbox $USER # Re-login for group changes to take effect -
Run TUI as socket owner:
sudo -u cbox cbox-init tui
Scale/Restart Not Working
Error: Operation failed or no response
Solutions:
-
Check process is enabled:
processes: worker: enabled: true # Must be true -
Verify no config errors:
cbox-init check-config --strict -
Check API logs:
# Look for API errors in Cbox logs journalctl -u cbox-init -f
Examples
Local Development
# Start Cbox Init with TUI-ready config
./cbox-init serve --config dev.yaml
# In another terminal, launch TUI
./cbox-init tui
# Auto-detects socket at /tmp/cbox-init.sock
Remote Production Monitoring
# From local machine, connect to production server
cbox-init tui \
--url https://prod-server.example.com:9180 \
--auth "${CBOX_INIT_PROD_TOKEN}"
# Monitor processes, view logs, scale workers as needed
Docker Container Access
# Exec into running container
docker exec -it my-app /bin/sh
# Launch TUI inside container
cbox-init tui
# Uses Unix socket /var/run/cbox-init.sock
Advanced Features
Log Streaming
Real-time log viewing:
- Navigate to process and press
Enter - Logs stream in real-time (tail mode)
- Scroll with
↑/↓orj/k - Jump to top with
g, bottom withG - Press
Escto return to process list
Features:
- Automatic scrolling (tail -f style)
- Color-coded log levels (ERROR=red, WARN=yellow, etc.)
- Multi-line log reassembly (stack traces)
- Search/filter (coming soon)
Bulk Operations
Scale multiple workers:
- Scale
queue-defaultfrom 3→5 (+) - Return to list
- Scale
queue-emailsfrom 2→4 (+) - All changes persist automatically
Quick restart all:
- Restart each process individually
- Changes apply immediately
- Health checks validate restart success
Integration with API
The TUI uses the Management API under the hood:
| TUI Action | API Call | Endpoint |
|---|---|---|
| List processes | GET | /api/v1/processes |
| Restart process | POST | /api/v1/processes/{name}/restart |
| Stop process | POST | /api/v1/processes/{name}/stop |
| Start process | POST | /api/v1/processes/{name}/start |
| Scale process | POST | /api/v1/processes/{name}/scale |
| Add process | POST | /api/v1/processes |
| Save config | POST | /api/v1/config/save |
See Management API for API documentation.
Next Steps
- Management API - REST API documentation
- Configuration - API configuration reference
- Process Scaling - Scaling strategies and patterns