forked from t8/memoryport
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev.sh
More file actions
executable file
·126 lines (113 loc) · 3.2 KB
/
dev.sh
File metadata and controls
executable file
·126 lines (113 loc) · 3.2 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
#!/usr/bin/env bash
set -e
CONFIG="${UC_CONFIG:-$HOME/.memoryport/uc.toml}"
SERVER_PORT=8090
PROXY_PORT=9191
UI_PORT=5174
RED='\033[0;31m'
GREEN='\033[0;32m'
CYAN='\033[0;36m'
DIM='\033[2m'
NC='\033[0m'
kill_port() {
local port=$1
local pids=$(lsof -i :"$port" -t 2>/dev/null)
if [ -n "$pids" ]; then
echo "$pids" | xargs kill -9 2>/dev/null || true
sleep 0.5
fi
}
status() {
echo ""
for pair in "uc-server:$SERVER_PORT" "uc-proxy:$PROXY_PORT" "ui:$UI_PORT"; do
name="${pair%%:*}"
port="${pair##*:}"
if curl -s -o /dev/null -w "" --connect-timeout 1 "http://localhost:$port/health" 2>/dev/null; then
echo -e " ${GREEN}●${NC} $name ${DIM}:$port${NC}"
else
echo -e " ${RED}●${NC} $name ${DIM}:$port${NC}"
fi
done
echo ""
}
build() {
echo -e "${CYAN}Building...${NC}"
cargo build -p uc-server -p uc-proxy 2>&1 | grep -E "Compiling|Finished|error" || true
}
start_server() {
kill_port $SERVER_PORT
echo -e " Starting uc-server on :$SERVER_PORT"
UC_SERVER_LISTEN="127.0.0.1:$SERVER_PORT" \
nohup ./target/debug/uc-server --config "$CONFIG" \
> /tmp/memoryport-server.log 2>&1 &
echo $! > /tmp/memoryport-server.pid
}
start_proxy() {
kill_port $PROXY_PORT
echo -e " Starting uc-proxy on :$PROXY_PORT"
nohup ./target/debug/uc-proxy --config "$CONFIG" --listen "127.0.0.1:$PROXY_PORT" \
> /tmp/memoryport-proxy.log 2>&1 &
echo $! > /tmp/memoryport-proxy.pid
}
start_ui() {
kill_port $UI_PORT
echo -e " Starting UI dev server on :$UI_PORT"
cd ui && nohup pnpm dev > /tmp/memoryport-ui.log 2>&1 &
echo $! > /tmp/memoryport-ui.pid
cd ..
}
stop_all() {
echo -e "${CYAN}Stopping all services...${NC}"
kill_port $SERVER_PORT
kill_port $PROXY_PORT
kill_port $UI_PORT
echo -e " ${GREEN}All stopped${NC}"
}
start_all() {
echo -e "${CYAN}Starting all services...${NC}"
start_server
sleep 1
start_proxy
start_ui
sleep 3
status
}
restart_all() {
stop_all
sleep 1
build
start_all
}
logs() {
local service="${1:-server}"
case "$service" in
server) tail -f /tmp/memoryport-server.log ;;
proxy) tail -f /tmp/memoryport-proxy.log ;;
ui) tail -f /tmp/memoryport-ui.log ;;
*) echo "Usage: dev.sh logs [server|proxy|ui]" ;;
esac
}
case "${1:-}" in
start) build && start_all ;;
stop) stop_all ;;
restart) restart_all ;;
status) status ;;
build) build ;;
logs) logs "$2" ;;
server) build && kill_port $SERVER_PORT && start_server && sleep 2 && status ;;
proxy) build && kill_port $PROXY_PORT && start_proxy && sleep 2 && status ;;
ui) kill_port $UI_PORT && start_ui && sleep 3 && status ;;
*)
echo "Usage: ./dev.sh {start|stop|restart|status|build|logs|server|proxy|ui}"
echo ""
echo " start - Build and start all services"
echo " stop - Stop all services"
echo " restart - Stop, rebuild, and start all"
echo " status - Show which services are running"
echo " build - Build Rust binaries only"
echo " logs X - Tail logs (server|proxy|ui)"
echo " server - Rebuild and restart just the server"
echo " proxy - Rebuild and restart just the proxy"
echo " ui - Restart just the UI dev server"
;;
esac