forked from omnara-ai/omnara
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev-start.sh
More file actions
executable file
·169 lines (144 loc) · 4.58 KB
/
dev-start.sh
File metadata and controls
executable file
·169 lines (144 loc) · 4.58 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
#!/bin/bash
# Development startup script for Agent Dashboard
# Runs PostgreSQL in Docker, everything else locally for live development
set -e
# Parse command line arguments
RESET_DB=false
while [[ $# -gt 0 ]]; do
case $1 in
--reset-db)
RESET_DB=true
shift
;;
*)
echo "Unknown option: $1"
echo "Usage: $0 [--reset-db]"
exit 1
;;
esac
done
echo "🚀 Starting Agent Dashboard in development mode..."
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Function to cleanup on exit
cleanup() {
echo -e "\n${YELLOW}Cleaning up...${NC}"
# Kill background processes
if [[ -n $VIEWER_PID ]]; then
echo "Stopping relay viewer..."
kill $VIEWER_PID 2>/dev/null || true
wait $VIEWER_PID 2>/dev/null || true
fi
if [[ -n $RELAY_PID ]]; then
echo "Stopping relay server..."
kill $RELAY_PID 2>/dev/null || true
wait $RELAY_PID 2>/dev/null || true
fi
if [[ -n $APP_PID ]]; then
echo "Stopping unified server..."
kill $APP_PID 2>/dev/null || true
fi
if [[ -n $BACKEND_PID ]]; then
echo "Stopping backend..."
kill $BACKEND_PID 2>/dev/null || true
fi
echo -e "${GREEN}Cleanup complete${NC}"
exit 0
}
# Set up signal handlers
trap cleanup SIGINT SIGTERM
# Check if Docker is running
if ! sudo docker info > /dev/null 2>&1; then
echo -e "${RED}Error: Docker is not running. Please start Docker first.${NC}"
exit 1
fi
# Set up data directory for PostgreSQL persistence
DATA_DIR="$(pwd)/postgres-data"
if [ "$RESET_DB" = true ]; then
echo -e "${YELLOW}Resetting database...${NC}"
if [ -d "$DATA_DIR" ]; then
echo -e "${YELLOW}Removing existing PostgreSQL data directory...${NC}"
sudo rm -rf "$DATA_DIR"
fi
fi
# Create data directory if it doesn't exist
if [ ! -d "$DATA_DIR" ]; then
echo -e "${BLUE}Creating PostgreSQL data directory...${NC}"
mkdir -p "$DATA_DIR"
fi
# Start PostgreSQL in Docker
echo -e "${BLUE}Starting PostgreSQL in Docker...${NC}"
sudo docker run -d \
--name agent-dashboard-db-dev \
--rm \
-p 5432:5432 \
-e POSTGRES_USER=user \
-e POSTGRES_PASSWORD=password \
-e POSTGRES_DB=agent_dashboard \
-v "$DATA_DIR:/var/lib/postgresql/data" \
postgres:16-alpine > /dev/null
# Wait for PostgreSQL to be ready
echo -e "${YELLOW}Waiting for PostgreSQL to be ready...${NC}"
for i in {1..30}; do
if sudo docker exec agent-dashboard-db-dev pg_isready -U user -d agent_dashboard > /dev/null 2>&1; then
echo -e "${GREEN}PostgreSQL is ready!${NC}"
break
fi
sleep 1
if [ $i -eq 30 ]; then
echo -e "${RED}Error: PostgreSQL failed to start${NC}"
sudo docker stop agent-dashboard-db-dev > /dev/null 2>&1 || true
exit 1
fi
done
# Initialize database
echo -e "${BLUE}Initializing database...${NC}"
export ENVIRONMENT="development"
export DEVELOPMENT_DB_URL="postgresql://user:password@localhost:5432/agent_dashboard"
./infrastructure/scripts/init-db.sh
# Prepare log directory
LOG_DIR="$(pwd)/logs"
mkdir -p "$LOG_DIR"
RELAY_LOG="$LOG_DIR/relay.log"
> "$RELAY_LOG"
VIEWER_LOG="$LOG_DIR/relay-viewer.log"
> "$VIEWER_LOG"
# Start relay server (FastAPI WebSocket)
echo -e "${BLUE}Starting relay WebSocket server...${NC}"
export PYTHONPATH="$(pwd)/src"
python -m relay_server.app >> "$RELAY_LOG" 2>&1 &
RELAY_PID=$!
sleep 2
# Start unified server (MCP + FastAPI)
echo -e "${BLUE}Starting unified server (MCP + FastAPI)...${NC}"
export PYTHONPATH="$(pwd)/src"
export API_PORT=8080
export MCP_SERVER_PORT=8080
python -m servers.app &
APP_PID=$!
# Wait a moment for unified server to start
sleep 2
# Start Backend API
echo -e "${BLUE}Starting Backend API...${NC}"
export PYTHONPATH="$(pwd)/src"
export API_PORT=8000
uvicorn backend.main:app --host 0.0.0.0 --port 8000 &
BACKEND_PID=$!
# Wait a moment for backend to start
sleep 2
echo -e "${GREEN}🎉 All services started successfully!${NC}"
echo -e "${BLUE}Services:${NC}"
echo -e " 🔌 Relay Server: http://localhost:8787 (FastAPI WebSocket)"
echo -e " - WebSocket agent: ws://localhost:8787/agent"
echo -e " - WebSocket viewer: ws://localhost:8787/terminal"
echo -e " 🤖 Unified Server: http://localhost:8080 (MCP + FastAPI)"
echo -e " 🔧 Backend API: http://localhost:8000"
echo -e " 🗄️ PostgreSQL: localhost:5432"
echo -e " 📜 Relay Log: $RELAY_LOG"
echo -e "\n${YELLOW}Press Ctrl+C to stop all services${NC}"
# Wait for all background processes
wait