Merge pull request #1195 from danielaskdd/env-file-check
feat: add .env file check on startup
This commit is contained in:
@@ -22,7 +22,9 @@ from lightrag.api.utils_api import (
|
|||||||
parse_args,
|
parse_args,
|
||||||
get_default_host,
|
get_default_host,
|
||||||
display_splash_screen,
|
display_splash_screen,
|
||||||
|
check_env_file,
|
||||||
)
|
)
|
||||||
|
import sys
|
||||||
from lightrag import LightRAG, __version__ as core_version
|
from lightrag import LightRAG, __version__ as core_version
|
||||||
from lightrag.api import __api_version__
|
from lightrag.api import __api_version__
|
||||||
from lightrag.types import GPTKeywordExtractionFormat
|
from lightrag.types import GPTKeywordExtractionFormat
|
||||||
@@ -595,6 +597,10 @@ def main():
|
|||||||
print("Running under Gunicorn - worker management handled by Gunicorn")
|
print("Running under Gunicorn - worker management handled by Gunicorn")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# Check .env file
|
||||||
|
if not check_env_file():
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
# Check and install dependencies
|
# Check and install dependencies
|
||||||
check_and_install_dependencies()
|
check_and_install_dependencies()
|
||||||
|
|
||||||
|
@@ -7,7 +7,7 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
import signal
|
import signal
|
||||||
import pipmaster as pm
|
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, check_env_file
|
||||||
from lightrag.kg.shared_storage import initialize_share_data, finalize_share_data
|
from lightrag.kg.shared_storage import initialize_share_data, finalize_share_data
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
@@ -47,6 +47,10 @@ def signal_handler(sig, frame):
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
# Check .env file
|
||||||
|
if not check_env_file():
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
# Check and install dependencies
|
# Check and install dependencies
|
||||||
check_and_install_dependencies()
|
check_and_install_dependencies()
|
||||||
|
|
||||||
|
@@ -6,6 +6,7 @@ import os
|
|||||||
import argparse
|
import argparse
|
||||||
from typing import Optional, List, Tuple
|
from typing import Optional, List, Tuple
|
||||||
import sys
|
import sys
|
||||||
|
from ascii_colors import ASCIIColors
|
||||||
import logging
|
import logging
|
||||||
from ascii_colors import ASCIIColors
|
from ascii_colors import ASCIIColors
|
||||||
from lightrag.api import __api_version__
|
from lightrag.api import __api_version__
|
||||||
@@ -16,6 +17,23 @@ from starlette.status import HTTP_403_FORBIDDEN
|
|||||||
from .auth import auth_handler
|
from .auth import auth_handler
|
||||||
from ..prompt import PROMPTS
|
from ..prompt import PROMPTS
|
||||||
|
|
||||||
|
def check_env_file():
|
||||||
|
"""
|
||||||
|
Check if .env file exists and handle user confirmation if needed.
|
||||||
|
Returns True if should continue, False if should exit.
|
||||||
|
"""
|
||||||
|
if not os.path.exists(".env"):
|
||||||
|
warning_msg = "Warning: .env file not found. Some features may not work properly."
|
||||||
|
ASCIIColors.yellow(warning_msg)
|
||||||
|
|
||||||
|
# Check if running in interactive terminal
|
||||||
|
if sys.stdin.isatty():
|
||||||
|
response = input("Do you want to continue? (yes/no): ")
|
||||||
|
if response.lower() != "yes":
|
||||||
|
ASCIIColors.red("Server startup cancelled")
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
# Load environment variables
|
# Load environment variables
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user