entrypoint.sh 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/bin/bash
  2. set -e
  3. if [[ "${MIGRATION_ENABLED}" == "true" ]]; then
  4. echo "Running migrations"
  5. flask upgrade-db
  6. fi
  7. if [[ "${MODE}" == "worker" ]]; then
  8. # Get the number of available CPU cores
  9. if [ "${CELERY_AUTO_SCALE,,}" = "true" ]; then
  10. # Set MAX_WORKERS to the number of available cores if not specified
  11. AVAILABLE_CORES=$(nproc)
  12. MAX_WORKERS=${CELERY_MAX_WORKERS:-$AVAILABLE_CORES}
  13. MIN_WORKERS=${CELERY_MIN_WORKERS:-1}
  14. CONCURRENCY_OPTION="--autoscale=${MAX_WORKERS},${MIN_WORKERS}"
  15. else
  16. CONCURRENCY_OPTION="-c ${CELERY_WORKER_AMOUNT:-1}"
  17. fi
  18. exec celery -A app.celery worker -P ${CELERY_WORKER_CLASS:-gevent} $CONCURRENCY_OPTION --loglevel ${LOG_LEVEL} \
  19. -Q ${CELERY_QUEUES:-dataset,generation,mail,ops_trace,app_deletion}
  20. elif [[ "${MODE}" == "beat" ]]; then
  21. exec celery -A app.celery beat --loglevel ${LOG_LEVEL}
  22. else
  23. if [[ "${DEBUG}" == "true" ]]; then
  24. exec flask run --host=${DIFY_BIND_ADDRESS:-0.0.0.0} --port=${DIFY_PORT:-5001} --debug
  25. else
  26. exec gunicorn \
  27. --bind "${DIFY_BIND_ADDRESS:-0.0.0.0}:${DIFY_PORT:-5001}" \
  28. --workers ${SERVER_WORKER_AMOUNT:-1} \
  29. --worker-class ${SERVER_WORKER_CLASS:-gevent} \
  30. --timeout ${GUNICORN_TIMEOUT:-200} \
  31. --preload \
  32. app:app
  33. fi
  34. fi