Esempio n. 1
0
File: center.py Progetto: mnms/share
 def _start_redis_process(self, ip, port, m_or_s):
     logger.info('[%s] Start redis (%s:%d)' % (m_or_s, ip, port))
     client = get_ssh(ip)
     redis_server = path_join(config.get_tsr2_home(), 'bin', 'redis-server')
     conf = path_join(config.get_tsr2_home(), 'conf', 'redis',
                      'redis-{port}.conf'.format(port=port))
     log_file = self.__get_redis_log_path_file(port)
     env = make_export_envs(ip, port)
     command = '''{env} ; {redis_server} {conf} >> {log_file} &'''.format(
         env=env, redis_server=redis_server, conf=conf, log_file=log_file)
     exit_status, stdout_msg, stderr_msg = ssh_execute(client=client,
                                                       command=command)
Esempio n. 2
0
    def command_raw(sub_cmd, ip_list, port_list):
        """Send redis-cli command raw

        :param sub_cmd: sub command
        :param ip_list: ip list
        :param port_list: port list
        :return: output string
        """
        logger.debug('command_raw')
        targets = utils.get_ip_port_tuple_list(ip_list, port_list)
        count = len(targets)
        index = random.randrange(0, count)
        target = targets[index]
        ip, port = target
        # logger.info('redis-cli connect to %s:%s' % (ip, port))
        outs = ''
        redis_cli = path_join(config.get_tsr2_home(), 'bin', 'redis-cli')
        env = utils.make_export_envs(ip, port)
        command = '{env}; {redis_cli} -h {ip} -p {port} {sub_cmd}'.format(
            env=env,
            redis_cli=redis_cli,
            ip=ip,
            port=port,
            sub_cmd=sub_cmd)
        try:
            stdout = subprocess.check_output(command, shell=True)
            outs += stdout
        except subprocess.CalledProcessError as ex:
            logger.debug('exception: %s' % str(ex))
        logger.debug('subprocess: %s' % command)
        return outs
Esempio n. 3
0
    def command_raw_all(sub_cmd, ip_list, port_list):
        """Send redis-cli command raw to all

        :param sub_cmd: sub command
        :param ip_list: ip list
        :param port_list: port list
        :return: (output string, meta)
        """
        logger.debug('command_raw_all')
        targets = utils.get_ip_port_tuple_list(ip_list, port_list)
        outs = ''
        stdout = ''
        meta = [['addr', 'stdout']]
        for ip, port in targets:
            env = utils.make_export_envs(ip, port)
            redis_cli = path_join(config.get_tsr2_home(), 'bin', 'redis-cli')
            command = '{env}; {redis_cli} -c -h {ip} -p {port} {sub_cmd}'.format(
                redis_cli=redis_cli,
                ip=ip,
                port=port,
                env=env,
                sub_cmd=sub_cmd)
            logger.debug('subprocess: %s' % command)
            try:
                stdout = subprocess.check_output(command, shell=True)
                outs += stdout
                meta.append(['%s:%s' % (ip, port), stdout])
            except subprocess.CalledProcessError as ex:
                logger.debug('exception: %s' % str(ex))
        return outs, meta
Esempio n. 4
0
File: center.py Progetto: mnms/share
 def __get_redis_log_path_file(port):
     dt = datetime.datetime.now()
     date = dt.strftime("%Y%m%d-%H%M%S")
     log_file = path_join(
         config.get_tsr2_home(), 'logs', 'redis',
         'servers-{date}-{port}.log'.format(date=date, port=port))
     return log_file
Esempio n. 5
0
 def overwrite_conf(report):
     logger.debug('_overwrite_conf')
     fb_config = config.get_config()
     nodes = fb_config['nodes']
     cluster_home = config.get_repo_cluster_path()
     tsr2_home = config.get_tsr2_home()
     src = path_join(cluster_home, 'tsr2-conf')
     dest = path_join(tsr2_home, 'conf')
     command = '''cp -a {src}/* {dest}'''.format(src=src, dest=dest)
     for node in nodes:
         client = get_ssh(node)
         ssh_execute(client=client, command=command)
         logger.debug('overwrite_conf success [{node}]'.format(node=node))
     if report:
         report.success()
Esempio n. 6
0
 def start(self):
     """Start thriftserver
     """
     ip, port, cluster_id = self._get_thriftserver_info()
     logger.debug('Start thriftserver (%s:%d)' % (ip, port))
     client = get_ssh(ip)
     if not client:
         logger.info('! ssh connection fail: %s' % ip)
         return
     exec_file = path_join(config.get_tsr2_home(cluster_id), 'sbin',
                           'thriftserver')
     env = ''  # TODO: import env
     command = '''{env} ; {exec_file} start &'''.format(env=env,
                                                        exec_file=exec_file)
     logger.info(command)
     ssh_execute(client=client, command=command)
Esempio n. 7
0
File: center.py Progetto: mnms/share
 def backup_server_logs(self):
     """Backup server logs"""
     logger.debug('backup_server_logs')
     self._update_ip_port()
     for ip in self.ip_list:
         backup_path = self.__get_redis_log_backup_path()
         client = get_ssh(ip)
         ssh_execute(client=client, command='mkdir -p %s' % backup_path)
         for port in (self.master_port_list + self.slave_port_list):
             redis_log_path = path_join(config.get_tsr2_home(), 'logs',
                                        'redis')
             command = '''mv {redis_log_path}/*{port}.log {backup_path} &> /dev/null'''.format(
                 redis_log_path=redis_log_path,
                 port=port,
                 backup_path=backup_path)
             ssh_execute(client=client,
                         command=command,
                         allow_status=[0, 1])
Esempio n. 8
0
File: center.py Progetto: mnms/share
 def __get_redis_log_backup_path():
     log_file = path_join(config.get_tsr2_home(), 'logs', 'redis', 'backup')
     return log_file