Skip to content

Commit 46fa2c1

Browse files
author
hzy@singhand.com
committed
Feat: support switch dev/pro server model.
1 parent f4d943c commit 46fa2c1

File tree

2 files changed

+50
-32
lines changed

2 files changed

+50
-32
lines changed

docker/.env

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,5 +182,16 @@ REGISTER_ENABLED=1
182182
# - For OpenSearch:
183183
# COMPOSE_PROFILES=opensearch,sandbox
184184

185-
# Gunicorn setting
185+
# Gunicorn settings
186+
# ENABLE_GUNICORN controls whether the API server runs under Gunicorn.
187+
# 1 - use Gunicorn (production mode)
188+
# 0 - run `python api/ragflow_server.py` (development mode)
189+
ENABLE_GUNICORN=0
190+
191+
# GUNICORN_MODE chooses the Gunicorn worker class.
192+
# gevent - asynchronous workers based on greenlets (default)
193+
# sync - standard synchronous workers; no gevent monkey patching
194+
GUNICORN_MODE=sync
195+
196+
# Number of Gunicorn worker processes
186197
GUNICORN_WORKERS=4

docker/entrypoint.sh

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ CONSUMER_NO_BEG=0
3131
CONSUMER_NO_END=0
3232
WORKERS=1
3333
GUNICORN_WORKERS=${GUNICORN_WORKERS:-4} # Number of Gunicorn workers for the web server
34+
ENABLE_GUNICORN=${ENABLE_GUNICORN:-1} # Whether to start the web server via Gunicorn
35+
GUNICORN_MODE=${GUNICORN_MODE:-gevent} # Gunicorn worker class (gevent or sync)
3436

3537
MCP_HOST="127.0.0.1"
3638
MCP_PORT=9382
@@ -185,38 +187,43 @@ if [[ "${ENABLE_WEBSERVER}" -eq 1 ]]; then
185187
echo "Starting nginx..."
186188
/usr/sbin/nginx
187189

188-
echo "Starting ragflow_server with Gunicorn (Production Mode)..."
189-
# Get host and port from environment variables or use defaults
190-
RAGFLOW_HOST=${RAGFLOW_HOST_IP:-0.0.0.0}
191-
RAGFLOW_PORT=${RAGFLOW_HOST_PORT:-9380}
192-
GUNICORN_WORKERS=${GUNICORN_WORKERS:-4}
193-
GUNICORN_TIMEOUT=${GUNICORN_TIMEOUT:-120}
194-
195-
# Set environment variable for gevent worker class
196-
export GUNICORN_WORKER_CLASS=gevent
197-
198-
echo "Gunicorn config: Workers=${GUNICORN_WORKERS}, Host=${RAGFLOW_HOST}, Port=${RAGFLOW_PORT}, Worker Class=gevent"
199-
200-
# Check if gunicorn config file exists and use it, otherwise use command line options
201-
if [[ -f "/ragflow/conf/gunicorn.conf.py" ]]; then
202-
echo "Using Gunicorn configuration file..."
203-
exec gunicorn --config /ragflow/conf/gunicorn.conf.py 'api.wsgi:application'
190+
if [[ "${ENABLE_GUNICORN}" -eq 1 ]]; then
191+
echo "Starting ragflow_server with Gunicorn (Production Mode)..."
192+
# Get host and port from environment variables or use defaults
193+
RAGFLOW_HOST=${RAGFLOW_HOST_IP:-0.0.0.0}
194+
RAGFLOW_PORT=${RAGFLOW_HOST_PORT:-9380}
195+
GUNICORN_WORKERS=${GUNICORN_WORKERS:-4}
196+
GUNICORN_TIMEOUT=${GUNICORN_TIMEOUT:-120}
197+
198+
# Set environment variable for worker class
199+
export GUNICORN_WORKER_CLASS=${GUNICORN_MODE}
200+
201+
echo "Gunicorn config: Workers=${GUNICORN_WORKERS}, Host=${RAGFLOW_HOST}, Port=${RAGFLOW_PORT}, Worker Class=${GUNICORN_MODE}"
202+
203+
# Check if gunicorn config file exists and use it, otherwise use command line options
204+
if [[ -f "/ragflow/conf/gunicorn.conf.py" ]]; then
205+
echo "Using Gunicorn configuration file..."
206+
exec gunicorn --config /ragflow/conf/gunicorn.conf.py 'api.wsgi:application'
207+
else
208+
echo "Using Gunicorn command line configuration..."
209+
# Start gunicorn with our WSGI application
210+
exec gunicorn --workers ${GUNICORN_WORKERS} \
211+
--worker-class ${GUNICORN_MODE} \
212+
--worker-connections 1000 \
213+
--max-requests 1000 \
214+
--max-requests-jitter 100 \
215+
--timeout ${GUNICORN_TIMEOUT} \
216+
--keep-alive 2 \
217+
--preload \
218+
--bind ${RAGFLOW_HOST}:${RAGFLOW_PORT} \
219+
--access-logfile - \
220+
--error-logfile - \
221+
--log-level info \
222+
'api.wsgi:application'
223+
fi
204224
else
205-
echo "Using Gunicorn command line configuration..."
206-
# Start gunicorn with our WSGI application
207-
exec gunicorn --workers ${GUNICORN_WORKERS} \
208-
--worker-class gevent \
209-
--worker-connections 1000 \
210-
--max-requests 1000 \
211-
--max-requests-jitter 100 \
212-
--timeout ${GUNICORN_TIMEOUT} \
213-
--keep-alive 2 \
214-
--preload \
215-
--bind ${RAGFLOW_HOST}:${RAGFLOW_PORT} \
216-
--access-logfile - \
217-
--error-logfile - \
218-
--log-level info \
219-
'api.wsgi:application'
225+
echo "Starting ragflow_server in development mode..."
226+
exec "$PY" api/ragflow_server.py
220227
fi
221228
fi
222229

0 commit comments

Comments
 (0)