-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.sh
More file actions
executable file
Β·167 lines (141 loc) Β· 4.68 KB
/
start.sh
File metadata and controls
executable file
Β·167 lines (141 loc) Β· 4.68 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
#!/bin/bash
# Documentation.AI - Start Script
echo "π Starting Documentation.AI..."
# Colors for output
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m' # No Color
# Function to cleanup on exit
cleanup() {
echo -e "\n${YELLOW}π Stopping servers...${NC}"
if [ ! -z "$BACKEND_PID" ]; then
kill $BACKEND_PID 2>/dev/null
echo -e "${GREEN}β
Backend server stopped${NC}"
fi
if [ ! -z "$FRONTEND_PID" ]; then
kill $FRONTEND_PID 2>/dev/null
echo -e "${GREEN}β
Frontend server stopped${NC}"
fi
echo -e "${GREEN}π Documentation.AI stopped successfully!${NC}"
exit 0
}
# Set up signal handlers
trap cleanup SIGINT SIGTERM
# Check dependencies
if ! command -v python3 &> /dev/null; then
echo -e "${RED}β Python 3 is not installed.${NC}"
exit 1
fi
if ! command -v node &> /dev/null; then
echo -e "${RED}β Node.js is not installed.${NC}"
exit 1
fi
echo -e "${GREEN}β
Dependencies found${NC}"
# Setup Python environment
if [ ! -d ".venv" ]; then
echo -e "${BLUE}π¦ Creating virtual environment...${NC}"
python3 -m venv .venv
fi
echo -e "${BLUE}π§ Activating virtual environment...${NC}"
source .venv/bin/activate
# Install Python dependencies if needed
if [ ! -f ".venv/.last_install" ] || [ "requirements.txt" -nt ".venv/.last_install" ]; then
echo -e "${BLUE}οΏ½ Installing Python dependencies...${NC}"
pip install -r requirements.txt
touch .venv/.last_install
fi
# Setup environment file
if [ ! -f .env ]; then
echo -e "${YELLOW}π Creating .env file...${NC}"
cp .env.example .env
echo -e "${YELLOW}β οΈ Please edit .env file with your API keys${NC}"
fi
# Setup frontend dependencies if needed
if [ ! -d "frontend/node_modules" ]; then
echo -e "${BLUE}π¦ Installing frontend dependencies...${NC}"
cd frontend
npm install
cd ..
fi
# Start backend server
echo -e "${BLUE}π― Starting backend server...${NC}"
python app.py > backend.log 2>&1 &
BACKEND_PID=$!
# Wait for backend to start
sleep 3
# Start frontend server
echo -e "${BLUE}π― Starting frontend server...${NC}"
cd frontend
npm start > ../frontend.log 2>&1 &
FRONTEND_PID=$!
cd ..
echo ""
echo -e "${GREEN}π Documentation.AI is running!${NC}"
echo ""
echo -e "${BLUE}π± Access Points:${NC}"
echo -e " Frontend: ${GREEN}http://localhost:3000${NC}"
echo -e " Backend: ${GREEN}http://localhost:5002${NC}"
echo ""
echo -e "${YELLOW}Press Ctrl+C to stop both servers${NC}"
# Wait for processes
wait
else
echo -e "${YELLOW}β οΈ Full app startup failed, starting simplified server...${NC}"
# Kill the failed process
kill $BACKEND_PID 2>/dev/null
# Start simple server
python app_simple.py > backend.log 2>&1 &
BACKEND_PID=$!
sleep 5
if curl -s http://localhost:5001/ > /dev/null 2>&1; then
echo -e "${GREEN}β
Simplified backend server started successfully${NC}"
echo -e "${YELLOW}π Note: AI features are disabled in simplified mode${NC}"
else
echo -e "${RED}β Even simplified server failed to start.${NC}"
echo -e "${YELLOW}π Backend log contents:${NC}"
cat backend.log
cleanup
fi
fi
# Start frontend server in background
echo -e "${BLUE}π― Starting frontend server on http://localhost:3000...${NC}"
cd frontend
PORT=3000 npm start > ../frontend.log 2>&1 &
FRONTEND_PID=$!
cd ..
# Wait a moment for frontend to start
sleep 8
# Check if frontend started successfully
if ! curl -s http://localhost:3000 > /dev/null; then
echo -e "${YELLOW}β οΈ Frontend server may still be starting up...${NC}"
fi
echo -e "${GREEN}β
Frontend server started${NC}"
echo ""
echo -e "${CYAN}π Documentation.AI is now running!${NC}"
echo ""
echo -e "${BLUE}π± Access your application:${NC}"
echo -e " ${CYAN}Frontend (Main App): http://localhost:3000${NC}"
echo -e " ${CYAN}Backend API: http://localhost:5001${NC}"
echo -e " ${CYAN}API Health Check: http://localhost:5001/api/health${NC}"
echo ""
echo -e "${YELLOW}π Useful commands:${NC}"
echo -e " ${CYAN}View backend logs: tail -f backend.log${NC}"
echo -e " ${CYAN}View frontend logs: tail -f frontend.log${NC}"
echo ""
echo -e "${GREEN}π¨ Press Ctrl+C to stop both servers${NC}"
echo ""
# Keep script running and wait for user to stop
while true; do
# Check if processes are still running
if ! kill -0 $BACKEND_PID 2>/dev/null; then
echo -e "${RED}β Backend server stopped unexpectedly. Check backend.log${NC}"
cleanup
fi
if ! kill -0 $FRONTEND_PID 2>/dev/null; then
echo -e "${RED}β Frontend server stopped unexpectedly. Check frontend.log${NC}"
cleanup
fi
sleep 5
done