Example #1
0
def start(service_name):
    log_handler = init_log(service_name)

    flask_config = GLOBAL_CONFIG.get("flask").get(service_name)
    # 启动falsk
    options = {
        'threaded' : True,
    }
    host = flask_config.get("host")
    port = flask_config.get('port')
    debug_mode = flask_config.get('debug_mode')
    reg_module_name = flask_config.get("reg_module_name")

    #注册interface
    import reg_route
    reg_route.reg(reg_module_name)
    logging.info(" start app %s", service_name)

    #生成pid
    pidFile = os.environ["BASIC_PATH"] + '/bin/' + service_name + '_flask_app.pid'
    pid_ins = pid_util.PidUtil(service_name, pidFile)
    pid_ins.start()

    flask_app.get_flask_app().logger.addHandler(log_handler)
    flask_app.get_flask_app().run(host, port, debug_mode, **options)

    pid_ins.clear()

    logging.info('stop app %s', service_name)
Example #2
0
def reg(module_name):
    '''
        这里的module_name来自于config中的reg_module_name
    :param module_name:
    :return:
    '''

    app = flask_app.get_flask_app()

    if module_name == 'all_services':
        from services import reg_route
        reg_route.reg(app)


    elif module_name == 'web_api':
        from web_api import reg_route
        reg_route.reg(app)
Example #3
0
    os.environ["BASIC_PATH"] = basic_path  #basic path 放到全局的一个变量当中去
    sys.path.append( basic_path )
    sys.path.append( basic_path+'/config')
    sys.path.append( basic_path+'/helper')
    sys.path.append( basic_path+'/lib')
    sys.path.append( basic_path+'/model')
    sys.path.append( basic_path+'/interface')

init_env()

import config
from core import flask_app

def init_log():
    import log_helper
    handler = log_helper.addTimedRotatingFileHandler(config.LOG_PATH, logLevel = logging.DEBUG)
    return handler
try:
    app = flask_app.get_flask_app()
    app.logger.addHandler(init_log())

    import reg_route
    reg_route.reg('web_api')

    logging.info('start')

    application = app.wsgi_app
except:
    logging.error(traceback.format_exc())