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.

1234567891011121314151617181920212223242526272829303132333435363738394041
  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 \
  19. --max-tasks-per-child ${MAX_TASK_PRE_CHILD:-50} --loglevel ${LOG_LEVEL:-INFO} \
  20. -Q ${CELERY_QUEUES:-dataset,mail,ops_trace,app_deletion,plugin}
  21. elif [[ "${MODE}" == "beat" ]]; then
  22. exec celery -A app.celery beat --loglevel ${LOG_LEVEL:-INFO}
  23. else
  24. if [[ "${DEBUG}" == "true" ]]; then
  25. exec flask run --host=${DIFY_BIND_ADDRESS:-0.0.0.0} --port=${DIFY_PORT:-5001} --debug
  26. else
  27. exec gunicorn \
  28. --bind "${DIFY_BIND_ADDRESS:-0.0.0.0}:${DIFY_PORT:-5001}" \
  29. --workers ${SERVER_WORKER_AMOUNT:-1} \
  30. --worker-class ${SERVER_WORKER_CLASS:-gevent} \
  31. --worker-connections ${SERVER_WORKER_CONNECTIONS:-10} \
  32. --timeout ${GUNICORN_TIMEOUT:-200} \
  33. app:app
  34. fi
  35. fi