Implement robust Redis URL parsing and connection checking
This commit is contained in:
79
start.sh
79
start.sh
@@ -31,22 +31,41 @@ export PORT=3001
|
||||
# Database configuration
|
||||
export DATABASE_URL="${CLOUDRON_POSTGRESQL_URL}"
|
||||
|
||||
# Redis configuration - debug and fix URL format
|
||||
echo "=> Original Redis URL: ${CLOUDRON_REDIS_URL}"
|
||||
# Redis configuration - parse Cloudron format to standard format
|
||||
echo "=> Configuring Redis..."
|
||||
|
||||
# Parse Redis URL components
|
||||
if [[ "$CLOUDRON_REDIS_URL" =~ redis://([^:]+):([^@]+)@([^:]+):([0-9]+) ]]; then
|
||||
REDIS_USER="${BASH_REMATCH[1]}"
|
||||
REDIS_PASSWORD="${BASH_REMATCH[2]}"
|
||||
REDIS_HOST="${BASH_REMATCH[3]}"
|
||||
REDIS_PORT="${BASH_REMATCH[4]}"
|
||||
# Cloudron provides Redis addon with specific environment variables
|
||||
# The CLOUDRON_REDIS_URL is in format: redis://:password@host:port
|
||||
# We need to ensure it's in the correct format for ioredis
|
||||
|
||||
if [ -n "${CLOUDRON_REDIS_URL}" ]; then
|
||||
# Extract components from the URL
|
||||
# Format: redis://:password@host:port/database
|
||||
REDIS_PASSWORD=$(echo "$CLOUDRON_REDIS_URL" | sed -n 's|redis://:\([^@]*\)@.*|\1|p')
|
||||
REDIS_HOST=$(echo "$CLOUDRON_REDIS_URL" | sed -n 's|redis://[^@]*@\([^:]*\):.*|\1|p')
|
||||
REDIS_PORT=$(echo "$CLOUDRON_REDIS_URL" | sed -n 's|redis://[^@]*@[^:]*:\([0-9]*\).*|\1|p')
|
||||
|
||||
# Reconstruct Redis URL in correct format
|
||||
export REDIS_URL="redis://:${REDIS_PASSWORD}@${REDIS_HOST}:${REDIS_PORT}"
|
||||
echo "=> Redis configured: ${REDIS_HOST}:${REDIS_PORT}"
|
||||
# Default port if not found
|
||||
if [ -z "$REDIS_PORT" ]; then
|
||||
REDIS_PORT="6379"
|
||||
fi
|
||||
|
||||
# Export individual components for Docmost
|
||||
export REDIS_HOST="${REDIS_HOST}"
|
||||
export REDIS_PORT="${REDIS_PORT}"
|
||||
export REDIS_PASSWORD="${REDIS_PASSWORD}"
|
||||
|
||||
# Also export the full URL in case it's needed
|
||||
export REDIS_URL="redis://:${REDIS_PASSWORD}@${REDIS_HOST}:${REDIS_PORT}/0"
|
||||
|
||||
echo "=> Redis configured: host=${REDIS_HOST}, port=${REDIS_PORT}"
|
||||
else
|
||||
echo "=> Failed to parse Redis URL, using original: ${CLOUDRON_REDIS_URL}"
|
||||
export REDIS_URL="${CLOUDRON_REDIS_URL}"
|
||||
echo "=> Warning: Redis URL not provided"
|
||||
# Set dummy Redis URL to prevent validation errors
|
||||
export REDIS_URL="redis://localhost:6379"
|
||||
export REDIS_HOST="localhost"
|
||||
export REDIS_PORT="6379"
|
||||
export REDIS_PASSWORD=""
|
||||
fi
|
||||
|
||||
# Email configuration
|
||||
@@ -70,10 +89,42 @@ export FILE_UPLOAD_SIZE_LIMIT="50mb"
|
||||
# JWT configuration
|
||||
export JWT_TOKEN_EXPIRES_IN="30d"
|
||||
|
||||
# Wait for Redis to be available
|
||||
if [ -n "${CLOUDRON_REDIS_URL}" ]; then
|
||||
echo "=> Waiting for Redis to be available..."
|
||||
for i in {1..30}; do
|
||||
if nc -z "${REDIS_HOST}" "${REDIS_PORT}" 2>/dev/null; then
|
||||
echo "=> Redis is available"
|
||||
break
|
||||
fi
|
||||
if [ $i -eq 30 ]; then
|
||||
echo "=> Warning: Redis not reachable after 30 seconds"
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
fi
|
||||
|
||||
echo "=> Running database migrations"
|
||||
cd /app/code
|
||||
chown -R cloudron:cloudron /app/data
|
||||
sudo -u cloudron /usr/bin/node /app/code/apps/server/node_modules/.bin/prisma migrate deploy || true
|
||||
|
||||
# Find the correct prisma binary path
|
||||
PRISMA_BIN=""
|
||||
if [ -f "/app/code/apps/server/node_modules/.bin/prisma" ]; then
|
||||
PRISMA_BIN="/app/code/apps/server/node_modules/.bin/prisma"
|
||||
elif [ -f "/app/code/node_modules/.bin/prisma" ]; then
|
||||
PRISMA_BIN="/app/code/node_modules/.bin/prisma"
|
||||
elif [ -f "/app/code/node_modules/@prisma/cli/build/index.js" ]; then
|
||||
PRISMA_BIN="/usr/bin/node /app/code/node_modules/@prisma/cli/build/index.js"
|
||||
fi
|
||||
|
||||
if [ -n "$PRISMA_BIN" ]; then
|
||||
echo "=> Found Prisma at: $PRISMA_BIN"
|
||||
cd /app/code/apps/server
|
||||
sudo -u cloudron $PRISMA_BIN migrate deploy || true
|
||||
else
|
||||
echo "=> Warning: Prisma binary not found, skipping migrations"
|
||||
fi
|
||||
|
||||
# Create nginx temp directories
|
||||
mkdir -p /tmp/nginx_client_temp /tmp/nginx_proxy_temp /tmp/nginx_fastcgi_temp /tmp/nginx_uwsgi_temp /tmp/nginx_scgi_temp
|
||||
|
Reference in New Issue
Block a user