服务启动方式被manage.py托管

publicsignpoll
youngS 3 years ago
parent 1e1385da84
commit ac8614b54c
  1. 2
      fir_ser/api/management/commands/services/command.py
  2. 45
      fir_ser/api/management/commands/services/hands.py
  3. 6
      fir_ser/api/management/commands/services/services/base.py
  4. 10
      fir_ser/api/management/commands/upgrade.py
  5. 2
      fir_ser/api/tasks.py
  6. 8
      fir_ser/api/utils/app/supersignutils.py
  7. 7
      fir_ser/api/utils/response.py
  8. 6
      fir_ser/config.py
  9. 14
      fir_ser/fir_ser/settings.py

@ -114,7 +114,7 @@ class BaseActionCommand(BaseCommand):
'uwsgi_threads': options.get('uwsgi_threads'), 'uwsgi_threads': options.get('uwsgi_threads'),
'uwsgi_socket_mode': options.get('uwsgi_socket_mode'), 'uwsgi_socket_mode': options.get('uwsgi_socket_mode'),
'uid': options.get('uid'), 'uid': options.get('uid'),
'gid': options.get('gid'), 'gid': options.get('uid') if options.get('gid') in ['root'] else options.get('gid'),
} }
services = Services.get_service_objects(service_names=service_names, **service_kwargs) services = Services.get_service_objects(service_names=service_names, **service_kwargs)

@ -2,13 +2,14 @@ import os
import sys import sys
import logging import logging
from django.conf import settings from django.conf import settings
from config import BASE_DIR
import time
import subprocess
from config import BASECONF from config import BASECONF
try: try:
from apps.jumpserver import const __version__ = BASECONF.VERSION
__version__ = const.VERSION
except ImportError as e: except ImportError as e:
print("Not found __version__: {}".format(e)) print("Not found __version__: {}".format(e))
print("Python is: ") print("Python is: ")
@ -26,3 +27,41 @@ BASE_DIR = settings.BASE_DIR
APPS_DIR = BASE_DIR APPS_DIR = BASE_DIR
LOG_DIR = os.path.join(BASE_DIR, 'logs') LOG_DIR = os.path.join(BASE_DIR, 'logs')
TMP_DIR = os.path.join(BASE_DIR, 'tmp') TMP_DIR = os.path.join(BASE_DIR, 'tmp')
def check_database_connection():
os.chdir(BASE_DIR)
for i in range(60):
logging.info("Check database connection ...")
_code = subprocess.call("python manage.py showmigrations api ", shell=True)
if _code == 0:
logging.info("Database connect success")
return
time.sleep(1)
logging.error("Connection database failed, exit")
sys.exit(10)
def check_migrations():
_cmd = "python manage.py showmigrations | grep '\[.\]' | grep -v '\[X\]'"
_code = subprocess.call(_cmd, shell=True, cwd=BASE_DIR)
if _code == 1:
return
def perform_db_migrate():
logging.info("Check database structure change ...")
os.chdir(BASE_DIR)
logging.info("Migrate model change to database ...")
_code = subprocess.call('python3 manage.py migrate', shell=True)
if _code == 0:
return
logging.error('Perform migrate failed, exit')
sys.exit(11)
def prepare():
check_database_connection()
check_migrations()
perform_db_migrate()

@ -1,10 +1,8 @@
import abc import abc
import time
import shutil import shutil
import psutil import psutil
import datetime import datetime
import threading import threading
import subprocess
import pwd import pwd
from ..hands import * from ..hands import *
@ -123,6 +121,8 @@ class BaseService(object):
# -- action -- # -- action --
def open_subprocess(self): def open_subprocess(self):
self.set_work_dir_owner() self.set_work_dir_owner()
if self.name in ['uwsgi']:
prepare()
kwargs = {'cwd': self.cwd, 'stderr': self.log_file, 'stdout': self.log_file} kwargs = {'cwd': self.cwd, 'stderr': self.log_file, 'stdout': self.log_file}
self._process = subprocess.Popen(self.cmd, **kwargs) self._process = subprocess.Popen(self.cmd, **kwargs)
@ -142,7 +142,7 @@ class BaseService(object):
uid = get_user_id(self.uid) uid = get_user_id(self.uid)
gid = get_user_id(self.gid) gid = get_user_id(self.gid)
u_gid = uid if uid else gid u_gid = uid if uid else gid
if u_gid: if u_gid is not None:
for (dir_path, dir_names, filenames) in os.walk(LOG_DIR): for (dir_path, dir_names, filenames) in os.walk(LOG_DIR):
for filename in filenames + dir_names: for filename in filenames + dir_names:
os.chown(uid=u_gid, gid=u_gid, path=os.path.join(dir_path, filename)) os.chown(uid=u_gid, gid=u_gid, path=os.path.join(dir_path, filename))

@ -0,0 +1,10 @@
from django.core.management.base import BaseCommand
from api.management.commands.services.hands import perform_db_migrate
class Command(BaseCommand):
help = 'upgrade database'
def handle(self, *args, **options):
perform_db_migrate()

@ -18,6 +18,7 @@ from api.utils.geetest.geetest_utils import check_bypass_status
from api.views.login import get_login_type from api.views.login import get_login_type
from fir_ser.celery import app from fir_ser.celery import app
from fir_ser.settings import LOGIN, CHANGER, REGISTER
@shared_task @shared_task
@ -66,6 +67,7 @@ def sync_download_times_job():
@app.task @app.task
def check_bypass_status_job(): def check_bypass_status_job():
if LOGIN.get("geetest") or CHANGER.get('geetest') or REGISTER.get('geetest'):
check_bypass_status() check_bypass_status()

@ -8,7 +8,7 @@ import uuid, xmltodict, os, logging, time
import zipfile import zipfile
from api.utils.response import BaseResponse from api.utils.response import BaseResponse
from fir_ser.settings import SUPER_SIGN_ROOT, MEDIA_ROOT, SERVER_DOMAIN, MOBILECONFIG_SIGN_SSL, MSGTEMPLATE from fir_ser.settings import SUPER_SIGN_ROOT, MEDIA_ROOT, SERVER_DOMAIN, MOBILE_CONFIG_SIGN_SSL, MSGTEMPLATE
from api.utils.app.iossignapi import ResignApp, AppDeveloperApiV2 from api.utils.app.iossignapi import ResignApp, AppDeveloperApiV2
from api.models import APPSuperSignUsedInfo, AppUDID, AppIOSDeveloperInfo, AppReleaseInfo, Apps, APPToDeveloper, \ from api.models import APPSuperSignUsedInfo, AppUDID, AppIOSDeveloperInfo, AppReleaseInfo, Apps, APPToDeveloper, \
UDIDsyncDeveloper, DeveloperAppID, DeveloperDevicesID UDIDsyncDeveloper, DeveloperAppID, DeveloperDevicesID
@ -82,9 +82,9 @@ def udid_bytes_to_dict(xml_stream):
def make_sign_udid_mobile_config(udid_url, app_id, bundle_id, app_name): def make_sign_udid_mobile_config(udid_url, app_id, bundle_id, app_name):
if MOBILECONFIG_SIGN_SSL.get("open"): if MOBILE_CONFIG_SIGN_SSL.get("open"):
ssl_key_path = MOBILECONFIG_SIGN_SSL.get("ssl_key_path", None) ssl_key_path = MOBILE_CONFIG_SIGN_SSL.get("ssl_key_path", None)
ssl_pem_path = MOBILECONFIG_SIGN_SSL.get("ssl_pem_path", None) ssl_pem_path = MOBILE_CONFIG_SIGN_SSL.get("ssl_pem_path", None)
if ssl_key_path and ssl_pem_path and os.path.isfile(ssl_key_path) and os.path.isfile(ssl_pem_path): if ssl_key_path and ssl_pem_path and os.path.isfile(ssl_key_path) and os.path.isfile(ssl_pem_path):
mobile_config_tmp_dir = os.path.join(SUPER_SIGN_ROOT, 'tmp', 'mobile_config') mobile_config_tmp_dir = os.path.join(SUPER_SIGN_ROOT, 'tmp', 'mobile_config')

@ -1,3 +1,10 @@
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# project: 4月
# author: NinEveN
# date: 2021/4/16
class BaseResponse(object): class BaseResponse(object):
def __init__(self): def __init__(self):
self.code = 1000 self.code = 1000

@ -12,6 +12,8 @@ BASE_DIR = os.path.dirname(os.path.abspath(__file__))
class BASECONF(object): class BASECONF(object):
VERSION = '1.3.1'
DEBUG = True DEBUG = True
SECRET_KEY = 'j!g@^bc(z(a3*i&kp$_@bgb)bug&^#3=amch!3lz&1x&s6ss6t' SECRET_KEY = 'j!g@^bc(z(a3*i&kp$_@bgb)bug&^#3=amch!3lz&1x&s6ss6t'
@ -121,7 +123,7 @@ class AUTHCONF(object):
'email': True, # 邮件登录 'email': True, # 邮件登录
'up': False, # 密码登录 'up': False, # 密码登录
'third': { 'third': {
'wxp': False # 微信公众号登录,需要在 THIRDLOGINCONF 配置好微信公众号登录 'wxp': THIRDLOGINCONF.wx_official.get('active') # 微信公众号登录,需要在 THIRDLOGINCONF 配置好微信公众号登录
}, },
} }
} }
@ -233,7 +235,7 @@ class SENDERCONF(object):
class IPACONF(object): class IPACONF(object):
MOBILECONFIG_SIGN_SSL = { MOBILE_CONFIG_SIGN_SSL = {
# 描述文件是否签名,默认是关闭状态;如果开启,并且ssl_key_path 和 ssl_pem_path 正常,则使用填写的ssl进行签名,否则默认不签名 # 描述文件是否签名,默认是关闭状态;如果开启,并且ssl_key_path 和 ssl_pem_path 正常,则使用填写的ssl进行签名,否则默认不签名
'open': True, 'open': True,
'ssl_key_path': '/data/cert/%s.key' % API_DOMAIN.split("://")[1], 'ssl_key_path': '/data/cert/%s.key' % API_DOMAIN.split("://")[1],

@ -232,7 +232,7 @@ SYNC_CACHE_TO_DATABASE = {
SERVER_DOMAIN = BASECONF.SERVER_DOMAIN SERVER_DOMAIN = BASECONF.SERVER_DOMAIN
MOBILECONFIG_SIGN_SSL = IPACONF.MOBILECONFIG_SIGN_SSL MOBILE_CONFIG_SIGN_SSL = IPACONF.MOBILE_CONFIG_SIGN_SSL
DEFAULT_MOBILEPROVISION = IPACONF.DEFAULT_MOBILEPROVISION DEFAULT_MOBILEPROVISION = IPACONF.DEFAULT_MOBILEPROVISION
# DEFAULT_MOBILEPROVISION = { # DEFAULT_MOBILEPROVISION = {
@ -399,12 +399,12 @@ CELERY_BEAT_SCHEDULE = {
'schedule': SYNC_CACHE_TO_DATABASE.get("auto_check_ios_developer_active_times"), 'schedule': SYNC_CACHE_TO_DATABASE.get("auto_check_ios_developer_active_times"),
'args': () 'args': ()
}, },
'start_api_sever_do_clean': { # 'start_api_sever_do_clean': {
'task': 'api.tasks.start_api_sever_do_clean', # 'task': 'api.tasks.start_api_sever_do_clean',
'schedule': 6, # 'schedule': 6,
'args': (), # 'args': (),
'one_off': True # 'one_off': True
}, # },
'sync_wx_access_token_job': { 'sync_wx_access_token_job': {
'task': 'api.tasks.sync_wx_access_token_job', 'task': 'api.tasks.sync_wx_access_token_job',
'schedule': SYNC_CACHE_TO_DATABASE.get("wx_get_access_token_times"), 'schedule': SYNC_CACHE_TO_DATABASE.get("wx_get_access_token_times"),

Loading…
Cancel
Save