-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.sh
More file actions
executable file
·163 lines (134 loc) · 4.26 KB
/
start.sh
File metadata and controls
executable file
·163 lines (134 loc) · 4.26 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
#!/usr/bin/env bash
set -euo pipefail
echo "=========================================="
echo " Starting Mini-OpenClaw System (uv)"
echo "=========================================="
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
print_status() {
echo -e "${GREEN}[STATUS]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PIDS_FILE="${ROOT_DIR}/.pids"
BACKEND_LOG="${ROOT_DIR}/backend.log"
FRONTEND_LOG="${ROOT_DIR}/frontend.log"
cleanup() {
print_status "Shutting down services..."
if [[ -f "${PIDS_FILE}" ]]; then
# shellcheck disable=SC1090
source "${PIDS_FILE}" || true
[[ -n "${BACKEND_PID:-}" ]] && kill "${BACKEND_PID}" 2>/dev/null || true
[[ -n "${FRONTEND_PID:-}" ]] && kill "${FRONTEND_PID}" 2>/dev/null || true
rm -f "${PIDS_FILE}"
fi
print_status "Services stopped."
}
trap cleanup INT TERM
check_command() {
local cmd="$1"
local msg="$2"
if ! command -v "${cmd}" >/dev/null 2>&1; then
print_error "${msg}"
exit 1
fi
}
check_dependencies() {
print_status "Checking dependencies..."
check_command python3 "Python3 is not installed. Please install Python 3.10+."
check_command node "Node.js is not installed. Please install Node.js 18+."
check_command npm "npm is not installed."
check_command uv "uv is not installed. Install from: https://docs.astral.sh/uv/getting-started/installation/"
# Python version check
local py_major py_minor
py_major="$(python3 -c 'import sys; print(sys.version_info.major)')"
py_minor="$(python3 -c 'import sys; print(sys.version_info.minor)')"
if [[ "${py_major}" -lt 3 || ( "${py_major}" -eq 3 && "${py_minor}" -lt 10 ) ]]; then
print_error "Python 3.10 or higher is required."
exit 1
fi
# Node version check
local node_major
node_major="$(node -v | sed 's/^v//' | cut -d. -f1)"
if [[ "${node_major}" -lt 18 ]]; then
print_warning "Node.js 18+ is recommended. Detected: $(node -v)"
fi
print_status "Dependencies check passed."
}
setup_backend() {
print_status "Syncing Python dependencies with uv..."
cd "${ROOT_DIR}"
# Sync dev deps too so pytest/tools are available
uv sync --all-groups
if [[ ! -f "${ROOT_DIR}/backend/.env" ]]; then
if [[ -f "${ROOT_DIR}/backend/.env.example" ]]; then
print_warning "backend/.env not found. Creating from backend/.env.example..."
cp "${ROOT_DIR}/backend/.env.example" "${ROOT_DIR}/backend/.env"
echo "Please edit backend/.env and set OPENAI_API_KEY before using chat features."
else
print_warning "backend/.env.example not found. Create backend/.env manually."
fi
fi
}
setup_frontend() {
print_status "Setting up frontend..."
cd "${ROOT_DIR}/frontend"
if [[ ! -d "node_modules" ]]; then
print_status "Installing Node.js dependencies..."
npm install
else
print_status "Node.js dependencies already present."
fi
}
start_services() {
print_status "Starting services..."
# Start backend
print_status "Starting backend server (port 8002)..."
cd "${ROOT_DIR}"
nohup uv run uvicorn backend.app:app --host 0.0.0.0 --port 8002 --reload > "${BACKEND_LOG}" 2>&1 &
BACKEND_PID=$!
# Wait for backend to initialize
sleep 3
# Start frontend
print_status "Starting frontend server (port 3000)..."
cd "${ROOT_DIR}/frontend"
nohup npm run dev > "${FRONTEND_LOG}" 2>&1 &
FRONTEND_PID=$!
# Persist PIDs
{
echo "BACKEND_PID=${BACKEND_PID}"
echo "FRONTEND_PID=${FRONTEND_PID}"
} > "${PIDS_FILE}"
print_status "Services started."
echo ""
echo "=========================================="
echo " Services are running!"
echo "=========================================="
echo "Frontend: http://localhost:3000"
echo "Backend API:http://localhost:8002"
echo "API Docs: http://localhost:8002/docs"
echo ""
echo "Logs:"
echo " Backend: tail -f ${BACKEND_LOG}"
echo " Frontend: tail -f ${FRONTEND_LOG}"
echo ""
echo "To stop: ./stop.sh (or Ctrl+C in this terminal)"
echo "=========================================="
}
main() {
check_dependencies
setup_backend
setup_frontend
start_services
print_status "Press Ctrl+C to stop services..."
wait
}
main "$@"