Skip to content

Commit

Permalink
Merge pull request #1966 from PolicyEngine/fix/1963-for-loop-bash
Browse files Browse the repository at this point in the history
Fix start.sh
  • Loading branch information
anth-volk authored Nov 11, 2024
2 parents 91d92ff + d26b164 commit 223ddaa
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
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

0 comments on commit 223ddaa

Please sign in to comment.