Spaces:
Running
Running
File size: 1,642 Bytes
41cc612 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | #!/usr/bin/env bash
# start.sh — Kill any process holding port 5000, then start the Flask app fresh.
# Usage: ./start.sh [venv-name] (default venv name: .venv)
PORT=5000
VENV_NAME="${1:-.venv}"
cd "$(dirname "$0")"
echo ""
echo " NSE Paper Trading Platform"
echo " --------------------------"
# Kill anything on port 5000
echo ""
echo " [1/4] Checking port $PORT..."
PIDS=$(lsof -ti tcp:"$PORT" 2>/dev/null || true)
if [ -n "$PIDS" ]; then
echo " Killing PID(s) $PIDS on port $PORT"
echo "$PIDS" | xargs kill -9 2>/dev/null || true
sleep 0.5
else
echo " Port $PORT is free"
fi
# Kill stale python app.py processes
STALE=$(pgrep -f "python.*app.py" 2>/dev/null || true)
if [ -n "$STALE" ]; then
echo " Killing stale Flask processes: $STALE"
echo "$STALE" | xargs kill -9 2>/dev/null || true
sleep 0.3
fi
# Set up / activate venv
echo ""
echo " [2/4] Environment (venv: $VENV_NAME)..."
if [ -f "$VENV_NAME/bin/activate" ]; then
source "$VENV_NAME/bin/activate"
echo " Activated existing venv: $VENV_NAME"
else
echo " '$VENV_NAME' not found — creating it..."
python3 -m venv "$VENV_NAME"
source "$VENV_NAME/bin/activate"
echo " Created and activated venv: $VENV_NAME"
echo ""
echo " [3/4] Installing dependencies..."
if [ -f "requirements.txt" ]; then
pip install -r requirements.txt
echo " Dependencies installed from requirements.txt"
else
echo " No requirements.txt found — skipping install"
fi
fi
# Start Flask
echo ""
echo " [4/4] Starting Flask on port $PORT..."
echo ""
echo " Open: http://localhost:$PORT"
echo " Stop: Ctrl+C"
echo ""
exec python3 app.py
|