/
keorlov
/
collsim
Обзор
Документация
Войти
/
keorlov
/
collsim
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
run.sh
100 строк
3 KB
Konstantin Orlov
wip
13 июл 2026, 09:01
13 июл 2026, 09:01
783d961
Код
Авторство
О чём код?
#!/usr/bin/env bash # CollSim - Run backend and frontend together set -e BACKEND_PORT=5000 FRONTEND_PORT=5173 HOST="0.0.0.0" # Colors GREEN='\033[0;32m' BLUE='\033[0;34m' YELLOW='\033[1;33m' RED='\033[0;31m' NC='\033[0m' # No Color BACKEND_PID="" FRONTEND_PID="" echo -e "${BLUE}=== CollSim Runner ===${NC}" # Check if we're in the right directory if [ ! -f "config.yaml" ]; then echo -e "${RED}Error: Run from project root (where config.yaml is)${NC}" exit 1 fi # Function to cleanup on exit cleanup() { echo -e "\n${YELLOW}Shutting down...${NC}" if [ -n "$BACKEND_PID" ] && kill -0 "$BACKEND_PID" 2>/dev/null; then kill "$BACKEND_PID" 2>/dev/null || true wait "$BACKEND_PID" 2>/dev/null || true fi if [ -n "$FRONTEND_PID" ] && kill -0 "$FRONTEND_PID" 2>/dev/null; then kill "$FRONTEND_PID" 2>/dev/null || true wait "$FRONTEND_PID" 2>/dev/null || true fi echo "Done." } trap cleanup INT TERM EXIT # Start backend echo -e "${GREEN}Starting backend on ${HOST}:${BACKEND_PORT}...${NC}" python -m app --host "$HOST" --port "$BACKEND_PORT" & BACKEND_PID=$! # Wait for backend health echo "Waiting for backend..." for i in {1..60}; do if curl -s "http://localhost:$BACKEND_PORT/health" > /dev/null 2>&1; then echo -e "${GREEN}Backend ready!${NC}" break fi if [ $i -eq 60 ]; then echo -e "${RED}Backend failed to start${NC}" exit 1 fi sleep 0.5 done # Start frontend if available if [ -d "frontend" ] && [ -f "frontend/package.json" ]; then echo -e "${GREEN}Starting frontend on port $FRONTEND_PORT...${NC}" cd frontend if [ ! -d "node_modules" ]; then echo "Installing frontend dependencies..." npm install fi npm run dev -- --port "$FRONTEND_PORT" --host 0.0.0.0 & FRONTEND_PID=$! cd .. echo -e "${GREEN}Frontend started!${NC}" else echo -e "${YELLOW}Frontend not found, running backend only${NC}" fi echo "" echo -e "${BLUE}=== CollSim Running ===${NC}" echo -e "Backend API: ${GREEN}http://localhost:$BACKEND_PORT${NC}" echo -e " POST /simulate" echo -e " GET /health" if [ -n "$FRONTEND_PID" ]; then echo -e "Frontend UI: ${GREEN}http://localhost:$FRONTEND_PORT${NC} (and LAN via --host 0.0.0.0)" fi echo "Press Ctrl+C to stop" echo "" # Wait for processes, handle early exit while true; do if [ -n "$BACKEND_PID" ] && ! kill -0 "$BACKEND_PID" 2>/dev/null; then echo -e "${RED}Backend process exited unexpectedly${NC}" break fi if [ -n "$FRONTEND_PID" ] && ! kill -0 "$FRONTEND_PID" 2>/dev/null; then echo -e "${YELLOW}Frontend process exited${NC}" break fi sleep 1 done