2023-05-15 08:51:32 +08:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
if [[ "${MIGRATION_ENABLED}" == "true" ]]; then
|
|
|
|
echo "Running migrations"
|
2024-08-05 10:55:26 +08:00
|
|
|
flask upgrade-db
|
2023-05-15 08:51:32 +08:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ "${MODE}" == "worker" ]]; then
|
2024-07-31 14:34:44 +08:00
|
|
|
|
|
|
|
# Get the number of available CPU cores
|
|
|
|
if [ "${CELERY_AUTO_SCALE,,}" = "true" ]; then
|
|
|
|
# Set MAX_WORKERS to the number of available cores if not specified
|
|
|
|
AVAILABLE_CORES=$(nproc)
|
|
|
|
MAX_WORKERS=${CELERY_MAX_WORKERS:-$AVAILABLE_CORES}
|
|
|
|
MIN_WORKERS=${CELERY_MIN_WORKERS:-1}
|
|
|
|
CONCURRENCY_OPTION="--autoscale=${MAX_WORKERS},${MIN_WORKERS}"
|
|
|
|
else
|
|
|
|
CONCURRENCY_OPTION="-c ${CELERY_WORKER_AMOUNT:-1}"
|
|
|
|
fi
|
|
|
|
|
2024-08-26 14:44:58 +08:00
|
|
|
exec celery -A app.celery worker -P ${CELERY_WORKER_CLASS:-gevent} $CONCURRENCY_OPTION --loglevel ${LOG_LEVEL} \
|
2024-07-01 14:21:17 +08:00
|
|
|
-Q ${CELERY_QUEUES:-dataset,generation,mail,ops_trace,app_deletion}
|
2024-07-31 14:34:44 +08:00
|
|
|
|
2024-01-02 15:29:18 +08:00
|
|
|
elif [[ "${MODE}" == "beat" ]]; then
|
2024-08-26 14:44:58 +08:00
|
|
|
exec celery -A app.celery beat --loglevel ${LOG_LEVEL}
|
2023-05-15 08:51:32 +08:00
|
|
|
else
|
|
|
|
if [[ "${DEBUG}" == "true" ]]; then
|
2024-07-18 07:50:54 +08:00
|
|
|
exec flask run --host=${DIFY_BIND_ADDRESS:-0.0.0.0} --port=${DIFY_PORT:-5001} --debug
|
2023-05-15 08:51:32 +08:00
|
|
|
else
|
2024-07-18 07:50:54 +08:00
|
|
|
exec gunicorn \
|
2023-05-15 08:51:32 +08:00
|
|
|
--bind "${DIFY_BIND_ADDRESS:-0.0.0.0}:${DIFY_PORT:-5001}" \
|
|
|
|
--workers ${SERVER_WORKER_AMOUNT:-1} \
|
|
|
|
--worker-class ${SERVER_WORKER_CLASS:-gevent} \
|
|
|
|
--timeout ${GUNICORN_TIMEOUT:-200} \
|
|
|
|
--preload \
|
|
|
|
app:app
|
|
|
|
fi
|
2024-07-18 07:50:54 +08:00
|
|
|
fi
|