This commit is contained in:
johnpccd 2025-05-24 18:35:10 +02:00
parent 4d8447bb40
commit 9c850fc632
3 changed files with 88 additions and 2 deletions

View File

@ -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
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

39
scripts/stop.sh Normal file
View File

@ -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."

View File

@ -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