#!/bin/bash # Chatty Application Startup Script echo "Starting Chatty..." # Check if virtual environment is activated if [[ "$VIRTUAL_ENV" == "" ]]; then echo "Activating virtual environment..." source atlas_env/bin/activate fi # Determine environment FLASK_ENV=${FLASK_ENV:-development} echo "Environment: $FLASK_ENV" # Check configuration based on environment if [ "$FLASK_ENV" = "production" ]; then echo "Production mode - validating configuration..." python deploy.py check-prod if [ $? -ne 0 ]; then echo "❌ Production configuration validation failed!" echo "Please fix configuration issues before starting in production mode." exit 1 fi echo "✅ Production configuration validated" elif [ "$FLASK_ENV" = "development" ]; then # Check if .env file exists for development if [ ! -f .env ]; then echo "Warning: .env file not found!" echo "Setting up development environment..." python deploy.py setup-dev echo "Please edit .env file with your configuration and restart." exit 1 fi fi # Test database connection echo "Testing database connection..." python -c "from database import test_connection; exit(0 if test_connection() else 1)" if [ $? -ne 0 ]; then echo "❌ Database connection failed!" echo "Please check your MongoDB configuration in .env file." exit 1 fi echo "✅ Database connection successful" # Clean up anonymous session data on startup echo "Cleaning up anonymous session data..." python cleanup_anonymous.py if [ $? -eq 0 ]; then echo "✅ Anonymous session cleanup completed" else echo "⚠️ Anonymous session cleanup encountered issues (continuing anyway)" fi # Run the application PORT=${PORT:-7860} echo "Starting Chatty server on http://localhost:$PORT" echo "Press Ctrl+C to stop" echo "" python app.py