From 645c1ec9dffc927880d0ba40568734e9672a8f62 Mon Sep 17 00:00:00 2001 From: SergeantPanda Date: Tue, 21 Oct 2025 21:47:15 -0500 Subject: [PATCH] Testing redis potential fix. Launch redis in entrypoint before uWSGI --- docker/entrypoint.sh | 21 +++++++++++++++++++++ docker/uwsgi.debug.ini | 8 ++------ docker/uwsgi.dev.ini | 8 ++------ docker/uwsgi.ini | 8 ++------ 4 files changed, 27 insertions(+), 18 deletions(-) diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index 1b41bf29..0e3513f0 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -183,6 +183,27 @@ if [ "$DISPATCHARR_DEBUG" != "true" ]; then uwsgi_args+=" --disable-logging" fi +# Start Redis before uwsgi to ensure it's available when Django apps initialize +echo "🚀 Starting Redis..." +setpriv --reuid=$POSTGRES_USER --regid=$POSTGRES_USER --clear-groups -- redis-server --daemonize yes + +# Wait for Redis to be ready +echo "⏳ Waiting for Redis to be ready..." +python /app/scripts/wait_for_redis.py +if [ $? -ne 0 ]; then + echo "❌ Redis failed to start properly!" + exit 1 +fi + +redis_pid=$(pgrep -x redis-server) +if [ -n "$redis_pid" ]; then + echo "✅ Redis started with PID $redis_pid" + pids+=("$redis_pid") +else + echo "❌ Redis process not found after startup!" + exit 1 +fi + # Launch uwsgi with configurable nice level (default: -10 for high priority) # Users can override via UWSGI_NICE_LEVEL environment variable in docker-compose # Start with nice as root, then use setpriv to drop privileges to dispatch user diff --git a/docker/uwsgi.debug.ini b/docker/uwsgi.debug.ini index 3de890a5..785d3218 100644 --- a/docker/uwsgi.debug.ini +++ b/docker/uwsgi.debug.ini @@ -2,12 +2,8 @@ ; exec-before = python manage.py collectstatic --noinput ; exec-before = python manage.py migrate --noinput -; First run Redis availability check script once -exec-before = python /app/scripts/wait_for_redis.py - -; Start Redis first -attach-daemon = redis-server -; Then start other services with configurable nice level (default: 5 for low priority) +; Redis is now started in entrypoint.sh before uwsgi to prevent race conditions +; Start services with configurable nice level (default: 5 for low priority) ; Users can override via CELERY_NICE_LEVEL environment variable in docker-compose attach-daemon = nice -n $(CELERY_NICE_LEVEL) celery -A dispatcharr worker --autoscale=6,1 attach-daemon = nice -n $(CELERY_NICE_LEVEL) celery -A dispatcharr beat diff --git a/docker/uwsgi.dev.ini b/docker/uwsgi.dev.ini index e476e216..f6681969 100644 --- a/docker/uwsgi.dev.ini +++ b/docker/uwsgi.dev.ini @@ -4,12 +4,8 @@ ; exec-pre = touch /data/logs/uwsgi-dev.log ; exec-pre = chmod 666 /data/logs/uwsgi-dev.log -; First run Redis availability check script once -exec-pre = python /app/scripts/wait_for_redis.py - -; Start Redis first -attach-daemon = redis-server -; Then start other services with configurable nice level (default: 5 for low priority) +; Redis is now started in entrypoint.sh before uwsgi to prevent race conditions +; Start services with configurable nice level (default: 5 for low priority) ; Users can override via CELERY_NICE_LEVEL environment variable in docker-compose attach-daemon = nice -n $(CELERY_NICE_LEVEL) celery -A dispatcharr worker --autoscale=6,1 attach-daemon = nice -n $(CELERY_NICE_LEVEL) celery -A dispatcharr beat diff --git a/docker/uwsgi.ini b/docker/uwsgi.ini index f8fe8ab7..9d0ab9bc 100644 --- a/docker/uwsgi.ini +++ b/docker/uwsgi.ini @@ -4,12 +4,8 @@ ; exec-pre = touch /data/logs/uwsgi.log ; exec-pre = chmod 666 /data/logs/uwsgi.log -; First run Redis availability check script once -exec-pre = python /app/scripts/wait_for_redis.py - -; Start Redis first -attach-daemon = redis-server -; Then start other services with configurable nice level (default: 5 for low priority) +; Redis is now started in entrypoint.sh before uwsgi to prevent race conditions +; Start services with configurable nice level (default: 5 for low priority) ; Users can override via CELERY_NICE_LEVEL environment variable in docker-compose attach-daemon = nice -n $(CELERY_NICE_LEVEL) celery -A dispatcharr worker --autoscale=6,1 attach-daemon = nice -n $(CELERY_NICE_LEVEL) celery -A dispatcharr beat