From 9c850fc63227add16111c9256fcb8b9a2d610733 Mon Sep 17 00:00:00 2001 From: johnpccd Date: Sat, 24 May 2025 18:35:10 +0200 Subject: [PATCH] cp --- scripts/start.sh | 27 ++++++++++++++++++++++++++- scripts/stop.sh | 39 +++++++++++++++++++++++++++++++++++++++ start_dev.sh | 24 +++++++++++++++++++++++- 3 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 scripts/stop.sh diff --git a/scripts/start.sh b/scripts/start.sh index ed37250..3546e2b 100644 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -1,5 +1,20 @@ #!/bin/bash +# Function to handle cleanup on exit +cleanup() { + echo "" + echo "Shutting down server..." + if [ ! -z "$SERVER_PID" ]; then + kill $SERVER_PID 2>/dev/null + wait $SERVER_PID 2>/dev/null + fi + echo "Server stopped." + exit 0 +} + +# Set up signal handlers +trap cleanup SIGINT SIGTERM + # Activate virtual environment based on platform if [ -d "venv" ]; then if [ -f "venv/Scripts/activate" ]; then @@ -20,4 +35,14 @@ export LOG_LEVEL=DEBUG # Start server in development mode with hot reloading echo "Starting development server..." -uvicorn main:app --host 0.0.0.0 --port 8000 --reload \ No newline at end of file +echo "Press Ctrl+C to stop the server" +echo "Server will be available at: http://localhost:8000" +echo "API documentation: http://localhost:8000/docs" +echo "" + +# Start uvicorn in background and capture PID +uvicorn main:app --host 0.0.0.0 --port 8000 --reload & +SERVER_PID=$! + +# Wait for the server process +wait $SERVER_PID \ No newline at end of file diff --git a/scripts/stop.sh b/scripts/stop.sh new file mode 100644 index 0000000..e3ba22d --- /dev/null +++ b/scripts/stop.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +echo "Stopping Sereact API server..." + +# Find and kill uvicorn processes +PIDS=$(ps aux | grep "uvicorn main:app" | grep -v grep | awk '{print $2}') + +if [ -z "$PIDS" ]; then + echo "No running server found." +else + echo "Found server process(es): $PIDS" + for PID in $PIDS; do + echo "Killing process $PID..." + kill $PID + sleep 1 + # Force kill if still running + if kill -0 $PID 2>/dev/null; then + echo "Force killing process $PID..." + kill -9 $PID + fi + done + echo "Server stopped." +fi + +# Also check for any Python processes running main.py +PYTHON_PIDS=$(ps aux | grep "python.*main.py\|python.*main:app" | grep -v grep | awk '{print $2}') +if [ ! -z "$PYTHON_PIDS" ]; then + echo "Found Python processes: $PYTHON_PIDS" + for PID in $PYTHON_PIDS; do + echo "Killing Python process $PID..." + kill $PID + sleep 1 + if kill -0 $PID 2>/dev/null; then + kill -9 $PID + fi + done +fi + +echo "All server processes stopped." \ No newline at end of file diff --git a/start_dev.sh b/start_dev.sh index 9e03857..802bdc3 100644 --- a/start_dev.sh +++ b/start_dev.sh @@ -4,6 +4,21 @@ # This script sets the environment variables and starts the application # Auto-generated by deployment/scripts/setup_local_env.sh +# Function to handle cleanup on exit +cleanup() { + echo "" + echo "Shutting down server..." + if [ ! -z "$SERVER_PID" ]; then + kill $SERVER_PID 2>/dev/null + wait $SERVER_PID 2>/dev/null + fi + echo "Server stopped." + exit 0 +} + +# Set up signal handlers +trap cleanup SIGINT SIGTERM + # Activate virtual environment source venv/Scripts/activate @@ -21,5 +36,12 @@ echo "Firestore project: $FIRESTORE_PROJECT_ID" echo "GCS bucket: $GCS_BUCKET_NAME" echo "API will be available at: http://localhost:8000" echo "API documentation: http://localhost:8000/docs" +echo "Press Ctrl+C to stop the server" +echo "" -uvicorn main:app --host 0.0.0.0 --port 8000 --reload +# Start uvicorn in background and capture PID +uvicorn main:app --host 0.0.0.0 --port 8000 --reload & +SERVER_PID=$! + +# Wait for the server process +wait $SERVER_PID