feat: Add development scripts for environment check and service management
- check-env.sh: Validates Python 3.10+, Node.js, Docker, venv, .env, ports - start-dev.sh: Starts MinIO, backend, frontend with health checks - stop-dev.sh: Gracefully stops all services Scripts are placed in project root for easy access. Supports --help flag and colored output. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
193
stop-dev.sh
Executable file
193
stop-dev.sh
Executable file
@@ -0,0 +1,193 @@
|
||||
#!/bin/bash
|
||||
# ============================================================================
|
||||
# Development Server Stop Script for Task Reporter
|
||||
# Gracefully stops all services: Frontend, Backend, MinIO
|
||||
# ============================================================================
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Script directory (scripts are in project root)
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
PROJECT_ROOT="$SCRIPT_DIR"
|
||||
|
||||
# PID file locations
|
||||
PID_DIR="$PROJECT_ROOT/.pids"
|
||||
BACKEND_PID_FILE="$PID_DIR/backend.pid"
|
||||
FRONTEND_PID_FILE="$PID_DIR/frontend.pid"
|
||||
|
||||
# Helper functions
|
||||
print_header() {
|
||||
echo -e "\n${BLUE}=== $1 ===${NC}"
|
||||
}
|
||||
|
||||
print_ok() {
|
||||
echo -e "${GREEN}[OK]${NC} $1"
|
||||
}
|
||||
|
||||
print_error() {
|
||||
echo -e "${RED}[ERROR]${NC} $1"
|
||||
}
|
||||
|
||||
print_warn() {
|
||||
echo -e "${YELLOW}[WARN]${NC} $1"
|
||||
}
|
||||
|
||||
print_info() {
|
||||
echo -e "${BLUE}[INFO]${NC} $1"
|
||||
}
|
||||
|
||||
# Show help
|
||||
show_help() {
|
||||
echo "Usage: $0 [OPTIONS]"
|
||||
echo ""
|
||||
echo "Stops all development services for Task Reporter."
|
||||
echo ""
|
||||
echo "Options:"
|
||||
echo " -h, --help Show this help message"
|
||||
echo " --keep-minio Don't stop MinIO container"
|
||||
echo " --keep-data Alias for --keep-minio"
|
||||
echo ""
|
||||
echo "Services stopped:"
|
||||
echo " - Frontend (Vite dev server)"
|
||||
echo " - Backend (uvicorn)"
|
||||
echo " - MinIO (Docker container)"
|
||||
}
|
||||
|
||||
# Parse arguments
|
||||
KEEP_MINIO=false
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
-h|--help)
|
||||
show_help
|
||||
exit 0
|
||||
;;
|
||||
--keep-minio|--keep-data)
|
||||
KEEP_MINIO=true
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
echo "Unknown option: $1"
|
||||
show_help
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
echo -e "${BLUE}============================================${NC}"
|
||||
echo -e "${BLUE} Task Reporter - Stopping Services${NC}"
|
||||
echo -e "${BLUE}============================================${NC}"
|
||||
|
||||
# ============================================================================
|
||||
# Stop Frontend
|
||||
# ============================================================================
|
||||
print_header "Stopping Frontend"
|
||||
|
||||
if [[ -f "$FRONTEND_PID_FILE" ]]; then
|
||||
FRONTEND_PID=$(cat "$FRONTEND_PID_FILE")
|
||||
if kill -0 "$FRONTEND_PID" 2>/dev/null; then
|
||||
kill "$FRONTEND_PID" 2>/dev/null || true
|
||||
# Also kill any child processes (npm spawns node)
|
||||
pkill -P "$FRONTEND_PID" 2>/dev/null || true
|
||||
sleep 1
|
||||
# Force kill if still running
|
||||
if kill -0 "$FRONTEND_PID" 2>/dev/null; then
|
||||
kill -9 "$FRONTEND_PID" 2>/dev/null || true
|
||||
fi
|
||||
print_ok "Frontend stopped (was PID: $FRONTEND_PID)"
|
||||
else
|
||||
print_info "Frontend was not running"
|
||||
fi
|
||||
rm -f "$FRONTEND_PID_FILE"
|
||||
else
|
||||
# Try to find and kill vite process
|
||||
VITE_PID=$(pgrep -f "vite.*frontend" 2>/dev/null | head -1)
|
||||
if [[ -n "$VITE_PID" ]]; then
|
||||
kill "$VITE_PID" 2>/dev/null || true
|
||||
print_ok "Frontend stopped (found PID: $VITE_PID)"
|
||||
else
|
||||
print_info "Frontend was not running"
|
||||
fi
|
||||
fi
|
||||
|
||||
# ============================================================================
|
||||
# Stop Backend
|
||||
# ============================================================================
|
||||
print_header "Stopping Backend"
|
||||
|
||||
if [[ -f "$BACKEND_PID_FILE" ]]; then
|
||||
BACKEND_PID=$(cat "$BACKEND_PID_FILE")
|
||||
if kill -0 "$BACKEND_PID" 2>/dev/null; then
|
||||
kill "$BACKEND_PID" 2>/dev/null || true
|
||||
sleep 1
|
||||
# Force kill if still running
|
||||
if kill -0 "$BACKEND_PID" 2>/dev/null; then
|
||||
kill -9 "$BACKEND_PID" 2>/dev/null || true
|
||||
fi
|
||||
print_ok "Backend stopped (was PID: $BACKEND_PID)"
|
||||
else
|
||||
print_info "Backend was not running"
|
||||
fi
|
||||
rm -f "$BACKEND_PID_FILE"
|
||||
else
|
||||
# Try to find and kill uvicorn process
|
||||
UVICORN_PID=$(pgrep -f "uvicorn app.main:app" 2>/dev/null | head -1)
|
||||
if [[ -n "$UVICORN_PID" ]]; then
|
||||
kill "$UVICORN_PID" 2>/dev/null || true
|
||||
print_ok "Backend stopped (found PID: $UVICORN_PID)"
|
||||
else
|
||||
print_info "Backend was not running"
|
||||
fi
|
||||
fi
|
||||
|
||||
# ============================================================================
|
||||
# Stop MinIO
|
||||
# ============================================================================
|
||||
if [[ "$KEEP_MINIO" == "false" ]]; then
|
||||
print_header "Stopping MinIO"
|
||||
|
||||
cd "$PROJECT_ROOT"
|
||||
|
||||
if docker ps --format '{{.Names}}' | grep -q "task-reporter-minio"; then
|
||||
if command -v docker-compose &> /dev/null; then
|
||||
docker-compose -f docker-compose.minio.yml down
|
||||
else
|
||||
docker compose -f docker-compose.minio.yml down
|
||||
fi
|
||||
print_ok "MinIO stopped (data preserved)"
|
||||
else
|
||||
print_info "MinIO was not running"
|
||||
fi
|
||||
else
|
||||
print_header "MinIO"
|
||||
print_info "Keeping MinIO running (--keep-minio)"
|
||||
fi
|
||||
|
||||
# ============================================================================
|
||||
# Cleanup
|
||||
# ============================================================================
|
||||
print_header "Cleanup"
|
||||
|
||||
# Remove PID directory if empty
|
||||
if [[ -d "$PID_DIR" ]] && [[ -z "$(ls -A "$PID_DIR")" ]]; then
|
||||
rmdir "$PID_DIR"
|
||||
print_ok "Cleaned up PID directory"
|
||||
fi
|
||||
|
||||
# ============================================================================
|
||||
# Summary
|
||||
# ============================================================================
|
||||
print_header "Summary"
|
||||
|
||||
echo -e "${GREEN}All services have been stopped.${NC}"
|
||||
echo ""
|
||||
if [[ "$KEEP_MINIO" == "true" ]]; then
|
||||
echo -e " ${YELLOW}Note:${NC} MinIO is still running (use without --keep-minio to stop)"
|
||||
fi
|
||||
echo -e " ${BLUE}Tip:${NC} Run ./scripts/start-dev.sh to start services again"
|
||||
echo ""
|
||||
Reference in New Issue
Block a user