| 1 | set -e |
| 2 | PVE="ssh -o ConnectTimeout=10 root@REDACTED-IP" |
| 3 | SHARE=/shared/projects/darwin/cortex |
| 4 | |
| 5 | echo "=== 1. patch adapters to env-driven ===" |
| 6 | cd "$SHARE/adapters" |
| 7 | for pair in "rag:9876" "cbm:9877" "serena:9878" "memgraph:9879"; do |
| 8 | name=${pair%%:*}; port=${pair |
| 9 | grep -q "^import os" "$name.py" || sed -i '/^from __future__ import annotations$/a import os' "$name.py" |
| 10 | sed -i "s|^${NAME}_URL = \"http://127.0.0.1:${port}/sse\"|${NAME}_URL = os.environ.get(\"${NAME}_URL\", \"http://127.0.0.1:${port}/sse\")|" "$name.py" |
| 11 | done |
| 12 | echo "--- patched URL lines ---"; grep -nE "_URL = os.environ" *.py |
| 13 | |
| 14 | echo "=== 2. re-package + ship to CT252 (keep existing .venv) ===" |
| 15 | tar czf /tmp/darwin-cortex.tgz --exclude='.venv' --exclude='__pycache__' -C /shared/projects/darwin cortex |
| 16 | cat /tmp/darwin-cortex.tgz | $PVE "cat > /tmp/darwin-cortex.tgz" |
| 17 | $PVE "pct push 252 /tmp/darwin-cortex.tgz /tmp/darwin-cortex.tgz && pct exec 252 -- tar xzf /tmp/darwin-cortex.tgz -C /opt/darwin" |
| 18 | |
| 19 | echo "=== 3. write /opt/darwin/.env ===" |
| 20 | cat <<'ENVEOF' | $PVE "pct exec 252 -- tee /opt/darwin/.env >/dev/null" |
| 21 | RAG_BRIDGE_URL=http://REDACTED-IP:9875 |
| 22 | RAG_URL=http://REDACTED-IP:9876/sse |
| 23 | CBM_URL=http://REDACTED-IP:9877/sse |
| 24 | SERENA_URL=http://REDACTED-IP:9878/sse |
| 25 | MEMGRAPH_URL=http://REDACTED-IP:9879/sse |
| 26 | MEMOS_BASE_URL=http://REDACTED-IP:5230 |
| 27 | MEMOS_ACCESS_TOKEN=memos_pat_0i7mGB8payehc01j6hW2MJDEOuZ2MVDo |
| 28 | DARWIN_QWEN_URL=http://REDACTED-IP:11434/api/chat |
| 29 | DARWIN_QWEN_MODEL=qwen2.5:7b |
| 30 | DARWIN_QWEN_TIMEOUT=20 |
| 31 | DARWIN_QWEN_KEEP_ALIVE=30m |
| 32 | ENVEOF |
| 33 | |
| 34 | echo "=== 4. write systemd unit ===" |
| 35 | cat <<'SVCEOF' | $PVE "pct exec 252 -- tee /etc/systemd/system/darwin-cortex.service >/dev/null" |
| 36 | [Unit] |
| 37 | Description=Darwin Cortex Gateway |
| 38 | After=network.target |
| 39 | [Service] |
| 40 | Type=simple |
| 41 | WorkingDirectory=/opt/darwin/cortex |
| 42 | EnvironmentFile=/opt/darwin/.env |
| 43 | ExecStart=/opt/darwin/cortex/.venv/bin/uvicorn main:app --host 0.0.0.0 --port 9890 |
| 44 | Restart=always |
| 45 | RestartSec=3 |
| 46 | [Install] |
| 47 | WantedBy=multi-user.target |
| 48 | SVCEOF |
| 49 | |
| 50 | echo "=== 5. import check + enable + start ===" |
| 51 | $PVE "pct exec 252 -- bash -c 'cd /opt/darwin/cortex && . .venv/bin/activate && python -c \"import main\" && echo IMPORT_OK'" |
| 52 | $PVE "pct exec 252 -- bash -c 'systemctl daemon-reload && systemctl enable --now darwin-cortex && sleep 5 && systemctl is-active darwin-cortex'" |
| 53 | |
| 54 | echo "=== 6. verify /health (CT252 localhost) ===" |
| 55 | $PVE "pct exec 252 -- bash -c 'curl -s -m 8 http://127.0.0.1:9890/health || echo HEALTH_FAIL'"; echo |
| 56 | echo "=== 7. verify /health over LAN from CT215 ===" |
| 57 | curl -s -m 8 http://REDACTED-IP:9890/health || echo LAN_HEALTH_FAIL; echo |
| 58 | echo "=== 8. live /ask smoke (Hermes status - the origin bug) ===" |
| 59 | curl -s -m 20 -X POST http://REDACTED-IP:9890/ask -H 'Content-Type: application/json' -d '{"query":"what is the current status of Hermes","mode":"both","k":5}' | head -c 2000; echo |
| 60 | echo "=== DARWIN CORTEX DEPLOY COMPLETE ===" |