ToolJet/server/entrypoint.sh

53 lines
1.4 KiB
Bash
Raw Normal View History

#!/bin/bash
2021-07-23 14:16:01 +00:00
set -e
2025-02-25 06:52:50 +00:00
npm cache clean --force
2021-07-23 14:16:01 +00:00
2025-02-25 06:52:50 +00:00
# Load environment variables from .env if the file exists
2024-01-08 18:47:59 +00:00
if [ -f "./.env" ]; then
2025-02-25 06:52:50 +00:00
export $(grep -v '^#' ./.env | xargs -d '\n') || true
fi
# Check WORKLOW_WORKER and skip SETUP_CMD if true
if [ "${WORKFLOW_WORKER}" == "true" ]; then
echo "WORKFLOW_WORKER is set to true. Running worker process."
npm run worker:prod
else
# Determine setup command based on the presence of ./server/dist
if [ -d "./server/dist" ]; then
SETUP_CMD='npm run db:setup:prod'
else
SETUP_CMD='npm run db:setup'
fi
fi
2025-02-25 06:52:50 +00:00
# Wait for PostgreSQL connection
2024-01-08 18:47:59 +00:00
if [ -z "$DATABASE_URL" ]; then
2025-02-25 06:52:50 +00:00
./server/scripts/wait-for-it.sh $PG_HOST:${PG_PORT:-5432} --strict --timeout=300 -- echo "PostgreSQL is up"
2024-01-08 18:47:59 +00:00
else
PG_HOST=$(echo "$DATABASE_URL" | awk -F'[/:@?]' '{print $6}')
PG_PORT=$(echo "$DATABASE_URL" | awk -F'[/:@?]' '{print $7}')
2025-02-25 06:52:50 +00:00
./server/scripts/wait-for-it.sh "$PG_HOST:$PG_PORT" --strict --timeout=300 -- echo "PostgreSQL is up"
fi
# Note: This Redis connection check changes are only for EE repo
# Check Redis connection
if [ -z "$REDIS_URL" ]; then
if [ -z "$REDIS_HOST" ] || [ -z "$REDIS_PORT" ]; then
echo "Waiting for Redis connection..."
2024-01-08 18:47:59 +00:00
fi
2025-02-25 06:52:50 +00:00
./server/scripts/wait-for-it.sh $REDIS_HOST:${REDIS_PORT:-6379} --strict --timeout=300 -- echo "Redis is up"
else
echo "REDIS_URL connection is set"
fi
# Run setup command if defined
if [ -n "$SETUP_CMD" ]; then
$SETUP_CMD
fi
2021-07-23 14:16:01 +00:00
exec "$@"