Severian commited on
Commit
b5f7ac8
·
verified ·
1 Parent(s): 2c2dfa1

Create entrypoint.sh

Browse files
Files changed (1) hide show
  1. entrypoint.sh +40 -0
entrypoint.sh ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ set -e
4
+
5
+ if [[ "${MIGRATION_ENABLED}" == "true" ]]; then
6
+ echo "Running migrations"
7
+ flask upgrade-db
8
+ fi
9
+
10
+ if [[ "${MODE}" == "worker" ]]; then
11
+
12
+ # Get the number of available CPU cores
13
+ if [ "${CELERY_AUTO_SCALE,,}" = "true" ]; then
14
+ # Set MAX_WORKERS to the number of available cores if not specified
15
+ AVAILABLE_CORES=$(nproc)
16
+ MAX_WORKERS=${CELERY_MAX_WORKERS:-$AVAILABLE_CORES}
17
+ MIN_WORKERS=${CELERY_MIN_WORKERS:-1}
18
+ CONCURRENCY_OPTION="--autoscale=${MAX_WORKERS},${MIN_WORKERS}"
19
+ else
20
+ CONCURRENCY_OPTION="-c ${CELERY_WORKER_AMOUNT:-1}"
21
+ fi
22
+
23
+ exec celery -A app.celery worker -P ${CELERY_WORKER_CLASS:-gevent} $CONCURRENCY_OPTION --loglevel ${LOG_LEVEL} \
24
+ -Q ${CELERY_QUEUES:-dataset,mail,ops_trace,app_deletion}
25
+
26
+ elif [[ "${MODE}" == "beat" ]]; then
27
+ exec celery -A app.celery beat --loglevel ${LOG_LEVEL}
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
+ --timeout ${GUNICORN_TIMEOUT:-200} \
37
+ --preload \
38
+ app:app
39
+ fi
40
+ fi