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.5KB

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