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)
def start(service_name): init_js_config_file() 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") print reg_module_name # 注册interface import reg_route reg_route.reg(reg_module_name) print reg_route logging.info(" start app %s", service_name) # 生成pid pid_file = os.environ[ "BASIC_PATH"] + '/bin/' + service_name + '_flask_app.pid' pid_ins = pid_util.PidUtil(service_name, pid_file) pid_ins.start() app = flask_app.get_flask_app() # secret_key两种方式:1.固定字符串 2.随机random:每次app重启,浏览器session会失效,用户需重登 app.config['SECRET_KEY'] = 'kvmmgr_666_lee#!&@!*@%' login_manager = LoginManager() # flask-login注册用户登录 @login_manager.user_loader def load_user(userid): user = user_info.UserInfo().get_user(userid) return user login_manager.init_app(app) app.logger.addHandler(log_handler) app.run(host, port, debug_mode, **options) pid_ins.clear() logging.info('stop app %s', service_name)
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())
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())