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

Fix start.sh #1966

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions changelog_entry.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- bump: patch
changes:
changed:
- Modified GCP shell script to drop Bash-specific for loop
20 changes: 11 additions & 9 deletions gcp/policyengine_api/start.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#!/bin/bash

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

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

# Start Redis with configuration for multiple clients
redis-server --protected-mode no \
Expand All @@ -16,13 +15,16 @@ redis-server --protected-mode no \
# Wait for Redis to be ready
sleep 2

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

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

wait
Loading