-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.sh
More file actions
executable file
·174 lines (152 loc) · 6.98 KB
/
start.sh
File metadata and controls
executable file
·174 lines (152 loc) · 6.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#!/usr/bin/env bash
# ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
# SerialAgent — one-click build & launch
# ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
# Usage:
# ./start.sh — build & open in browser
# ./start.sh --tauri — build & open Tauri desktop app
set -euo pipefail
ROOT="$(cd "$(dirname "$0")" && pwd)"
cd "$ROOT"
GATEWAY_PORT=3210
MEMORY_PORT=4545
LOG_DIR="$ROOT/data/logs"
TAURI=false
mkdir -p "$LOG_DIR"
# ── Parse flags ───────────────────────────────────────────────────────
for arg in "$@"; do
case "$arg" in
--tauri) TAURI=true ;;
esac
done
# ── Colors ────────────────────────────────────────────────────────────
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
CYAN='\033[0;36m'
NC='\033[0m'
log() { echo -e "${CYAN}[serialagent]${NC} $1"; }
ok() { echo -e "${GREEN}[✓]${NC} $1"; }
warn() { echo -e "${YELLOW}[!]${NC} $1"; }
# ── 1. Check SerialMemory ────────────────────────────────────────────
if ss -tlnp 2>/dev/null | grep -q ":${MEMORY_PORT} "; then
ok "SerialMemory already running on :${MEMORY_PORT}"
else
MEMORY_DIR="$HOME/Projects/SerialMemoryServer"
if [ -d "$MEMORY_DIR" ]; then
log "Starting SerialMemory..."
(cd "$MEMORY_DIR" && nohup cargo run --release > "$LOG_DIR/serialmemory.log" 2>&1 &)
sleep 3
if ss -tlnp 2>/dev/null | grep -q ":${MEMORY_PORT} "; then
ok "SerialMemory started on :${MEMORY_PORT}"
else
warn "SerialMemory may still be building — check $LOG_DIR/serialmemory.log"
fi
else
warn "SerialMemory not found at $MEMORY_DIR — skipping (memory features disabled)"
fi
fi
# ── 1b. Check SearXNG ─────────────────────────────────────────────────
if ss -tlnp 2>/dev/null | grep -q ":8080 "; then
ok "SearXNG already running on :8080"
else
if [ -f "$ROOT/deploy/docker-compose.yml" ]; then
log "Starting SearXNG..."
(cd "$ROOT/deploy" && docker compose up -d 2>&1 | tail -1)
sleep 3
if ss -tlnp 2>/dev/null | grep -q ":8080 "; then
ok "SearXNG started on :8080"
else
warn "SearXNG may still be starting"
fi
else
warn "deploy/docker-compose.yml not found — SearXNG not available"
fi
fi
# ── 1c. Check OpenBB ─────────────────────────────────────────────────
if ss -tlnp 2>/dev/null | grep -q ":6900 "; then
ok "OpenBB already running on :6900"
else
OPENBB_BIN="$HOME/.local/openbb-venv/bin/openbb-api"
if [ -x "$OPENBB_BIN" ]; then
log "Starting OpenBB..."
nohup "$OPENBB_BIN" --port 6900 --host 0.0.0.0 > "$LOG_DIR/openbb.log" 2>&1 &
sleep 5
if ss -tlnp 2>/dev/null | grep -q ":6900 "; then
ok "OpenBB started on :6900"
else
warn "OpenBB may still be starting — check $LOG_DIR/openbb.log"
fi
else
warn "OpenBB not installed — run: python3 -m venv ~/.local/openbb-venv && ~/.local/openbb-venv/bin/pip install openbb-platform-api"
fi
fi
# ── Tauri mode: let `cargo tauri dev` handle everything ──────────────
if [ "$TAURI" = true ]; then
# Build gateway (Tauri dev needs it running separately)
log "Building gateway..."
cargo build --release -p sa-gateway 2>&1 | tail -1
ok "Gateway built"
# Stop old gateway if running
if ss -tlnp 2>/dev/null | grep -q ":${GATEWAY_PORT} "; then
log "Stopping old gateway..."
pkill -f "serialagent serve" 2>/dev/null || true
sleep 1
fi
# Start gateway in background
log "Starting gateway..."
nohup ./target/release/serialagent serve > "$LOG_DIR/gateway.log" 2>&1 &
for i in $(seq 1 10); do
if ss -tlnp 2>/dev/null | grep -q ":${GATEWAY_PORT} "; then break; fi
sleep 0.5
done
ok "Gateway running on :${GATEWAY_PORT}"
# Launch Tauri desktop app (blocks until window closes)
log "Launching Tauri desktop app..."
cd apps/dashboard
npx tauri dev 2>&1
exit 0
fi
# ── Browser mode (default) ───────────────────────────────────────────
# ── 2. Build dashboard ───────────────────────────────────────────────
log "Building dashboard..."
(cd apps/dashboard && npm run build --silent 2>&1) || {
warn "Dashboard build failed — gateway will run without UI"
}
ok "Dashboard built"
# ── 3. Build gateway ─────────────────────────────────────────────────
log "Building gateway..."
cargo build --release -p sa-gateway 2>&1 | tail -1
ok "Gateway built"
# ── 4. Stop old gateway if running ───────────────────────────────────
if ss -tlnp 2>/dev/null | grep -q ":${GATEWAY_PORT} "; then
log "Stopping old gateway..."
pkill -f "serialagent serve" 2>/dev/null || true
sleep 1
fi
# ── 5. Start gateway ─────────────────────────────────────────────────
log "Starting gateway..."
nohup ./target/release/serialagent serve > "$LOG_DIR/gateway.log" 2>&1 &
GATEWAY_PID=$!
# Wait for it to bind
for i in $(seq 1 10); do
if ss -tlnp 2>/dev/null | grep -q ":${GATEWAY_PORT} "; then
break
fi
sleep 0.5
done
if ss -tlnp 2>/dev/null | grep -q ":${GATEWAY_PORT} "; then
ok "Gateway running on http://127.0.0.1:${GATEWAY_PORT} (PID $GATEWAY_PID)"
else
warn "Gateway failed to start — check $LOG_DIR/gateway.log"
exit 1
fi
# ── 6. Open browser ──────────────────────────────────────────────────
URL="http://localhost:${GATEWAY_PORT}/app"
log "Opening $URL"
xdg-open "$URL" 2>/dev/null || open "$URL" 2>/dev/null || warn "Open $URL in your browser"
echo ""
ok "SerialAgent is running!"
echo " Dashboard: $URL"
echo " API: http://localhost:${GATEWAY_PORT}/v1/health"
echo " Logs: $LOG_DIR/"
echo " Stop: ./stop.sh"