|
| 1 | +# Deploy zhub on a $5 VPS in 10 minutes |
| 2 | + |
| 3 | +Goal: a stable URL that survives reboots and gives you `https://your-domain/...` on a quiet server you forget about. |
| 4 | + |
| 5 | +This guide assumes Ubuntu 22.04+ on a tiny box (1 vCPU, 512 MB RAM is fine for personal-tier loads). Adapt freely for Debian / Arch / Fedora; the steps are the same. |
| 6 | + |
| 7 | +--- |
| 8 | + |
| 9 | +## 1. Server prep (90 seconds) |
| 10 | + |
| 11 | +```bash |
| 12 | +ssh root@your-vps |
| 13 | +apt update && apt install -y python3-venv python3-pip git curl |
| 14 | +adduser zhub --disabled-password --gecos "" |
| 15 | +su - zhub |
| 16 | +``` |
| 17 | + |
| 18 | +## 2. Install zhub (60 seconds) |
| 19 | + |
| 20 | +```bash |
| 21 | +git clone https://github.com/Zawwarsami16/zhub |
| 22 | +cd zhub |
| 23 | +python3 -m venv .venv && source .venv/bin/activate |
| 24 | +pip install -e '.[server,brains]' |
| 25 | +python -m zhub doctor # sanity check |
| 26 | +``` |
| 27 | + |
| 28 | +## 3. Cloudflare named tunnel — stable URL forever (4 minutes) |
| 29 | + |
| 30 | +A *quick tunnel* (`--public-tunnel`) gives you a random `*.trycloudflare.com` URL that changes every restart. A *named tunnel* keeps the same hostname forever. One-time setup: |
| 31 | + |
| 32 | +```bash |
| 33 | +# install cloudflared (linux/amd64) |
| 34 | +curl -L --output cloudflared.deb \ |
| 35 | + https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64.deb |
| 36 | +sudo dpkg -i cloudflared.deb |
| 37 | + |
| 38 | +# log in once — opens a browser link, you authorize a CF zone you control |
| 39 | +cloudflared tunnel login |
| 40 | + |
| 41 | +# create a named tunnel (does NOT expose anything yet) |
| 42 | +cloudflared tunnel create zhub-prod |
| 43 | +# → Created tunnel zhub-prod with id XYZ |
| 44 | +# → Tunnel credentials written to ~/.cloudflared/XYZ.json |
| 45 | + |
| 46 | +# point a hostname (must be in a CF zone you own) at the tunnel |
| 47 | +cloudflared tunnel route dns zhub-prod hub.example.com |
| 48 | +``` |
| 49 | + |
| 50 | +Now `hub.example.com` is wired to your tunnel. The tunnel itself isn't running yet — that's step 4. |
| 51 | + |
| 52 | +## 4. Run zhub as a systemd service (3 minutes) |
| 53 | + |
| 54 | +Two services: one for the hub + brain publisher, one for the cloudflared tunnel. Both auto-restart on failure. |
| 55 | + |
| 56 | +`/etc/systemd/system/zhub.service`: |
| 57 | + |
| 58 | +```ini |
| 59 | +[Unit] |
| 60 | +Description=zhub hub + brain publisher |
| 61 | +After=network-online.target |
| 62 | +Wants=network-online.target |
| 63 | + |
| 64 | +[Service] |
| 65 | +Type=simple |
| 66 | +User=zhub |
| 67 | +WorkingDirectory=/home/zhub/zhub |
| 68 | +Environment="PATH=/home/zhub/zhub/.venv/bin:/usr/bin" |
| 69 | +# Set whichever brain creds you use: |
| 70 | +Environment="GROQ_API_KEY=gsk_REDACTED" |
| 71 | +ExecStart=/home/zhub/zhub/.venv/bin/python -m zhub up \ |
| 72 | + --no-tunnel --port 8080 --name me \ |
| 73 | + --db /home/zhub/zhub/zhub.db |
| 74 | +Restart=on-failure |
| 75 | +RestartSec=5 |
| 76 | + |
| 77 | +[Install] |
| 78 | +WantedBy=multi-user.target |
| 79 | +``` |
| 80 | + |
| 81 | +`/etc/systemd/system/zhub-tunnel.service`: |
| 82 | + |
| 83 | +```ini |
| 84 | +[Unit] |
| 85 | +Description=cloudflared named tunnel for zhub |
| 86 | +After=zhub.service network-online.target |
| 87 | +Requires=zhub.service |
| 88 | + |
| 89 | +[Service] |
| 90 | +Type=simple |
| 91 | +User=zhub |
| 92 | +ExecStart=/usr/bin/cloudflared tunnel --no-autoupdate run zhub-prod |
| 93 | +Restart=on-failure |
| 94 | +RestartSec=5 |
| 95 | + |
| 96 | +[Install] |
| 97 | +WantedBy=multi-user.target |
| 98 | +``` |
| 99 | + |
| 100 | +Enable + start: |
| 101 | + |
| 102 | +```bash |
| 103 | +sudo systemctl daemon-reload |
| 104 | +sudo systemctl enable --now zhub.service zhub-tunnel.service |
| 105 | +sudo systemctl status zhub.service zhub-tunnel.service |
| 106 | +``` |
| 107 | + |
| 108 | +## 5. Verify (60 seconds) |
| 109 | + |
| 110 | +```bash |
| 111 | +# health |
| 112 | +curl https://hub.example.com/healthz |
| 113 | +# → {"status":"ok","publishers":"1"} |
| 114 | + |
| 115 | +# entity (zhub's self-knowledge) |
| 116 | +curl https://hub.example.com/entity | head -20 |
| 117 | + |
| 118 | +# the AI's manifest |
| 119 | +curl https://hub.example.com/me/manifest.json | jq . |
| 120 | + |
| 121 | +# grab the api key the publisher generated (one-time on first start; |
| 122 | +# stable forever after because of --db persistence) |
| 123 | +sudo journalctl -u zhub.service --no-pager | grep -E "KEY:" | tail -1 |
| 124 | +``` |
| 125 | + |
| 126 | +Paste `https://hub.example.com/me/v1` + the `zk_...` key into Pocket / openai-py / curl / Claude Desktop. Done. |
| 127 | + |
| 128 | +--- |
| 129 | + |
| 130 | +## Operational notes |
| 131 | + |
| 132 | +**Logs.** `journalctl -u zhub.service -f` for live tail. Each request shows up at INFO via the `zhub.access` logger: |
| 133 | + |
| 134 | +``` |
| 135 | +123 GET /healthz 0ms |
| 136 | +200 POST /me/v1/chat/completions 412ms ai=me |
| 137 | +``` |
| 138 | + |
| 139 | +**Metrics.** `curl https://hub.example.com/metrics` returns a JSON snapshot with per-AI request_count, total_latency_ms, max_latency_ms, avg_latency_ms, plus rate-limit / peer-proxy / tool-call counters. Pipe to a collector if you want history. |
| 140 | + |
| 141 | +**Persistence.** `zhub.db` (SQLite) holds publishers + entity extensions. Survives reboots. Back it up the same way you'd back up any small file. |
| 142 | + |
| 143 | +**Updating.** `cd ~/zhub && git pull && pip install -e '.[server,brains]' && sudo systemctl restart zhub.service`. The named tunnel keeps running. |
| 144 | + |
| 145 | +**Resources.** zhub itself is ~30 MB RSS idle. The brain dominates: brain=ollama means a local model burning whatever Ollama burns; brain=groq/openai/cerebras/anthropic means just outbound HTTPS. For a brain-bills-elsewhere setup, a 512 MB / 1 vCPU box runs zhub + cloudflared + a publisher comfortably. |
| 146 | + |
| 147 | +**Multi-AI.** Run more publishers with different `--name`s against the same hub. Each gets its own `zk_` key + URL. The hub doesn't need restart — just spawn another publisher process. |
| 148 | + |
| 149 | +**Rotating the brain.** Stop the publisher service, change `Environment="..."` in the unit file with a new brain's creds, restart. The `zk_` key is preserved (persistence). External clients see no change; brain underneath silently swapped. |
0 commit comments