You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

entrypoint.sh 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/bin/bash
  2. set -e
  3. # Set UTF-8 encoding to address potential encoding issues in containerized environments
  4. export LANG=${LANG:-en_US.UTF-8}
  5. export LC_ALL=${LC_ALL:-en_US.UTF-8}
  6. export PYTHONIOENCODING=${PYTHONIOENCODING:-utf-8}
  7. if [[ "${MIGRATION_ENABLED}" == "true" ]]; then
  8. echo "Running migrations"
  9. flask upgrade-db
  10. # Pure migration mode
  11. if [[ "${MODE}" == "migration" ]]; then
  12. echo "Migration completed, exiting normally"
  13. exit 0
  14. fi
  15. fi
  16. if [[ "${MODE}" == "worker" ]]; then
  17. # Get the number of available CPU cores
  18. if [ "${CELERY_AUTO_SCALE,,}" = "true" ]; then
  19. # Set MAX_WORKERS to the number of available cores if not specified
  20. AVAILABLE_CORES=$(nproc)
  21. MAX_WORKERS=${CELERY_MAX_WORKERS:-$AVAILABLE_CORES}
  22. MIN_WORKERS=${CELERY_MIN_WORKERS:-1}
  23. CONCURRENCY_OPTION="--autoscale=${MAX_WORKERS},${MIN_WORKERS}"
  24. else
  25. CONCURRENCY_OPTION="-c ${CELERY_WORKER_AMOUNT:-1}"
  26. fi
  27. exec celery -A app.celery worker -P ${CELERY_WORKER_CLASS:-gevent} $CONCURRENCY_OPTION \
  28. --max-tasks-per-child ${MAX_TASKS_PER_CHILD:-50} --loglevel ${LOG_LEVEL:-INFO} \
  29. -Q ${CELERY_QUEUES:-dataset,mail,ops_trace,app_deletion,plugin,workflow_storage,conversation}
  30. elif [[ "${MODE}" == "beat" ]]; then
  31. exec celery -A app.celery beat --loglevel ${LOG_LEVEL:-INFO}
  32. else
  33. if [[ "${DEBUG}" == "true" ]]; then
  34. exec flask run --host=${DIFY_BIND_ADDRESS:-0.0.0.0} --port=${DIFY_PORT:-5001} --debug
  35. else
  36. exec gunicorn \
  37. --bind "${DIFY_BIND_ADDRESS:-0.0.0.0}:${DIFY_PORT:-5001}" \
  38. --workers ${SERVER_WORKER_AMOUNT:-1} \
  39. --worker-class ${SERVER_WORKER_CLASS:-gevent} \
  40. --worker-connections ${SERVER_WORKER_CONNECTIONS:-10} \
  41. --timeout ${GUNICORN_TIMEOUT:-200} \
  42. app:app
  43. fi
  44. fi