yangdx
commited on
Commit
·
0cfee1e
1
Parent(s):
6d1b218
Add automatic dependency checking and installation for server startup
Browse files• Added check_and_install_dependencies()
• Install missing dependencies automatically
- lightrag/api/lightrag_server.py +19 -0
- run_with_gunicorn.py +18 -7
lightrag/api/lightrag_server.py
CHANGED
@@ -12,6 +12,7 @@ import os
|
|
12 |
import logging
|
13 |
import logging.config
|
14 |
import uvicorn
|
|
|
15 |
from fastapi.staticfiles import StaticFiles
|
16 |
from pathlib import Path
|
17 |
import configparser
|
@@ -501,6 +502,21 @@ def configure_logging():
|
|
501 |
)
|
502 |
|
503 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
504 |
def main():
|
505 |
# Check if running under Gunicorn
|
506 |
if "GUNICORN_CMD_ARGS" in os.environ:
|
@@ -508,6 +524,9 @@ def main():
|
|
508 |
print("Running under Gunicorn - worker management handled by Gunicorn")
|
509 |
return
|
510 |
|
|
|
|
|
|
|
511 |
from multiprocessing import freeze_support
|
512 |
|
513 |
freeze_support()
|
|
|
12 |
import logging
|
13 |
import logging.config
|
14 |
import uvicorn
|
15 |
+
import pipmaster as pm
|
16 |
from fastapi.staticfiles import StaticFiles
|
17 |
from pathlib import Path
|
18 |
import configparser
|
|
|
502 |
)
|
503 |
|
504 |
|
505 |
+
def check_and_install_dependencies():
|
506 |
+
"""Check and install required dependencies"""
|
507 |
+
required_packages = [
|
508 |
+
"uvicorn",
|
509 |
+
"tiktoken",
|
510 |
+
"fastapi",
|
511 |
+
# Add other required packages here
|
512 |
+
]
|
513 |
+
|
514 |
+
for package in required_packages:
|
515 |
+
if not pm.is_installed(package):
|
516 |
+
print(f"Installing {package}...")
|
517 |
+
pm.install(package)
|
518 |
+
print(f"{package} installed successfully")
|
519 |
+
|
520 |
def main():
|
521 |
# Check if running under Gunicorn
|
522 |
if "GUNICORN_CMD_ARGS" in os.environ:
|
|
|
524 |
print("Running under Gunicorn - worker management handled by Gunicorn")
|
525 |
return
|
526 |
|
527 |
+
# Check and install dependencies
|
528 |
+
check_and_install_dependencies()
|
529 |
+
|
530 |
from multiprocessing import freeze_support
|
531 |
|
532 |
freeze_support()
|
run_with_gunicorn.py
CHANGED
@@ -6,9 +6,24 @@ Start LightRAG server with Gunicorn
|
|
6 |
import os
|
7 |
import sys
|
8 |
import signal
|
|
|
9 |
from lightrag.api.utils_api import parse_args, display_splash_screen
|
10 |
from lightrag.kg.shared_storage import initialize_share_data, finalize_share_data
|
11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
# Signal handler for graceful shutdown
|
14 |
def signal_handler(sig, frame):
|
@@ -25,6 +40,9 @@ def signal_handler(sig, frame):
|
|
25 |
|
26 |
|
27 |
def main():
|
|
|
|
|
|
|
28 |
# Register signal handlers for graceful shutdown
|
29 |
signal.signal(signal.SIGINT, signal_handler) # Ctrl+C
|
30 |
signal.signal(signal.SIGTERM, signal_handler) # kill command
|
@@ -45,13 +63,6 @@ def main():
|
|
45 |
print(f"Workers setting: {args.workers}")
|
46 |
print("=" * 80 + "\n")
|
47 |
|
48 |
-
# Check and install gunicorn if not present
|
49 |
-
import pipmaster as pm
|
50 |
-
|
51 |
-
if not pm.is_installed("gunicorn"):
|
52 |
-
print("Installing gunicorn...")
|
53 |
-
pm.install("gunicorn")
|
54 |
-
|
55 |
# Import Gunicorn's StandaloneApplication
|
56 |
from gunicorn.app.base import BaseApplication
|
57 |
|
|
|
6 |
import os
|
7 |
import sys
|
8 |
import signal
|
9 |
+
import pipmaster as pm
|
10 |
from lightrag.api.utils_api import parse_args, display_splash_screen
|
11 |
from lightrag.kg.shared_storage import initialize_share_data, finalize_share_data
|
12 |
|
13 |
+
def check_and_install_dependencies():
|
14 |
+
"""Check and install required dependencies"""
|
15 |
+
required_packages = [
|
16 |
+
"gunicorn",
|
17 |
+
"tiktoken",
|
18 |
+
# Add other required packages here
|
19 |
+
]
|
20 |
+
|
21 |
+
for package in required_packages:
|
22 |
+
if not pm.is_installed(package):
|
23 |
+
print(f"Installing {package}...")
|
24 |
+
pm.install(package)
|
25 |
+
print(f"{package} installed successfully")
|
26 |
+
|
27 |
|
28 |
# Signal handler for graceful shutdown
|
29 |
def signal_handler(sig, frame):
|
|
|
40 |
|
41 |
|
42 |
def main():
|
43 |
+
# Check and install dependencies
|
44 |
+
check_and_install_dependencies()
|
45 |
+
|
46 |
# Register signal handlers for graceful shutdown
|
47 |
signal.signal(signal.SIGINT, signal_handler) # Ctrl+C
|
48 |
signal.signal(signal.SIGTERM, signal_handler) # kill command
|
|
|
63 |
print(f"Workers setting: {args.workers}")
|
64 |
print("=" * 80 + "\n")
|
65 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
# Import Gunicorn's StandaloneApplication
|
67 |
from gunicorn.app.base import BaseApplication
|
68 |
|