Add automatic dependency checking and installation for server startup
• Added check_and_install_dependencies() • Install missing dependencies automatically
This commit is contained in:
parent
e8d0d065f3
commit
f76cf98dbd
2 changed files with 37 additions and 7 deletions
|
|
@ -12,6 +12,7 @@ import os
|
||||||
import logging
|
import logging
|
||||||
import logging.config
|
import logging.config
|
||||||
import uvicorn
|
import uvicorn
|
||||||
|
import pipmaster as pm
|
||||||
from fastapi.staticfiles import StaticFiles
|
from fastapi.staticfiles import StaticFiles
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import configparser
|
import configparser
|
||||||
|
|
@ -501,6 +502,21 @@ def configure_logging():
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def check_and_install_dependencies():
|
||||||
|
"""Check and install required dependencies"""
|
||||||
|
required_packages = [
|
||||||
|
"uvicorn",
|
||||||
|
"tiktoken",
|
||||||
|
"fastapi",
|
||||||
|
# Add other required packages here
|
||||||
|
]
|
||||||
|
|
||||||
|
for package in required_packages:
|
||||||
|
if not pm.is_installed(package):
|
||||||
|
print(f"Installing {package}...")
|
||||||
|
pm.install(package)
|
||||||
|
print(f"{package} installed successfully")
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
# Check if running under Gunicorn
|
# Check if running under Gunicorn
|
||||||
if "GUNICORN_CMD_ARGS" in os.environ:
|
if "GUNICORN_CMD_ARGS" in os.environ:
|
||||||
|
|
@ -508,6 +524,9 @@ def main():
|
||||||
print("Running under Gunicorn - worker management handled by Gunicorn")
|
print("Running under Gunicorn - worker management handled by Gunicorn")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# Check and install dependencies
|
||||||
|
check_and_install_dependencies()
|
||||||
|
|
||||||
from multiprocessing import freeze_support
|
from multiprocessing import freeze_support
|
||||||
|
|
||||||
freeze_support()
|
freeze_support()
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,24 @@ Start LightRAG server with Gunicorn
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import signal
|
import signal
|
||||||
|
import pipmaster as pm
|
||||||
from lightrag.api.utils_api import parse_args, display_splash_screen
|
from lightrag.api.utils_api import parse_args, display_splash_screen
|
||||||
from lightrag.kg.shared_storage import initialize_share_data, finalize_share_data
|
from lightrag.kg.shared_storage import initialize_share_data, finalize_share_data
|
||||||
|
|
||||||
|
def check_and_install_dependencies():
|
||||||
|
"""Check and install required dependencies"""
|
||||||
|
required_packages = [
|
||||||
|
"gunicorn",
|
||||||
|
"tiktoken",
|
||||||
|
# Add other required packages here
|
||||||
|
]
|
||||||
|
|
||||||
|
for package in required_packages:
|
||||||
|
if not pm.is_installed(package):
|
||||||
|
print(f"Installing {package}...")
|
||||||
|
pm.install(package)
|
||||||
|
print(f"{package} installed successfully")
|
||||||
|
|
||||||
|
|
||||||
# Signal handler for graceful shutdown
|
# Signal handler for graceful shutdown
|
||||||
def signal_handler(sig, frame):
|
def signal_handler(sig, frame):
|
||||||
|
|
@ -25,6 +40,9 @@ def signal_handler(sig, frame):
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
# Check and install dependencies
|
||||||
|
check_and_install_dependencies()
|
||||||
|
|
||||||
# Register signal handlers for graceful shutdown
|
# Register signal handlers for graceful shutdown
|
||||||
signal.signal(signal.SIGINT, signal_handler) # Ctrl+C
|
signal.signal(signal.SIGINT, signal_handler) # Ctrl+C
|
||||||
signal.signal(signal.SIGTERM, signal_handler) # kill command
|
signal.signal(signal.SIGTERM, signal_handler) # kill command
|
||||||
|
|
@ -45,13 +63,6 @@ def main():
|
||||||
print(f"Workers setting: {args.workers}")
|
print(f"Workers setting: {args.workers}")
|
||||||
print("=" * 80 + "\n")
|
print("=" * 80 + "\n")
|
||||||
|
|
||||||
# Check and install gunicorn if not present
|
|
||||||
import pipmaster as pm
|
|
||||||
|
|
||||||
if not pm.is_installed("gunicorn"):
|
|
||||||
print("Installing gunicorn...")
|
|
||||||
pm.install("gunicorn")
|
|
||||||
|
|
||||||
# Import Gunicorn's StandaloneApplication
|
# Import Gunicorn's StandaloneApplication
|
||||||
from gunicorn.app.base import BaseApplication
|
from gunicorn.app.base import BaseApplication
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue