fix: resolve duplicate header and improve Redis management
- Dashboard: Remove redundant header (Layout already provides it) - projectctl.sh: Add start_redis/stop_redis functions for automatic Redis lifecycle management on project start/stop - rate_limiter.py: Add fallback to memory storage when Redis unavailable 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -213,6 +213,94 @@ check_redis() {
|
||||
return 0
|
||||
}
|
||||
|
||||
start_redis() {
|
||||
local env_file="$BACKEND_DIR/.env"
|
||||
local redis_host redis_port
|
||||
redis_host="$(get_env_value "REDIS_HOST" "$env_file")"
|
||||
redis_port="$(get_env_value "REDIS_PORT" "$env_file")"
|
||||
redis_host="${redis_host:-localhost}"
|
||||
redis_port="${redis_port:-6379}"
|
||||
|
||||
# Only manage local Redis
|
||||
if [[ "$redis_host" != "localhost" && "$redis_host" != "127.0.0.1" ]]; then
|
||||
log "Redis host is remote ($redis_host), skipping local Redis management"
|
||||
return 0
|
||||
fi
|
||||
|
||||
# Check if Redis is already running
|
||||
if command -v redis-cli >/dev/null 2>&1; then
|
||||
if redis-cli -h "$redis_host" -p "$redis_port" ping >/dev/null 2>&1; then
|
||||
log "Redis already running at $redis_host:$redis_port"
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
|
||||
# Try to start Redis using brew services (macOS)
|
||||
if command -v brew >/dev/null 2>&1; then
|
||||
if brew services list 2>/dev/null | grep -q "redis"; then
|
||||
log "Starting Redis via brew services..."
|
||||
brew services start redis >/dev/null 2>&1 || true
|
||||
sleep 2
|
||||
if redis-cli -h "$redis_host" -p "$redis_port" ping >/dev/null 2>&1; then
|
||||
log "Redis started successfully"
|
||||
env_log "Redis: Started via brew services"
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
# Try to start redis-server directly
|
||||
if command -v redis-server >/dev/null 2>&1; then
|
||||
log "Starting Redis server directly..."
|
||||
redis-server --daemonize yes --port "$redis_port" >/dev/null 2>&1 || true
|
||||
sleep 1
|
||||
if redis-cli -h "$redis_host" -p "$redis_port" ping >/dev/null 2>&1; then
|
||||
log "Redis started successfully"
|
||||
env_log "Redis: Started directly"
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
|
||||
log "WARN: Could not start Redis automatically"
|
||||
return 1
|
||||
}
|
||||
|
||||
stop_redis() {
|
||||
local env_file="$BACKEND_DIR/.env"
|
||||
local redis_host redis_port
|
||||
redis_host="$(get_env_value "REDIS_HOST" "$env_file")"
|
||||
redis_port="$(get_env_value "REDIS_PORT" "$env_file")"
|
||||
redis_host="${redis_host:-localhost}"
|
||||
redis_port="${redis_port:-6379}"
|
||||
|
||||
# Only manage local Redis
|
||||
if [[ "$redis_host" != "localhost" && "$redis_host" != "127.0.0.1" ]]; then
|
||||
echo "Redis host is remote ($redis_host), skipping local Redis management"
|
||||
return 0
|
||||
fi
|
||||
|
||||
# Try to stop Redis using brew services (macOS)
|
||||
if command -v brew >/dev/null 2>&1; then
|
||||
if brew services list 2>/dev/null | grep -q "redis.*started"; then
|
||||
echo "Stopping Redis via brew services..."
|
||||
brew services stop redis >/dev/null 2>&1 || true
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
|
||||
# Try to stop redis-server via redis-cli
|
||||
if command -v redis-cli >/dev/null 2>&1; then
|
||||
if redis-cli -h "$redis_host" -p "$redis_port" ping >/dev/null 2>&1; then
|
||||
echo "Stopping Redis via redis-cli shutdown..."
|
||||
redis-cli -h "$redis_host" -p "$redis_port" shutdown nosave >/dev/null 2>&1 || true
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "Redis: not running or not managed locally"
|
||||
return 0
|
||||
}
|
||||
|
||||
check_mysql() {
|
||||
local env_file="$BACKEND_DIR/.env"
|
||||
local mysql_host mysql_port
|
||||
@@ -397,7 +485,8 @@ start() {
|
||||
check_env_file
|
||||
check_python_deps
|
||||
check_node_deps
|
||||
check_redis || true # Warn but don't fail
|
||||
start_redis || true # Start Redis if not running (warn but don't fail)
|
||||
check_redis || true # Verify Redis is available
|
||||
check_mysql || true # Warn but don't fail
|
||||
check_ports
|
||||
|
||||
@@ -425,6 +514,7 @@ stop() {
|
||||
fi
|
||||
stop_service "backend" "$dir/backend.pid"
|
||||
stop_service "frontend" "$dir/frontend.pid"
|
||||
stop_redis
|
||||
}
|
||||
|
||||
status() {
|
||||
|
||||
Reference in New Issue
Block a user