mirror of https://github.com/jumpserver/jumpserver
parent
0e1d3f93ff
commit
49a166552e
|
@ -12,7 +12,6 @@ RUN yum -y install epel-release && cd /tmp/requirements && \
|
|||
RUN cd /tmp/requirements && pip install -r requirements.txt
|
||||
|
||||
COPY . /opt/jumpserver
|
||||
COPY config_example.yml /opt/jumpserver/config.yml
|
||||
VOLUME /opt/jumpserver/data
|
||||
VOLUME /opt/jumpserver/logs
|
||||
|
||||
|
|
|
@ -340,29 +340,33 @@ defaults = {
|
|||
}
|
||||
|
||||
|
||||
def load_user_config():
|
||||
sys.path.insert(0, PROJECT_DIR)
|
||||
config = Config(PROJECT_DIR, defaults)
|
||||
loaded = False
|
||||
|
||||
for i in ['config.yml', 'config.yaml']:
|
||||
if os.path.isfile(os.path.join(config.root_path, i)):
|
||||
config.from_yaml(i)
|
||||
loaded = True
|
||||
|
||||
def load_from_object(config):
|
||||
try:
|
||||
from config import config as c
|
||||
config.from_object(c)
|
||||
loaded = True
|
||||
return True
|
||||
except ImportError:
|
||||
pass
|
||||
return False
|
||||
|
||||
try:
|
||||
config.from_yaml('config.yml')
|
||||
loaded = True
|
||||
except IOError:
|
||||
pass
|
||||
|
||||
def load_from_yml(config):
|
||||
for i in ['config.yml', 'config.yaml']:
|
||||
if not os.path.isfile(os.path.join(config.root_path, i)):
|
||||
continue
|
||||
loaded = config.from_yaml(i)
|
||||
if loaded:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def load_user_config():
|
||||
sys.path.insert(0, PROJECT_DIR)
|
||||
config = Config(PROJECT_DIR, defaults)
|
||||
|
||||
loaded = load_from_object(config)
|
||||
if not loaded:
|
||||
loaded = load_from_yml(config)
|
||||
if not loaded:
|
||||
msg = """
|
||||
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
# coding: utf-8
|
||||
import os
|
||||
|
||||
from celery import shared_task, subtask
|
||||
from django.utils import timezone
|
||||
|
||||
from common.utils import get_logger, get_object_or_none
|
||||
from .celery.utils import register_as_period_task, after_app_shutdown_clean
|
||||
from .models import Task, CommandExecution
|
||||
from .models import Task, CommandExecution, CeleryTask
|
||||
|
||||
logger = get_logger(__file__)
|
||||
|
||||
|
@ -48,6 +51,24 @@ def clean_tasks_adhoc_period():
|
|||
ad.delete()
|
||||
|
||||
|
||||
@shared_task
|
||||
@register_as_period_task(interval=3600*24)
|
||||
@after_app_shutdown_clean
|
||||
def clean_celery_tasks_period():
|
||||
logger.debug("Start clean celery task history")
|
||||
one_month_ago = timezone.now() - timezone.timedelta(days=30)
|
||||
tasks = CeleryTask.objects.filter(date_start__lt=one_month_ago)
|
||||
for task in tasks:
|
||||
if os.path.isfile(task.full_log_path):
|
||||
try:
|
||||
os.remove(task.full_log_path)
|
||||
except (FileNotFoundError, PermissionError):
|
||||
pass
|
||||
task.delete()
|
||||
tasks = CeleryTask.objects.filter(date_start__isnull=True)
|
||||
tasks.delete()
|
||||
|
||||
|
||||
@shared_task
|
||||
def hello(name, callback=None):
|
||||
print("Hello {}".format(name))
|
||||
|
|
|
@ -25,7 +25,7 @@ logger = get_task_logger(__name__)
|
|||
@after_app_ready_start
|
||||
@after_app_shutdown_clean
|
||||
def delete_terminal_status_period():
|
||||
yesterday = timezone.now() - datetime.timedelta(days=3)
|
||||
yesterday = timezone.now() - datetime.timedelta(days=1)
|
||||
Status.objects.filter(date_created__lt=yesterday).delete()
|
||||
|
||||
|
||||
|
|
3
jms
3
jms
|
@ -15,7 +15,8 @@ sys.path.append(BASE_DIR)
|
|||
from apps import __version__
|
||||
|
||||
try:
|
||||
from config import config as CONFIG
|
||||
from apps.jumpserver.conf import load_user_config
|
||||
CONFIG = load_user_config()
|
||||
except ImportError:
|
||||
print("Could not find config file, `cp config_example.py config.py`")
|
||||
sys.exit(1)
|
||||
|
|
Loading…
Reference in New Issue