def init(self):
        self.pubsub_timeout = int(config.get('system', 'pubsub_timeout'), 0)
        self.loop_count = 100
        self.job_periodic = tornado.ioloop.PeriodicCallback(self._periodic_callback, 1000)
        self.job_periodic.start()

        if not config.has_section("redis"):
            return

        redis_enable = config.get('redis', 'enable')
        if redis_enable != "true":
            return

        redis_host = config.get('redis', 'host')
        redis_port = int(config.get('redis', 'port'), 0)
        redis_password = config.get('redis', 'password')
        self.redis_sub = tornadoredis.Client(
            host=redis_host,
            port=redis_port,
            password=redis_password)

        self.redis_pub = tornadoredis.Client(
            host=redis_host,
            port=redis_port,
            password=redis_password)
        self.redis_pub.connect()

        yield tornado.gen.Task(self.redis_sub.subscribe, self.REDIS_PUBSU_CHANEL_ID)
        self.redis_sub.listen(self.on_redis_message)
Example #2
0
    def _init_handlers(self):
        """
        @summary: 加载应用程序模块

        @return: 初始化成功返回True,否则返回False
        """
        handlers = []
        if config.has_section("services"):
            if config.has_option("services", "enable_pub") and \
                            config.get("services", "enable_pub", "0") == "1":
                handlers.append(((r"/sub/(.+)"), SubHandler))
                handlers.append(((r"/pub/(.+)"), PubHandler))
                
                #
                # 批量订阅支持
                #
                handlers.append(((r"/subs"), SubsHandler))
                handlers.append(((r"/pubs"), PubsHandler))

        handlers.append(((r"/logs"), LogHandler))
        handlers.append(((r"/watch"), WatchHandler))
        host_pattern = ".*$"
        if len(handlers) <= 0:
            return False

        self.add_handlers(host_pattern, handlers)
        return True
Example #3
0
    def _init_piwik(self):
        """
        @summary: 初始化统计模块piwik

        @return: 初始化成功返回True,否则返回False
        """
        if not config.has_section("piwik") or \
            not config.has_option("piwik", "enable"):
            return False

        enable_piwik = config.get("piwik", "enable", "false")
        if enable_piwik != "true":
            return True

        self.enable_piwik = True
        return True
Example #4
0
    def init(self):
        """
        @summary: 初始化所有部分

        @return: 初始化成功返回
        """
        #
        # 初始化处理句柄
        #
        ret = self._init_handlers()
        if not ret:
            return ret

        #
        # 初始化redis监控句柄
        #
        self.pub_sub.init()

        #
        # 初始化piwik统计模块
        #
        self._init_piwik()
        
        if not config.has_section("system"):
            return ret

        #
        # 添加ip检测开关量
        #
        if config.has_option("system", "enable_ip_auth"):
            enable_ip_auth = config.get("system", "trust_ips", "false")
            if enable_ip_auth == "true":
                self.ip_auth = True

        if not config.has_option("system", "trust_ips"):
            return ret

        trust_ips = config.get("system", "trust_ips", "0")
        trust_ip_list = trust_ips.split('|')
        for ip in trust_ip_list:
            if ip in self.trust_ips:
                continue
            self.trust_ips.append(ip)
        return ret