Severian commited on
Commit
895529e
·
1 Parent(s): 3ec4c07

fix: improve Redis handling for HF Spaces

Browse files

- Add Redis installation check
- Add local Redis fallback for HF Spaces
- Improve Redis connection handling
- Add data directory for Redis persistence
- Fix Redis connection timeout issues

Files changed (1) hide show
  1. docker/entrypoint.sh +10 -2
docker/entrypoint.sh CHANGED
@@ -37,10 +37,17 @@ check_redis() {
37
  local max_attempts=30
38
  local attempt=1
39
 
 
 
 
 
 
 
40
  # For HF Spaces, start local Redis by default
41
  if [ "${REDIS_TYPE}" = "local" ] || [ "${SPACE_ID}" != "" ]; then
42
  echo "Starting local Redis server..."
43
- redis-server --daemonize yes --port 6379 --requirepass "${REDIS_PASSWORD:-difyai123456}"
 
44
  export REDIS_HOST=localhost
45
  sleep 2
46
  if redis-cli -h localhost -p 6379 -a "${REDIS_PASSWORD:-difyai123456}" ping > /dev/null 2>&1; then
@@ -62,7 +69,8 @@ check_redis() {
62
  echo "Falling back to local Redis..."
63
  export REDIS_TYPE="local"
64
  export REDIS_HOST=localhost
65
- redis-server --daemonize yes --port 6379 --requirepass "${REDIS_PASSWORD:-difyai123456}"
 
66
  sleep 2
67
  if redis-cli -h localhost -p 6379 -a "${REDIS_PASSWORD:-difyai123456}" ping > /dev/null 2>&1; then
68
  echo "Local Redis server started successfully"
 
37
  local max_attempts=30
38
  local attempt=1
39
 
40
+ # Ensure Redis is installed
41
+ if ! command -v redis-server >/dev/null 2>&1; then
42
+ echo "Redis server not found, installing..."
43
+ apt-get update && apt-get install -y redis-server
44
+ fi
45
+
46
  # For HF Spaces, start local Redis by default
47
  if [ "${REDIS_TYPE}" = "local" ] || [ "${SPACE_ID}" != "" ]; then
48
  echo "Starting local Redis server..."
49
+ mkdir -p /data/redis
50
+ redis-server --daemonize yes --dir /data/redis --port 6379 --requirepass "${REDIS_PASSWORD:-difyai123456}"
51
  export REDIS_HOST=localhost
52
  sleep 2
53
  if redis-cli -h localhost -p 6379 -a "${REDIS_PASSWORD:-difyai123456}" ping > /dev/null 2>&1; then
 
69
  echo "Falling back to local Redis..."
70
  export REDIS_TYPE="local"
71
  export REDIS_HOST=localhost
72
+ mkdir -p /data/redis
73
+ redis-server --daemonize yes --dir /data/redis --port 6379 --requirepass "${REDIS_PASSWORD:-difyai123456}"
74
  sleep 2
75
  if redis-cli -h localhost -p 6379 -a "${REDIS_PASSWORD:-difyai123456}" ping > /dev/null 2>&1; then
76
  echo "Local Redis server started successfully"