|
1 | 1 | #!/bin/bash |
2 | 2 | # Azure App Service startup script |
3 | 3 | # Azure sets PORT env var automatically (default 8000) |
4 | | -set -e |
| 4 | + |
| 5 | +echo "=== API-Watch Startup ===" |
| 6 | +echo "PWD: $(pwd)" |
| 7 | +echo "Date: $(date)" |
5 | 8 |
|
6 | 9 | # Ensure we're in the deployment directory |
7 | 10 | cd /home/site/wwwroot |
| 11 | +echo "Working dir: $(pwd)" |
| 12 | +echo "Contents: $(ls -la)" |
8 | 13 |
|
9 | 14 | # Activate Oryx-created virtual environment (created during zip deployment) |
10 | 15 | if [ -d "antenv" ]; then |
11 | 16 | echo "Activating Oryx virtual environment (antenv)..." |
12 | 17 | source antenv/bin/activate |
| 18 | + echo "Python: $(which python)" |
| 19 | + echo "Pip packages: $(pip list --format=columns 2>/dev/null | head -5)" |
| 20 | +else |
| 21 | + echo "WARNING: antenv directory not found!" |
| 22 | + echo "Checking for packages directory..." |
13 | 23 | fi |
14 | 24 |
|
15 | 25 | # Add bundled packages to Python path (fallback if no antenv) |
|
20 | 30 |
|
21 | 31 | # Fallback: install if neither antenv nor bundled packages have gunicorn |
22 | 32 | if ! python -c "import gunicorn" 2>/dev/null; then |
23 | | - echo "Installing Python dependencies (timeout 180s)..." |
24 | | - timeout 180 pip install --no-cache-dir -r requirements.txt 2>&1 | tail -5 || echo "⚠️ pip install timed out or failed (non-fatal)" |
| 33 | + echo "gunicorn not found, installing dependencies..." |
| 34 | + pip install --no-cache-dir -r requirements.txt 2>&1 | tail -10 || echo "⚠️ pip install failed" |
25 | 35 | fi |
26 | 36 |
|
| 37 | +# Verify critical imports work |
| 38 | +echo "Testing critical imports..." |
| 39 | +python -c " |
| 40 | +import sys |
| 41 | +print(f'Python: {sys.executable}') |
| 42 | +try: |
| 43 | + import fastapi; print(f'fastapi: {fastapi.__version__}') |
| 44 | +except Exception as e: print(f'fastapi FAILED: {e}') |
| 45 | +try: |
| 46 | + import gunicorn; print(f'gunicorn: OK') |
| 47 | +except Exception as e: print(f'gunicorn FAILED: {e}') |
| 48 | +try: |
| 49 | + from src.api_server import app; print('src.api_server: OK') |
| 50 | +except Exception as e: print(f'src.api_server FAILED: {e}') |
| 51 | +" 2>&1 || echo "Import test failed" |
| 52 | + |
27 | 53 | # Run database migrations (safe to run repeatedly — no-ops if up to date) |
28 | 54 | if [ -d "alembic" ]; then |
29 | 55 | echo "Running database migrations..." |
30 | | - python -m alembic upgrade head || echo "⚠️ Migrations skipped (non-fatal)" |
| 56 | + python -m alembic upgrade head 2>&1 || echo "⚠️ Migrations skipped (non-fatal)" |
31 | 57 | fi |
32 | 58 |
|
33 | 59 | # Start with gunicorn + uvicorn workers for production performance |
34 | | -# Azure sets PORT; default to 8000 if unset |
35 | 60 | export PORT=${PORT:-8000} |
36 | 61 | echo "Starting API-Watch on port $PORT..." |
37 | 62 |
|
|
0 commit comments