#!/bin/bash # Gitea Webhook Ambassador start script # Check virtual environment if [ ! -d "venv" ]; then echo "❌ Virtual environment does not exist, please run ./scripts/setup.sh first" exit 1 fi # Activate virtual environment source venv/bin/activate # Check environment file if [ ! -f ".env" ]; then echo "❌ .env file does not exist, please run ./scripts/setup.sh first" exit 1 fi # Check if Redis is running if ! pgrep -f redis-server > /dev/null; then echo "🐳 Starting Redis..." docker run -d -p 6379:6379 redis:alpine fi # Start Gitea Webhook Ambassador echo "🚀 Starting Gitea Webhook Ambassador..." # Start API service API_LOG="logs/api.log" echo "🌐 Starting API service..." nohup python -m uvicorn app.main:app --host 0.0.0.0 --port 8000 > $API_LOG 2>&1 & API_PID=$! # Wait for API service to start sleep 3 # Start Celery worker WORKER_LOG="logs/worker.log" echo "⚙️ Starting Celery worker..." nohup celery -A app.tasks.jenkins_tasks worker --loglevel=info > $WORKER_LOG 2>&1 & WORKER_PID=$! # Start Celery beat (scheduled tasks) BEAT_LOG="logs/beat.log" echo "⏰ Starting scheduled task scheduler..." nohup celery -A app.tasks.jenkins_tasks beat --loglevel=info > $BEAT_LOG 2>&1 & BEAT_PID=$! # All services started sleep 2 echo "✅ All services started!" echo "📊 Service status:" echo "- API service: http://localhost:8000 (PID: $API_PID)" echo "- Health check: http://localhost:8000/health" echo "- Metrics: http://localhost:8000/metrics" # Wait for Ctrl+C to stop all services echo "🛑 Press Ctrl+C to stop all services" # Wait for interrupt signal trap 'echo "🛑 Stopping services..."; kill $API_PID $WORKER_PID $BEAT_PID 2>/dev/null; exit 0' INT # Wait for all background processes wait