Esempio n. 1
0
    def __init__(self, service_type, service_version, is_sm=False, db_update_dir_path=None,
                 use_mysqldb=False, use_orm=False, use_redis=False):
        self.service_type = service_type
        self.service_version = service_version
        self.thread_ls = []
        self.is_sm = is_sm
        self.db_update_dir_path = db_update_dir_path
        self.use_mysqldb = use_mysqldb
        self.use_orm = use_orm
        self.use_redis = use_redis

        self.adv = None
        self.sm_rpc = None

        logger.init_log(self.service_type, self.service_type)
        ExitHandler().add_exit_handler(self.stop_service)

        arg_parser = ArgumentParser()
        p = arg_parser.get_argparser()

        p.add_argument('--is_https', default=False, type=parser_boolean,  help="Is use http ssl connection")
        p.add_argument('--http_port', default=0, type=int,  help="The port of the http app listen")
        p.add_argument('--tcp_port', default=0, type=int,  help="The port of of the tcp rpc app listen")

        p.add_argument('--service_type', default=service_type, type=str, help="The type of the service")
        p.add_argument('--service_version', default=use_redis, type=str,  help="The version of the service")
        p.add_argument('--is_sm', default=is_sm, type=bool,  help="Whether it is the service manager")
        p.add_argument('--db_update_dir_path', default=db_update_dir_path, type=str,  help="The dir for db update use")
        p.add_argument('--use_mysqldb', default=use_mysqldb, type=parser_boolean,  help="Whether to use the mysqldb lib")
        p.add_argument('--use_orm', default=use_orm, type=parser_boolean,  help="Whether to use the orm db lib")
        p.add_argument('--use_redis', default=use_redis, type=parser_boolean,  help="Whether to use the redis cache")

        p.add_argument('--logger_err_2_mail', default=False, type=bool, help="whether logger 2 mail when error")
        p.add_argument('--logger_err_2_sms', default=False, type=bool, help="whether logger 2 sms when error")
        self.add_cmd_opts(p)

        IpFinder().is_extranet = arg_parser.args.is_extranet

        if self.db_update_dir_path:
            self._db_update()
        if self.use_mysqldb:
            self._start_mysqldb()
        if self.use_orm:
            self._start_orm()
        if self.use_redis:
            self._start_redis_client()

        args = arg_parser.args
        arg_parser.will_change = False

        self.prepare(args)
        self.init(args)
        self._set_logger(args)
        logger.set_logger_level(args.logger_level)
Esempio n. 2
0
    def __init__(self,
                 service_type,
                 service_version,
                 is_sm=False,
                 db_update_dir_path=None,
                 use_mysqldb=False,
                 use_orm=False,
                 use_redis=False):
        self.service_type = service_type
        self.service_version = service_version
        self.thread_ls = []
        self.is_sm = is_sm
        self.db_update_dir_path = db_update_dir_path
        self.use_mysqldb = use_mysqldb
        self.use_orm = use_orm
        self.use_redis = use_redis

        self.adv = None
        self.sm_rpc = None

        logger.init_log(self.service_type, self.service_type)
        ExitHandler().add_exit_handler(self.stop_service)

        arg_parser = ArgumentParser()
        p = arg_parser.get_argparser()

        self.add_cmd_opts(p)

        p.add_argument('--service_type',
                       default=service_type,
                       type=str,
                       help="The type of the service")
        p.add_argument('--service_version',
                       default=use_redis,
                       type=str,
                       help="The version of the service")
        p.add_argument('--is_sm',
                       default=is_sm,
                       type=bool,
                       help="Whether it is the service manager")
        p.add_argument('--db_update_dir_path',
                       default=db_update_dir_path,
                       type=str,
                       help="The dir for db update use")
        p.add_argument('--use_mysqldb',
                       default=use_mysqldb,
                       type=parser_boolean,
                       help="Whether to use the mysqldb lib")
        p.add_argument('--use_orm',
                       default=use_orm,
                       type=parser_boolean,
                       help="Whether to use the orm db lib")
        p.add_argument('--use_redis',
                       default=use_redis,
                       type=parser_boolean,
                       help="Whether to use the redis cache")

        p.add_argument('--logger_mask',
                       default='0000',
                       type=str,
                       help="The logger mask em es fm fs")

        IpFinder().is_extranet = arg_parser.args.is_extranet

        if not self.is_sm:
            SMParamParser(service_type=self.service_type,
                          sm_rpc=ParamCacher().sm_rpc,
                          arg_parser=p,
                          rdm_port_fun=get_random_port)

            self.add_cmd_opts_after_sm(p)

        if self.db_update_dir_path:
            self._db_update()
        if self.use_mysqldb:
            self._start_mysqldb()
        if self.use_redis:
            self._start_redis_client()

        args = arg_parser.args
        arg_parser.will_change = False

        self.init(args)
        logger.set_logger_level(args.logger_level)
Esempio n. 3
0
    def __init__(self,
                 service_type,
                 service_version,
                 is_sm=False,
                 db_update_dir_path=None,
                 use_mysqldb=False,
                 use_orm=False,
                 use_redis=False):
        self.service_type = service_type
        self.service_version = service_version
        self.thread_ls = []
        self.is_sm = is_sm
        self.db_update_dir_path = db_update_dir_path
        self.use_mysqldb = use_mysqldb
        self.use_orm = use_orm
        self.use_redis = use_redis

        self.adv = None
        self.sm_rpc = None

        setproctitle(self.service_type)

        logger.init_log(self.service_type, self.service_type)
        ExitHandler().add_exit_handler(self.stop_service)

        arg_parser = ArgumentParser()
        p = arg_parser.get_argparser()

        p.add_argument('--is_https',
                       default=False,
                       type=parser_boolean,
                       help="Is use http ssl connection")
        p.add_argument('--http_port',
                       default=0,
                       type=int,
                       help="The port of the http app listen")
        p.add_argument('--tcp_port',
                       default=0,
                       type=int,
                       help="The port of of the tcp rpc app listen")

        p.add_argument('--service_type',
                       default=service_type,
                       type=str,
                       help="The type of the service")
        p.add_argument('--service_version',
                       default=use_redis,
                       type=str,
                       help="The version of the service")
        p.add_argument('--is_sm',
                       default=is_sm,
                       type=bool,
                       help="Whether it is the service manager")
        p.add_argument('--db_update_dir_path',
                       default=db_update_dir_path,
                       type=str,
                       help="The dir for db update use")
        p.add_argument('--use_mysqldb',
                       default=use_mysqldb,
                       type=parser_boolean,
                       help="Whether to use the mysqldb lib")
        p.add_argument('--use_orm',
                       default=use_orm,
                       type=parser_boolean,
                       help="Whether to use the orm db lib")
        p.add_argument('--use_redis',
                       default=use_redis,
                       type=parser_boolean,
                       help="Whether to use the redis cache")

        p.add_argument('--logger_err_2_mail',
                       default=False,
                       type=bool,
                       help="whether logger 2 mail when error")
        p.add_argument('--logger_err_2_sms',
                       default=False,
                       type=bool,
                       help="whether logger 2 sms when error")
        self.add_cmd_opts(p)

        IpFinder().is_extranet = arg_parser.args.is_extranet

        if self.db_update_dir_path:
            self._db_update()
        if self.use_mysqldb:
            self._start_mysqldb()
        if self.use_orm:
            self._start_orm()
        if self.use_redis:
            self._start_redis_client()

        args = arg_parser.args
        arg_parser.will_change = False

        self.prepare(args)
        self.init(args)
        self._set_logger(args)
        logger.set_logger_level(args.logger_level)