fix: Set the startup environment variables (#4321)
parent
a4d8595dbf
commit
88fc5dd398
|
|
@ -1,11 +1,10 @@
|
||||||
import math
|
import math
|
||||||
|
import os
|
||||||
|
|
||||||
from django.core.management.base import BaseCommand
|
from django.core.management.base import BaseCommand
|
||||||
from django.db.models import TextChoices
|
from django.db.models import TextChoices
|
||||||
|
|
||||||
from .hands import *
|
|
||||||
from .utils import ServicesUtil
|
from .utils import ServicesUtil
|
||||||
import os
|
|
||||||
|
|
||||||
|
|
||||||
class Services(TextChoices):
|
class Services(TextChoices):
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,6 @@
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
|
||||||
from .celery_base import CeleryBaseService
|
from .celery_base import CeleryBaseService
|
||||||
|
|
||||||
__all__ = ['CeleryDefaultService']
|
__all__ = ['CeleryDefaultService']
|
||||||
|
|
@ -8,3 +11,14 @@ class CeleryDefaultService(CeleryBaseService):
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
kwargs['queue'] = 'celery'
|
kwargs['queue'] = 'celery'
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
|
|
||||||
|
def open_subprocess(self):
|
||||||
|
env = os.environ.copy()
|
||||||
|
env['SERVER_NAME'] = 'celery'
|
||||||
|
kwargs = {
|
||||||
|
'cwd': self.cwd,
|
||||||
|
'stderr': self.log_file,
|
||||||
|
'stdout': self.log_file,
|
||||||
|
'env': env
|
||||||
|
}
|
||||||
|
self._process = subprocess.Popen(self.cmd, **kwargs)
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
import subprocess
|
||||||
|
|
||||||
from .base import BaseService
|
from .base import BaseService
|
||||||
from ..hands import *
|
from ..hands import *
|
||||||
|
|
||||||
|
|
@ -35,3 +37,15 @@ class GunicornService(BaseService):
|
||||||
@property
|
@property
|
||||||
def cwd(self):
|
def cwd(self):
|
||||||
return APPS_DIR
|
return APPS_DIR
|
||||||
|
|
||||||
|
def open_subprocess(self):
|
||||||
|
# 复制当前环境变量,并设置 ENABLE_SCHEDULER=1
|
||||||
|
env = os.environ.copy()
|
||||||
|
env['SERVER_NAME'] = 'web'
|
||||||
|
kwargs = {
|
||||||
|
'cwd': self.cwd,
|
||||||
|
'stderr': self.log_file,
|
||||||
|
'stdout': self.log_file,
|
||||||
|
'env': env
|
||||||
|
}
|
||||||
|
self._process = subprocess.Popen(self.cmd, **kwargs)
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,8 @@
|
||||||
@date:2024/8/21 13:28
|
@date:2024/8/21 13:28
|
||||||
@desc:
|
@desc:
|
||||||
"""
|
"""
|
||||||
|
import subprocess
|
||||||
|
|
||||||
from maxkb.const import CONFIG
|
from maxkb.const import CONFIG
|
||||||
from .base import BaseService
|
from .base import BaseService
|
||||||
from ..hands import *
|
from ..hands import *
|
||||||
|
|
@ -22,7 +24,6 @@ class GunicornLocalModelService(BaseService):
|
||||||
@property
|
@property
|
||||||
def cmd(self):
|
def cmd(self):
|
||||||
print("\n- Start Gunicorn Local Model WSGI HTTP Server")
|
print("\n- Start Gunicorn Local Model WSGI HTTP Server")
|
||||||
os.environ.setdefault('SERVER_NAME', 'local_model')
|
|
||||||
log_format = '%(h)s %(t)s %(L)ss "%(r)s" %(s)s %(b)s '
|
log_format = '%(h)s %(t)s %(L)ss "%(r)s" %(s)s %(b)s '
|
||||||
bind = f'{CONFIG.get("LOCAL_MODEL_HOST")}:{CONFIG.get("LOCAL_MODEL_PORT")}'
|
bind = f'{CONFIG.get("LOCAL_MODEL_HOST")}:{CONFIG.get("LOCAL_MODEL_PORT")}'
|
||||||
worker = CONFIG.get("LOCAL_MODEL_HOST_WORKER", 1)
|
worker = CONFIG.get("LOCAL_MODEL_HOST_WORKER", 1)
|
||||||
|
|
@ -45,3 +46,15 @@ class GunicornLocalModelService(BaseService):
|
||||||
@property
|
@property
|
||||||
def cwd(self):
|
def cwd(self):
|
||||||
return APPS_DIR
|
return APPS_DIR
|
||||||
|
|
||||||
|
def open_subprocess(self):
|
||||||
|
# 复制当前环境变量,并设置 ENABLE_SCHEDULER=1
|
||||||
|
env = os.environ.copy()
|
||||||
|
env['SERVER_NAME'] = 'local_model'
|
||||||
|
kwargs = {
|
||||||
|
'cwd': self.cwd,
|
||||||
|
'stderr': self.log_file,
|
||||||
|
'stdout': self.log_file,
|
||||||
|
'env': env
|
||||||
|
}
|
||||||
|
self._process = subprocess.Popen(self.cmd, **kwargs)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue