Files
herolib_python/pythonsetup/start_server.sh
2025-08-20 04:32:30 +02:00

71 lines
2.0 KiB
Bash
Executable File

#!/bin/bash
# KnowledgeCenter Web Server Startup Script
# This script starts the Flask web server on port 9922 for PRODUCTION
set -e # Exit on any error
# 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
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
source pipenv.sh
echo -e "${BLUE}🚀 KnowledgeCenter Web Server Startup (PRODUCTION)${NC}"
echo "================================================="
# Check if uv is installed
# Check if port 9922 is available
if lsof -Pi :9922 -sTCP:LISTEN -t >/dev/null 2>&1; then
echo -e "${YELLOW}⚠️ Port 9922 is already in use. Attempting to stop existing process...${NC}"
PID=$(lsof -ti:9922)
if [ ! -z "$PID" ]; then
kill -9 $PID 2>/dev/null || true
sleep 2
echo -e "${GREEN}✅ Existing process stopped${NC}"
fi
fi
# Set environment variables for production
export FLASK_APP=src/app.py
export FLASK_ENV=production
export FLASK_DEBUG=0
# Display startup information
echo ""
echo -e "${BLUE}📋 Server Information:${NC}"
echo " • Application: KnowledgeCenter Interest Registration"
echo " • Port: 9922"
echo " • URL: http://localhost:9922"
echo " • Environment: Production"
echo " • Debug Mode: Disabled"
echo ""
# Function to handle cleanup on exit
cleanup() {
echo -e "\n${YELLOW}🛑 Shutting down server...${NC}"
exit 0
}
# Set trap for cleanup
trap cleanup SIGINT SIGTERM
# Start the Flask development server
echo -e "${GREEN}🌟 Starting KnowledgeCenter web server...${NC}"
echo -e "${BLUE}📡 Server will be available at: http://localhost:9922${NC}"
echo -e "${YELLOW}💡 Press Ctrl+C to stop the server${NC}"
echo ""
# Start the server with uv, specifying production config
uv run python src/app.py --cfg prod --port 9922 --host 0.0.0.0
# This line should not be reached unless the server exits
echo -e "${RED}❌ Server stopped unexpectedly${NC}"