Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add explicit deploy logging to start.sh #2024

Open
anth-volk opened this issue Nov 26, 2024 · 0 comments
Open

Add explicit deploy logging to start.sh #2024

anth-volk opened this issue Nov 26, 2024 · 0 comments

Comments

@anth-volk
Copy link
Collaborator

A few things:

  1. We should configure GCP to wait to run readiness checks until the API is actually ready
  2. We should add definitive logging at particular points within the launch script (I believe we also have to specify specifically to log to stdout)
  3. We should ensure that after doing so, the logs actually appear within the GCP console

Here are some modifications that Claude recommended, but I haven't proofed them:

#!/bin/sh
# Environment variables
PORT="${PORT:-8080}"
WORKER_COUNT="${WORKER_COUNT:-3}"
REDIS_PORT="${REDIS_PORT:-6379}"

echo "Starting API server..." >&2

# Start the API
gunicorn -b :"$PORT" policyengine_api.api --timeout 300 --workers 5 &
API_PID=$!

# Wait for API to be ready (try connecting to the port)
TIMEOUT=30
while [ $TIMEOUT -gt 0 ]; do
    if nc -z localhost "$PORT"; then
        echo "API server is ready" >&2
        break
    fi
    TIMEOUT=$((TIMEOUT - 1))
    sleep 1
done

if [ $TIMEOUT -eq 0 ]; then
    echo "API server failed to start" >&2
    exit 1
fi

echo "Starting Redis..." >&2

# Start Redis with configuration for multiple clients
redis-server --protected-mode no \
             --maxclients 10000 \
             --timeout 0 &
REDIS_PID=$!

# Wait for Redis to be ready
sleep 2

# Start multiple workers using POSIX-compliant loop
i=1
while [ $i -le "$WORKER_COUNT" ]
do
    echo "Starting worker $i..." >&2
    python3 policyengine_api/worker.py &
    i=$((i + 1))
done

# Keep the script running and handle shutdown gracefully
trap "kill $API_PID $REDIS_PID; pkill -P $$; exit 1" INT TERM

wait
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant