# llama-swap — Operations

## Upgrading llama-swap

llama-swap is a statically compiled Go binary — upgrade is a simple binary swap.

```bash
# Check current version
llama-swap --version

# Download latest from GitHub
cd /tmp
curl -sLO "https://github.com/mostlygeek/llama-swap/releases/latest/download/llama-swap_linux_amd64.tar.gz"
tar xzf llama-swap_linux_amd64.tar.gz
./llama-swap --version   # verify

# Install (backup old first)
sudo cp /usr/local/bin/llama-swap /usr/local/bin/llama-swap-v<OLD_VERSION>
sudo mv ./llama-swap /usr/local/bin/llama-swap
sudo chmod +x /usr/local/bin/llama-swap

# Restart service
sudo systemctl restart llama-swap
sleep 3
systemctl status llama-swap
curl -s http://127.0.0.1:9292/v1/models | python3 -c "import sys,json; [print(f'  - {m[\"id\"]}') for m in json.load(sys.stdin).get('data',[])]"
```

## Verification Endpoints
```bash
curl http://localhost:9292/v1/models                    # list models
curl http://localhost:9292/v1/chat/completions           # test (cold load ~30-90s)
curl http://localhost:9292/ui                            # web UI
curl http://localhost:9292/running                       # active model (process args)
curl -X POST http://localhost:9292/api/models/unload     # manual unload
```

## Hermes Migration to llama-swap

1. Disable legacy path watcher: `systemctl --user disable hermes-config.path`
2. Disable old per-model `llama-server*.service` units
3. Add llama-swap `aliases:` matching Hermes friendly names
4. If keeping a cron watchdog, check `llama-swap.service` + :9292/v1/models
5. Archive: `auto-model-switch.py`, `model-switcher`, `quick-start-model.py`, old units
6. Verify with: `hermes chat -Q --provider custom:local --model '<name>' -q 'Reply with OK'`

## Port Allocation on This Host

| Port | Service | Binds |
|------|---------|-------|
| :80 | Nginx (WebUI proxy) | 0.0.0.0 |
| :443 | Tailscale Funnel (scraper) | 100.x.x.x |
| :3081 | Open WebUI | 127.0.0.1 |
| :3091 | Nexstream Scraper | 0.0.0.0 |
| :8080 | SearXNG | 127.0.0.1 |
| :9292 | llama-swap | 0.0.0.0 |

## Fleet Verification
```bash
# llama-swap health
systemctl status llama-swap.service
curl -s http://127.0.0.1:9292/v1/models | jq '.data[].id'

# Path + config cross-reference
python3 scripts/cross-ref-audit.py

# Port audit
sudo ss -tlnp | grep -E '9292|llama'

# VRAM
nvidia-smi --query-gpu=memory.used,memory.total --format=csv,noheader

# System tuning health
cat /sys/kernel/mm/transparent_hugepage/enabled
cat /proc/$(pgrep llama-swap)/limits | grep -E "open files|locked memory"
```

## Quick Reference
- **Switch chain:** Hermes → llama-swap :9292 → auto-starts model on its own port
- **Three-way alignment:** Disk → llama-swap config → Hermes custom_providers
- **Local-first rule:** Start local, escalate only when needed
- **VRAM rule:** 3s drain on local→local; llama-swap handles automatically
- **Diagnosis rule:** Is `llama-swap.service` running? Port :9292 respond to /v1/models?
- **System tuning:** THP→madvise, nofile→65536, memlock=infinity
