This repository has been archived on 2024-10-27. You can view files and clone it, but cannot push or open issues or pull requests.
local-llm-server/other/gunicorn_conf.py

55 lines
1.6 KiB
Python

from llm_server.helpers import resolve_path
try:
import gevent.monkey
gevent.monkey.patch_all()
except ImportError:
pass
import logging
import os
import sys
import time
from pathlib import Path
from llm_server.config.global_config import GlobalConfig
from llm_server.config.load import load_config
from llm_server.custom_redis import redis
from llm_server.database.conn import Database
from llm_server.database.create import create_db
from llm_server.logging import init_logging, create_logger
def post_fork(server, worker):
"""
Initalize the worker after gunicorn has forked. This is done to avoid issues with the database manager.
"""
script_path = Path(os.path.dirname(os.path.realpath(__file__)))
config_path_environ = os.getenv("CONFIG_PATH")
if config_path_environ:
config_path = config_path_environ
else:
config_path = script_path / '../config/config.yml'
config_path = resolve_path(config_path)
success, msg = load_config(config_path)
if not success:
logger = logging.getLogger('llm_server')
logger.setLevel(logging.INFO)
logger.error(f'Failed to load config: {msg}')
sys.exit(1)
init_logging()
logger = create_logger('Server')
logger.debug('Debug logging enabled.')
while not redis.get('daemon_started', dtype=bool):
logger.warning('Could not find the key daemon_started in Redis. Did you forget to start the daemon process?')
time.sleep(10)
Database.initialise(**GlobalConfig.get().postgresql.dict())
create_db()
logger.info('Started HTTP worker!')