Severian commited on
Commit
6612613
·
1 Parent(s): 8cfad5c
Files changed (1) hide show
  1. docker/entrypoint.sh +26 -3
docker/entrypoint.sh CHANGED
@@ -39,12 +39,35 @@ check_redis() {
39
  redis-cli -h "${REDIS_HOST}" -p "${REDIS_PORT}" -a "${REDIS_PASSWORD}" ping > /dev/null 2>&1
40
  }
41
 
 
 
 
 
 
 
 
 
 
 
 
42
  echo "Waiting for Redis to be ready..."
43
- until check_redis; do
44
- echo "Redis is unavailable (host: ${REDIS_HOST}, port: ${REDIS_PORT}) - retrying..."
 
 
 
 
 
 
 
 
45
  sleep 5
 
 
 
 
 
46
  done
47
- echo "Redis is ready!"
48
 
49
  # Initialize database if needed
50
  cd /app/api
 
39
  redis-cli -h "${REDIS_HOST}" -p "${REDIS_PORT}" -a "${REDIS_PASSWORD}" ping > /dev/null 2>&1
40
  }
41
 
42
+ check_redis() {
43
+ if [ "${REDIS_TYPE}" = "local" ]; then
44
+ echo "Starting local Redis server..."
45
+ redis-server --daemonize yes --requirepass "${REDIS_PASSWORD}"
46
+ sleep 2
47
+ return 0
48
+ else
49
+ redis-cli -h "${REDIS_HOST}" -p "${REDIS_PORT}" -a "${REDIS_PASSWORD}" ping > /dev/null 2>&1
50
+ fi
51
+ }
52
+
53
  echo "Waiting for Redis to be ready..."
54
+ local max_attempts=30
55
+ local attempt=1
56
+
57
+ while [ $attempt -le $max_attempts ]; do
58
+ if check_redis; then
59
+ echo "Redis is ready!"
60
+ break
61
+ fi
62
+ echo "Redis is unavailable (attempt $attempt/$max_attempts) - retrying..."
63
+ attempt=$((attempt + 1))
64
  sleep 5
65
+
66
+ if [ $attempt -eq $max_attempts ]; then
67
+ echo "Falling back to local Redis..."
68
+ export REDIS_TYPE="local"
69
+ fi
70
  done
 
71
 
72
  # Initialize database if needed
73
  cd /app/api