-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.sh
More file actions
executable file
·151 lines (128 loc) · 4.55 KB
/
Copy pathstart.sh
File metadata and controls
executable file
·151 lines (128 loc) · 4.55 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
#!/bin/bash
# Startup script for Invictus-plan
# Starts both backend (FastAPI) and frontend (Next.js) servers
# Don't exit on error for port killing (it's okay if ports are already free)
# We'll use set -e after initial cleanup
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Get the directory where this script is located
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "$SCRIPT_DIR"
echo -e "${BLUE}========================================${NC}"
echo -e "${BLUE} Invictus-plan Startup Script${NC}"
echo -e "${BLUE}========================================${NC}"
echo ""
# Function to kill process on a port
kill_port() {
local port=$1
local name=$2
echo -e "${YELLOW}Checking for processes on port ${port} (${name})...${NC}"
# Find and kill processes on the port
local pids=$(lsof -ti:$port 2>/dev/null || true)
if [ -n "$pids" ]; then
echo -e "${YELLOW}Killing existing processes on port ${port}...${NC}"
echo "$pids" | xargs kill -9 2>/dev/null || true
sleep 1
echo -e "${GREEN}✓ Port ${port} cleared${NC}"
else
echo -e "${GREEN}✓ Port ${port} is free${NC}"
fi
}
# Kill existing processes
echo -e "${BLUE}Step 1: Cleaning up existing processes...${NC}"
kill_port 8000 "Backend"
kill_port 3000 "Frontend"
echo ""
# Enable exit on error for critical checks
set -e
# Check if virtual environment exists
if [ ! -d "venv" ]; then
echo -e "${RED}Error: Virtual environment not found at venv/${NC}"
echo -e "${YELLOW}Please create it first: python3 -m venv venv${NC}"
exit 1
fi
# Check if venv Python exists
VENV_PYTHON="$SCRIPT_DIR/venv/bin/python"
if [ ! -f "$VENV_PYTHON" ]; then
echo -e "${RED}Error: Python not found in venv at $VENV_PYTHON${NC}"
exit 1
fi
# Check if node_modules exists
if [ ! -d "frontend/node_modules" ]; then
echo -e "${YELLOW}Warning: Frontend node_modules not found${NC}"
echo -e "${YELLOW}Installing frontend dependencies...${NC}"
cd frontend
npm install
cd ..
fi
# Create log directory
LOG_DIR="$SCRIPT_DIR/logs"
mkdir -p "$LOG_DIR"
# Start backend
echo -e "${BLUE}Step 2: Starting backend server (port 8000)...${NC}"
cd "$SCRIPT_DIR/backend"
"$VENV_PYTHON" -m uvicorn main:app --host 0.0.0.0 --port 8000 --reload > "$LOG_DIR/backend.log" 2>&1 &
BACKEND_PID=$!
echo -e "${GREEN}✓ Backend started (PID: $BACKEND_PID)${NC}"
echo -e "${YELLOW} Logs: $LOG_DIR/backend.log${NC}"
# Wait a moment for backend to start
sleep 2
# Verify backend is running
if ! curl -s http://localhost:8000/ > /dev/null 2>&1; then
echo -e "${RED}Warning: Backend may not have started correctly${NC}"
echo -e "${YELLOW}Check logs: tail -f $LOG_DIR/backend.log${NC}"
else
echo -e "${GREEN}✓ Backend is responding${NC}"
fi
# Start frontend
echo -e "${BLUE}Step 3: Starting frontend server (port 3000)...${NC}"
cd "$SCRIPT_DIR/frontend"
npm run dev > "$LOG_DIR/frontend.log" 2>&1 &
FRONTEND_PID=$!
echo -e "${GREEN}✓ Frontend started (PID: $FRONTEND_PID)${NC}"
echo -e "${YELLOW} Logs: $LOG_DIR/frontend.log${NC}"
# Wait a moment for frontend to start
sleep 3
# Verify frontend is running
if ! curl -s http://localhost:3000/ > /dev/null 2>&1; then
echo -e "${RED}Warning: Frontend may not have started correctly${NC}"
echo -e "${YELLOW}Check logs: tail -f $LOG_DIR/frontend.log${NC}"
else
echo -e "${GREEN}✓ Frontend is responding${NC}"
fi
echo ""
echo -e "${GREEN}========================================${NC}"
echo -e "${GREEN} Servers are running!${NC}"
echo -e "${GREEN}========================================${NC}"
echo ""
echo -e "${BLUE}Backend:${NC} http://localhost:8000"
echo -e "${BLUE}Frontend:${NC} http://localhost:3000"
echo -e "${BLUE}API Docs:${NC} http://localhost:8000/docs"
echo ""
echo -e "${YELLOW}Process IDs:${NC}"
echo -e " Backend: $BACKEND_PID"
echo -e " Frontend: $FRONTEND_PID"
echo ""
echo -e "${YELLOW}To stop servers:${NC}"
echo -e " kill $BACKEND_PID $FRONTEND_PID"
echo -e " or run: ./stop.sh"
echo ""
echo -e "${YELLOW}To view logs:${NC}"
echo -e " Backend: tail -f $LOG_DIR/backend.log"
echo -e " Frontend: tail -f $LOG_DIR/frontend.log"
echo ""
# Save PIDs to file for stop script
echo "$BACKEND_PID $FRONTEND_PID" > "$LOG_DIR/pids.txt"
# Option to follow logs (only if running in interactive terminal)
if [ -t 0 ]; then
read -p "Follow logs? (y/n) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo -e "${BLUE}Following logs (Ctrl+C to exit)...${NC}"
tail -f "$LOG_DIR/backend.log" "$LOG_DIR/frontend.log"
fi
fi