You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
2.2 KiB
60 lines
2.2 KiB
from django.core.management.base import BaseCommand, CommandError
|
|
import os
|
|
import shutil
|
|
from django.conf import settings
|
|
|
|
|
|
class Command(BaseCommand):
|
|
help = 'Сздаёт супервисор конфиги для селери'
|
|
|
|
def add_arguments(self, parser):
|
|
parser.add_argument(
|
|
'--user',
|
|
type=str,
|
|
default='www',
|
|
dest='user',
|
|
help='Пользователь от имени которого будут запускаться процессы супервизора'
|
|
)
|
|
parser.add_argument(
|
|
'--env',
|
|
type=str,
|
|
default='dev',
|
|
dest='env',
|
|
help='Тип кружения из пд которого запускается скрипт (env, dev, test)'
|
|
)
|
|
parser.add_argument(
|
|
'--celery-path',
|
|
type=str,
|
|
dest='celery_path',
|
|
help='Путь до celery'
|
|
)
|
|
|
|
def handle(self, *args, **options):
|
|
with open(settings.BASE_DIR + '/config_app/supervisor_configs/build.conf') as file_in:
|
|
text = file_in.read()
|
|
|
|
text = text.replace("$CELERY_PATH$", options['celery_path'])
|
|
text = text.replace("$USER$", options['user'])
|
|
text = text.replace("$PROJECT_PATH$", settings.BASE_DIR)
|
|
|
|
if options['env'] == 'dev':
|
|
text = text.replace("$LOG_LEVEL$", 'info')
|
|
try:
|
|
shutil.rmtree(settings.BASE_DIR + '/config_app/supervisor_configs/dist')
|
|
except FileNotFoundError:
|
|
pass
|
|
|
|
os.mkdir(settings.BASE_DIR + '/config_app/supervisor_configs/dist')
|
|
for name in ['beat', 'worker', 'flower']:
|
|
out_text = text.replace("$NAME$", name)
|
|
out_file_path = '%s/config_app/supervisor_configs/dist/%s.conf' % (settings.BASE_DIR, name)
|
|
with open(out_file_path, 'w') as file_out:
|
|
file_out.write(out_text)
|
|
|
|
try:
|
|
os.symlink(out_file_path, '/etc/supervisor/conf.d/%s.conf' % name)
|
|
except FileExistsError:
|
|
pass
|
|
|
|
else:
|
|
raise CommandError('No such environ %s use one of (dev, prod, test)')
|
|
|