Esempio n. 1
0
    def setUp(self):
        print 'init logging'
        nowPath = re.findall('(.*?)IMAgent\\\\test', os.getcwd())[0]
        self.configPath = nowPath + 'IMAgent\\test\\conf\\'
        AgentLog.init(self.configPath + 'logging.cnf')

        #正确配置
        AgentConfig.database = AgentConfig.database = {
            'name': 'Mysql',
            'attr': {
                'user': '',
                'passwd': '',
                'home': '',
                'configFile': 'test.cnf',
                'backupDir': ''
            }
        }
Esempio n. 2
0
def main():
    agentManager = None
    try:

        # 解析命令行,获取配置文件地址和是否console执行
        optParser = AgentOptionParser()
        cfgFile = Util.getRealPath(optParser.configFile)
        console = optParser.console

        # 获取配置文件配置
        userConfig, sysConfig = AgentConfigManager.initAllConfig(cfgFile)

        # 如果为console状态,则直接运行,如果为非console状态,则在后台以daemon形式运行
        if not console:
            Daemon()
        else:
            userConfig.log['logSection'] = "debug"

        # 初始化日志句柄,所有相关日志的操作都需要放该操作后面
        AgentLog.init(userConfig.log['logConfig'],
                      userConfig.log['logSection'])

        agentManager = AgentManager(userConfig, sysConfig)

        agentManager.start()

        while True:
            Util.sleep(5)

        agentManager.stop()

    except KeyboardInterrupt:
        if agentManager is not None:
            agentManager.stop()
    finally:
        if agentManager is not None:
            agentManager.stop()