Пример #1
0
 def init_mysql(self):
     hostname = 'localhost'
     user = '******'
     passwd = 'bingchennetwork'
     port = 3306
     dbname = 'san'
     charset = 'utf8'
     dbpool.initPool(host = hostname,
                     user = user,
                     passwd = passwd,
                     port = port,
                     db = dbname,
                     charset = charset)
Пример #2
0
 def config(self, config, servername=None, dbconfig=None,
             memconfig=None, masterconf=None):
     '''配置服务器
     '''
     GlobalObject().json_config = config
     netport = config.get('netport')#客户端连接
     webport = config.get('webport')#http连接
     rootport = config.get('rootport')#root节点配置
     self.remoteportlist = config.get('remoteport',[])#remote节点配置列表
     if not servername:
         servername = config.get('name')#服务器名称
     logpath = config.get('log')#日志
     hasdb = config.get('db')#数据库连接
     hasmem = config.get('mem')#memcached连接
     app = config.get('app')#入口模块名称
     cpuid = config.get('cpu')#绑定cpu
     mreload = config.get('reload')#重新加载模块名称
     self.servername = servername
     if masterconf:
         masterport = masterconf.get('rootport')
         masterhost = masterconf.get('roothost')
         self.master_remote = RemoteObject(servername)
         addr = ('localhost',masterport) if not masterhost else (masterhost,masterport)
         self.master_remote.connect(addr)
         GlobalObject().masterremote = self.master_remote
         
     if netport:
         self.netfactory = LiberateFactory()
         netservice = services.CommandService("netservice")
         self.netfactory.addServiceChannel(netservice)
         reactor.listenTCP(netport,self.netfactory)
         
     if webport:
         self.webroot = vhost.NameVirtualHost()
         GlobalObject().webroot = self.webroot
         reactor.listenTCP(webport, DelaySite(self.webroot))
         
     if rootport:
         self.root = PBRoot()
         rootservice = services.Service("rootservice")
         self.root.addServiceChannel(rootservice)
         reactor.listenTCP(rootport, BilateralFactory(self.root))
         
     for cnf in self.remoteportlist:
         rname = cnf.get('rootname')
         self.remote[rname] = RemoteObject(self.servername)
         
     if hasdb and dbconfig:
         log.msg(str(dbconfig))
         dbpool.initPool(**dbconfig)
         
     if hasmem and memconfig:
         urls = memconfig.get('urls')
         hostname = str(memconfig.get('hostname'))
         mclient.connect(urls, hostname)
         
     if logpath:
         log.addObserver(loogoo(logpath))#日志处理
     log.startLogging(sys.stdout)
     
     if cpuid:
         affinity.set_process_affinity_mask(os.getpid(), cpuid)
     GlobalObject().config(netfactory = self.netfactory, root=self.root,
                 remote = self.remote)
     if app:
         __import__(app)
     if mreload:
         GlobalObject().reloadmodule = __import__(mreload)
     GlobalObject().remote_connect = self.remote_connect
     import admin
Пример #3
0
    def config(self,
               config,
               servername=None,
               dbconfig=None,
               memconfig=None,
               masterconf=None):
        '''配置服务器
        '''
        GlobalObject().json_config = config
        netport = config.get('netport')  #客户端连接
        webport = config.get('webport')  #http连接
        rootport = config.get('rootport')  #root节点配置
        self.remoteportlist = config.get('remoteport', [])  #remote节点配置列表
        if not servername:
            servername = config.get('name')  #服务器名称
        logpath = config.get('log')  #日志
        hasdb = config.get('db')  #数据库连接
        hasmem = config.get('mem')  #memcached连接
        app = config.get('app')  #入口模块名称
        cpuid = config.get('cpu')  #绑定cpu
        mreload = config.get('reload')  #重新加载模块名称
        self.servername = servername
        if masterconf:
            masterport = masterconf.get('rootport')
            masterhost = masterconf.get('roothost')
            self.master_remote = RemoteObject(servername, "master")
            addr = ('localhost',
                    masterport) if not masterhost else (masterhost, masterport)
            self.master_remote.connect(addr)
            GlobalObject().masterremote = self.master_remote

        if netport:
            self.netfactory = LiberateFactory()
            netservice = services.CommandService("netservice")
            self.netfactory.addServiceChannel(netservice)
            reactor.listenTCP(netport, self.netfactory)

        if webport:
            self.webroot = vhost.NameVirtualHost()
            GlobalObject().webroot = self.webroot
            reactor.listenTCP(webport, DelaySite(self.webroot))

        if rootport:
            self.root = PBRoot()
            rootservice = services.Service("rootservice")
            self.root.addServiceChannel(rootservice)
            reactor.listenTCP(rootport, BilateralFactory(self.root))

        for cnf in self.remoteportlist:
            rname = cnf.get('rootname')
            self.remote[rname] = RemoteObject(self.servername, rname)

        if hasdb and dbconfig:
            log.msg(str(dbconfig))
            dbpool.initPool(**dbconfig)

        if hasmem and memconfig:
            urls = memconfig.get('urls')
            hostname = str(memconfig.get('hostname'))
            mclient.connect(urls, hostname)

        if logpath:
            log.addObserver(loogoo(logpath))  #日志处理
        log.startLogging(sys.stdout)

        if cpuid:
            affinity.set_process_affinity_mask(os.getpid(), cpuid)
        GlobalObject().config(netfactory=self.netfactory,
                              root=self.root,
                              remote=self.remote)
        if app:
            __import__(app)
        if mreload:
            _path_list = mreload.split(".")
            GlobalObject().reloadmodule = __import__(mreload,
                                                     fromlist=_path_list[:1])
        GlobalObject().remote_connect = self.remote_connect
        import admin
Пример #4
0
    def set_config(self):
        """
        初始化节点服务配置
        :return:
        """
        config = Config().config
        ser_cfg = config.get("servers", {}).get(self.servername)
        if not ser_cfg:
            raise ValueError
        mem_cfg = config.get("cache")
        master_cfg = config.get("master")
        db_cfg = config.get("db")

        GlobalObject().json_config = ser_cfg
        netport = ser_cfg.get('netport')  # 客户端连接
        webport = ser_cfg.get('webport')  # http连接
        rootport = ser_cfg.get('rootport')  # root节点配置
        wsport = ser_cfg.get("wsport")  # WebSocket端口
        self.remoteportlist = ser_cfg.get('remoteport', [])  # remote节点配置列表
        logpath = ser_cfg.get('log')  # 日志
        hasdb = ser_cfg.get('db')  # 数据库连接
        hasmem = ser_cfg.get('mem')  # memcached连接
        app = ser_cfg.get('app')  # 入口模块名称
        cpuid = ser_cfg.get('cpu')  # 绑定cpu
        mreload = ser_cfg.get('reload')  # 重新加载模块名称

        if master_cfg:
            masterport = master_cfg.get('rootport')
            masterhost = master_cfg.get('roothost')
            self.master_remote = RemoteObject(self.servername)
            addr = ('localhost',
                    masterport) if not masterhost else (masterhost, masterport)
            self.master_remote.connect(addr)
            GlobalObject().masterremote = self.master_remote

        if netport:
            self.netfactory = LiberateFactory()
            netservice = services.CommandService("netservice")
            self.netfactory.addServiceChannel(netservice)
            reactor.listenTCP(netport, self.netfactory)

        if webport:
            self.webroot = vhost.NameVirtualHost()
            GlobalObject().webroot = self.webroot
            reactor.listenTCP(webport, DelaySite(self.webroot))

        if rootport:
            self.root = PBRoot()
            rootservice = services.Service("rootservice")
            self.root.addServiceChannel(rootservice)
            reactor.listenTCP(rootport, BilateralFactory(self.root))

        if wsport:
            self.ws = WsFactory(wsport)
            wsservice = services.CommandService("wsservice")
            self.ws.addServiceChannel(wsservice)
            reactor.listenTCP(wsport, self.ws)

        for cnf in self.remoteportlist:
            rname = cnf.get('rootname')
            self.remote[rname] = RemoteObject(self.servername)

        if hasdb and db_cfg:
            log.msg(str(db_cfg))
            dbpool.initPool(**db_cfg)

        if hasmem and mem_cfg:
            urls = mem_cfg.get('urls')
            hostname = str(mem_cfg.get('hostname'))
            mclient.connect(urls, hostname)

        if logpath:
            log.addObserver(loogoo(logpath))  #日志处理
        log.startLogging(sys.stdout)

        if cpuid:
            affinity.set_process_affinity_mask(os.getpid(), cpuid)

        GlobalObject().config(netfactory=self.netfactory,
                              root=self.root,
                              remote=self.remote)
        GlobalObject().server = self

        if app:
            __import__(app)
        if mreload:
            _path_list = mreload.split(".")
            GlobalObject().reloadmodule = __import__(mreload,
                                                     fromlist=_path_list[:1])
        GlobalObject().remote_connect = self.remote_connect
        import admin
Пример #5
0
    def config(self, config, servername=None, dbconfig=None, memconfig=None, masterconf=None):
        """配置服务器
        """
        GlobalObject().json_config = config
        netport = config.get("netport")  # 客户端连接
        webport = config.get("webport")  # http连接
        rootport = config.get("rootport")  # root节点配置
        self.remoteportlist = config.get("remoteport", [])  # remote节点配置列表
        if not servername:
            servername = config.get("name")  # 服务器名称
        logpath = config.get("log")  # 日志
        hasdb = config.get("db")  # 数据库连接
        hasmem = config.get("mem")  # memcached连接
        app = config.get("app")  # 入口模块名称
        cpuid = config.get("cpu")  # 绑定cpu
        mreload = config.get("reload")  # 重新加载模块名称
        self.servername = servername
        if masterconf:
            masterport = masterconf.get("rootport")
            masterhost = masterconf.get("roothost")
            self.master_remote = RemoteObject(servername, "master")
            addr = ("localhost", masterport) if not masterhost else (masterhost, masterport)
            self.master_remote.connect(addr)
            GlobalObject().masterremote = self.master_remote

        if netport:
            self.netfactory = LiberateFactory()
            netservice = services.CommandService("netservice")
            self.netfactory.addServiceChannel(netservice)
            reactor.listenTCP(netport, self.netfactory)

        if webport:
            self.webroot = vhost.NameVirtualHost()
            GlobalObject().webroot = self.webroot
            reactor.listenTCP(webport, DelaySite(self.webroot))

        if rootport:
            self.root = PBRoot()
            rootservice = services.Service("rootservice")
            self.root.addServiceChannel(rootservice)
            reactor.listenTCP(rootport, BilateralFactory(self.root))

        for cnf in self.remoteportlist:
            rname = cnf.get("rootname")
            self.remote[rname] = RemoteObject(self.servername, rname)

        if hasdb and dbconfig:
            log.msg(str(dbconfig))
            dbpool.initPool(**dbconfig)

        if logpath:
            log.addObserver(loogoo(logpath))  # 日志处理
        log.startLogging(sys.stdout)
        GlobalObject().config(netfactory=self.netfactory, root=self.root, remote=self.remote)
        if app:
            __import__(app)
        if mreload:
            _path_list = mreload.split(".")
            GlobalObject().reloadmodule = __import__(mreload, fromlist=_path_list[:1])
        GlobalObject().remote_connect = self.remote_connect
        from . import admin
Пример #6
0
    #    CREATE TABLE `tb_register` (
    #   `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'id',
    #   `username` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '' COMMENT '用户名',
    #   `password` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '' COMMENT '用户密码',
    #   PRIMARY KEY (`id`,`username`)
    #   ) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8
    #
    hostname = "localhost"
    username = '******'
    password = '******'
    dbname = 'test'
    charset = 'utf8'
    tablename = "test1"  #
    aa = {
        'host': "localhost",
        'user': '******',
        'passwd': '111',
        'db': 'test',
        'port': 3306,
        'charset': 'utf8'
    }
    dbpool.initPool(**aa)
    mclient.connect(['127.0.0.1:11211'], "test")

    mmanager = MAdminManager()
    m1 = mmode.MAdmin('test1', 'id', incrkey='id')
    m1.insert()
    print m1.get('_incrvalue')
    m2 = mmode.MAdmin('test1', 'id', incrkey='id')
    print m2.get('_incrvalue')
Пример #7
0
    #    CREATE TABLE `tb_register` (
    #   `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'id',
    #   `username` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '' COMMENT '用户名',
    #   `password` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '' COMMENT '用户密码',
    #   PRIMARY KEY (`id`,`username`)
    #   ) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8
    #
    hostname = "localhost"
    username = '******'
    password = '******'
    dbname = 'test'
    charset = 'utf8'
    tablename = "test1"  #
    aa = {
        'host': "localhost",
        'user': '******',
        'passwd': '111',
        'db': 'test',
        'port': 3306,
        'charset': 'utf8'
    }
    dbpool.initPool(**aa)  # 字典
    mclient.connect(['127.0.0.1:11211'], "test")  # memcached

    mmanager = MAdminManager()
    m1 = mmode.MAdmin('test1', 'id', incrkey='id')
    m1.insert()
    print m1.get('_incrvalue')
    m2 = mmode.MAdmin('test1', 'id', incrkey='id')
    print m2.get('_incrvalue')
Пример #8
0
    
#    CREATE TABLE `tb_register` (
#   `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'id',
#   `username` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '' COMMENT '用户名',
#   `password` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '' COMMENT '用户密码',
#   PRIMARY KEY (`id`,`username`)
#   ) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8
#
    hostname = "localhost"
    username = '******'
    password = '******'
    dbname = 'test'
    charset = 'utf8'
    tablename = "test1"#
    aa = {'host':"localhost",
    'user':'******',
    'passwd':'111',
    'db':'test',
    'port':3306,
    'charset':'utf8'}
    dbpool.initPool(**aa)
    mclient.connect(['127.0.0.1:11211'], "test")

    mmanager = MAdminManager()
    m1 = mmode.MAdmin( 'test1', 'id', incrkey='id')
    m1.insert()
    print m1.get('_incrvalue')
    m2 = mmode.MAdmin( 'test1', 'id', incrkey='id')
    print m2.get('_incrvalue')