yangdx
commited on
Commit
·
9fc9acd
1
Parent(s):
8571c18
Enhance gunicorn config handling with env vars and command line arg priority
Browse files• Add env var support for timeout/keepalive
• Prioritize CLI args over env vars
• Standardize default timeout to 150s
- gunicorn_config.py +2 -2
- run_with_gunicorn.py +21 -15
gunicorn_config.py
CHANGED
@@ -26,8 +26,8 @@ preload_app = True
|
|
26 |
worker_class = "uvicorn.workers.UvicornWorker"
|
27 |
|
28 |
# Other Gunicorn configurations
|
29 |
-
timeout = int(os.getenv("TIMEOUT",
|
30 |
-
keepalive = 5
|
31 |
|
32 |
# Logging configuration
|
33 |
errorlog = os.getenv("ERROR_LOG", log_file_path) # Default write to lightrag.log
|
|
|
26 |
worker_class = "uvicorn.workers.UvicornWorker"
|
27 |
|
28 |
# Other Gunicorn configurations
|
29 |
+
timeout = int(os.getenv("TIMEOUT", 150)) # Default 150s to match run_with_gunicorn.py
|
30 |
+
keepalive = int(os.getenv("KEEPALIVE", 5)) # Default 5s
|
31 |
|
32 |
# Logging configuration
|
33 |
errorlog = os.getenv("ERROR_LOG", log_file_path) # Default write to lightrag.log
|
run_with_gunicorn.py
CHANGED
@@ -96,21 +96,27 @@ def main():
|
|
96 |
# Import and configure the gunicorn_config module
|
97 |
import gunicorn_config
|
98 |
|
99 |
-
# Set configuration variables in gunicorn_config
|
100 |
-
gunicorn_config.workers = int(os.getenv("WORKERS",
|
101 |
-
|
102 |
-
|
103 |
-
)
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
)
|
109 |
-
|
110 |
-
#
|
111 |
-
if args.
|
112 |
-
|
113 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
114 |
|
115 |
# Set configuration options from the module
|
116 |
for key in dir(gunicorn_config):
|
|
|
96 |
# Import and configure the gunicorn_config module
|
97 |
import gunicorn_config
|
98 |
|
99 |
+
# Set configuration variables in gunicorn_config, prioritizing command line arguments
|
100 |
+
gunicorn_config.workers = args.workers if args.workers else int(os.getenv("WORKERS", 1))
|
101 |
+
|
102 |
+
# Bind configuration prioritizes command line arguments
|
103 |
+
host = args.host if args.host != "0.0.0.0" else os.getenv("HOST", "0.0.0.0")
|
104 |
+
port = args.port if args.port != 9621 else int(os.getenv("PORT", 9621))
|
105 |
+
gunicorn_config.bind = f"{host}:{port}"
|
106 |
+
|
107 |
+
# Log level configuration prioritizes command line arguments
|
108 |
+
gunicorn_config.loglevel = args.log_level.lower() if args.log_level else os.getenv("LOG_LEVEL", "info")
|
109 |
+
|
110 |
+
# Timeout configuration prioritizes command line arguments
|
111 |
+
gunicorn_config.timeout = args.timeout if args.timeout else int(os.getenv("TIMEOUT", 150))
|
112 |
+
|
113 |
+
# Keepalive configuration
|
114 |
+
gunicorn_config.keepalive = int(os.getenv("KEEPALIVE", 5))
|
115 |
+
|
116 |
+
# SSL configuration prioritizes command line arguments
|
117 |
+
if args.ssl or os.getenv("SSL", "").lower() in ("true", "1", "yes", "t", "on"):
|
118 |
+
gunicorn_config.certfile = args.ssl_certfile if args.ssl_certfile else os.getenv("SSL_CERTFILE")
|
119 |
+
gunicorn_config.keyfile = args.ssl_keyfile if args.ssl_keyfile else os.getenv("SSL_KEYFILE")
|
120 |
|
121 |
# Set configuration options from the module
|
122 |
for key in dir(gunicorn_config):
|