mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-09-09 19:29:48 +00:00
merge: with v3
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import multiprocessing
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
from django.db.models import TextChoices
|
||||
from .utils import ServicesUtil
|
||||
@@ -6,7 +7,6 @@ from .hands import *
|
||||
|
||||
class Services(TextChoices):
|
||||
gunicorn = 'gunicorn', 'gunicorn'
|
||||
daphne = 'daphne', 'daphne'
|
||||
celery_ansible = 'celery_ansible', 'celery_ansible'
|
||||
celery_default = 'celery_default', 'celery_default'
|
||||
beat = 'beat', 'beat'
|
||||
@@ -22,7 +22,6 @@ class Services(TextChoices):
|
||||
from . import services
|
||||
services_map = {
|
||||
cls.gunicorn.value: services.GunicornService,
|
||||
cls.daphne: services.DaphneService,
|
||||
cls.flower: services.FlowerService,
|
||||
cls.celery_default: services.CeleryDefaultService,
|
||||
cls.celery_ansible: services.CeleryAnsibleService,
|
||||
@@ -30,13 +29,9 @@ class Services(TextChoices):
|
||||
}
|
||||
return services_map.get(name)
|
||||
|
||||
@classmethod
|
||||
def ws_services(cls):
|
||||
return [cls.daphne]
|
||||
|
||||
@classmethod
|
||||
def web_services(cls):
|
||||
return [cls.gunicorn, cls.daphne, cls.flower]
|
||||
return [cls.gunicorn, cls.flower]
|
||||
|
||||
@classmethod
|
||||
def celery_services(cls):
|
||||
@@ -97,11 +92,15 @@ class BaseActionCommand(BaseCommand):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
def add_arguments(self, parser):
|
||||
cores = 10
|
||||
if (multiprocessing.cpu_count() * 2 + 1) < cores:
|
||||
cores = multiprocessing.cpu_count() * 2 + 1
|
||||
|
||||
parser.add_argument(
|
||||
'services', nargs='+', choices=Services.export_services_values(), help='Service',
|
||||
)
|
||||
parser.add_argument('-d', '--daemon', nargs="?", const=True)
|
||||
parser.add_argument('-w', '--worker', type=int, nargs="?", default=4)
|
||||
parser.add_argument('-w', '--worker', type=int, nargs="?", default=cores)
|
||||
parser.add_argument('-f', '--force', nargs="?", const=True)
|
||||
|
||||
def initial_util(self, *args, **options):
|
||||
|
@@ -1,6 +1,5 @@
|
||||
from .beat import *
|
||||
from .celery_ansible import *
|
||||
from .celery_default import *
|
||||
from .daphne import *
|
||||
from .flower import *
|
||||
from .gunicorn import *
|
||||
|
@@ -44,7 +44,9 @@ class BaseService(object):
|
||||
if self.is_running:
|
||||
msg = f'{self.name} is running: {self.pid}.'
|
||||
else:
|
||||
msg = f'{self.name} is stopped.'
|
||||
msg = '\033[31m{} is stopped.\033[0m\nYou can manual start it to find the error: \n' \
|
||||
' $ cd {}\n' \
|
||||
' $ {}'.format(self.name, self.cwd, ' '.join(self.cmd))
|
||||
print(msg)
|
||||
|
||||
# -- log --
|
||||
|
@@ -1,25 +0,0 @@
|
||||
from ..hands import *
|
||||
from .base import BaseService
|
||||
|
||||
__all__ = ['DaphneService']
|
||||
|
||||
|
||||
class DaphneService(BaseService):
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
|
||||
@property
|
||||
def cmd(self):
|
||||
print("\n- Start Daphne ASGI WS Server")
|
||||
|
||||
cmd = [
|
||||
'daphne', 'jumpserver.asgi:application',
|
||||
'-b', HTTP_HOST,
|
||||
'-p', str(WS_PORT),
|
||||
]
|
||||
return cmd
|
||||
|
||||
@property
|
||||
def cwd(self):
|
||||
return APPS_DIR
|
@@ -16,11 +16,11 @@ class GunicornService(BaseService):
|
||||
|
||||
log_format = '%(h)s %(t)s %(L)ss "%(r)s" %(s)s %(b)s '
|
||||
bind = f'{HTTP_HOST}:{HTTP_PORT}'
|
||||
|
||||
cmd = [
|
||||
'gunicorn', 'jumpserver.wsgi',
|
||||
'gunicorn', 'jumpserver.asgi:application',
|
||||
'-b', bind,
|
||||
'-k', 'gthread',
|
||||
'--threads', '10',
|
||||
'-k', 'uvicorn.workers.UvicornWorker',
|
||||
'-w', str(self.worker),
|
||||
'--max-requests', '4096',
|
||||
'--access-logformat', log_format,
|
||||
|
@@ -76,7 +76,6 @@ class ServicesUtil(object):
|
||||
def clean_up(self):
|
||||
if not self.EXIT_EVENT.is_set():
|
||||
self.EXIT_EVENT.set()
|
||||
|
||||
self.stop()
|
||||
|
||||
def show_status(self):
|
||||
|
Reference in New Issue
Block a user