Example #1
0
def stop():
    """停止
    """
    return_value=normal_code
    dch_stop_command=f"cd {dch_dir} && bin/dch-cli -a {dch_password} shutdown"
    log.logger.debug(f"dch停止: {dch_stop_command=}")
    result, msg=common.exec_command(dch_stop_command)
    if result:
        log.logger.debug(f"检测端口: {dch_port}")
        if not common.port_exist([dch_port], exist_or_not=False):
            return_value=error_code
    else:
        log.logger.error(msg)
        return_value=error_code

    if sentinel_flag:
        if sentinel_password_str == "":
            sentinel_stop_command=f"cd {dch_dir} && bin/dch-cli -p {sentinel_port} shutdown"
        else:
            sentinel_stop_command=f"cd {dch_dir} && bin/dch-cli -a {sentinel_password} -p {sentinel_port} shutdown"
        log.logger.debug(f"sentinel停止: {sentinel_stop_command=}")
        result, msg=common.exec_command(sentinel_stop_command)
        if result:
            log.logger.debug(f"检测端口: {sentinel_port}")
            if not common.port_exist([sentinel_port], exist_or_not=False):
                return_value=error_code
        else:
            log.logger.error(msg)
            return_value=error_code
    return return_value
Example #2
0
def run():
    """运行
    """
    return_value = normal_code
    # exec使用get_pty, redis配置为后台运行, 但未启动完全时, 断开依然会停止, 故使用sleep 2让其完全启动
    redis_start_command = f"cd {redis_dir} && bin/redis-server conf/redis.conf"
    log.logger.debug(f"redis启动: {redis_start_command=}")
    result, msg = common.exec_command(redis_start_command)
    if result:
        log.logger.debug(f"检测端口: {redis_port} ")
        if not common.port_exist([redis_port]):
            return_value = error_code
    else:
        log.logger.error(msg)
        return_value = error_code

    if sentinel_flag:
        #sentinel_port=sentinel_info.get("sentinel_port")
        sentinel_start_command = f"cd {redis_dir} && bin/redis-sentinel conf/sentinel.conf"
        log.logger.debug(f"sentinel启动: {sentinel_start_command=}")
        result, msg = common.exec_command(sentinel_start_command)
        if result:
            log.logger.debug(f"检测端口: {sentinel_port} ")
            if not common.port_exist([sentinel_port]):
                return_value = error_code
        else:
            log.logger.error(msg)
            return_value = error_code
    return return_value
Example #3
0
def stop():
    """停止
    """
    return_value = normal_code
    redis_stop_command = f"cd {redis_dir} && bin/redis-cli -a {password} shutdown"
    log.logger.debug(f"redis停止: {redis_stop_command=}")
    result, msg = common.exec_command(redis_stop_command)
    if result:
        log.logger.debug(f"检测端口: {redis_port} ")
        if not common.port_exist([redis_port], exist_or_not=False):
            return_value = error_code
    else:
        log.logger.error(msg)
        return_value = error_code

    if sentinel_flag:
        sentinel_stop_command = f"cd {redis_dir} && bin/redis-cli -a {password} -p {sentinel_port} shutdown"
        log.logger.debug(f"sentinel停止: {sentinel_stop_command=}")
        result, msg = common.exec_command(sentinel_stop_command)
        if result:
            log.logger.debug(f"检测端口: {sentinel_port} ")
            if not common.port_exist([sentinel_port], exist_or_not=False):
                return_value = error_code
        else:
            log.logger.error(msg)
            return_value = error_code
    return return_value
Example #4
0
def run():
    """运行
    """
    return_value = normal_code
    redis_start_command = f"cd {redis_dir} && bin/redis-server conf/redis.conf"
    log.logger.debug(f"redis启动: {redis_start_command=}")
    result, msg = common.exec_command(redis_start_command)
    if result:
        log.logger.debug(f"检测端口: {redis_port} ")
        if not common.port_exist([redis_port]):
            return_value = error_code
    else:
        log.logger.error(msg)
        return_value = error_code

    if sentinel_flag:
        sentinel_start_command = f"cd {redis_dir} && bin/redis-sentinel conf/sentinel.conf"
        log.logger.debug(f"sentinel启动: {sentinel_start_command=}")
        result, msg = common.exec_command(sentinel_start_command)
        if result:
            log.logger.debug(f"检测端口: {sentinel_port} ")
            if not common.port_exist([sentinel_port]):
                return_value = error_code
        else:
            log.logger.error(msg)
            return_value = error_code
    return return_value
Example #5
0
def stop():
    """停止
    """
    return_value = normal_code
    namesrv_command = f"bash -lc 'cd {rocketmq_dir} && bash bin/mqshutdown namesrv'"
    broker_command = f"bash -lc 'cd {rocketmq_dir} && bash bin/mqshutdown broker'"

    log.logger.debug(f"{namesrv_command=}")
    result, msg = common.exec_command(namesrv_command)
    if result:
        log.logger.debug(f"检测端口: {namesrv_port_list=}")
        if not common.port_exist(namesrv_port_list, exist_or_not=False):
            return_value = error_code
        else:
            log.logger.debug(f"{broker_command=}")
            result, msg = common.exec_command(broker_command)
            if result:
                log.logger.debug(f"检测端口: {broker_port_list=}")
                if not common.port_exist(broker_port_list, exist_or_not=False):
                    return_value = error_code
            else:
                log.logger.error(msg)
                return_value = error_code
    else:
        log.logger.error(msg)
        return_value = error_code
    return return_value
Example #6
0
def run():
    """运行
    """
    return_value = normal_code
    namesrv_command = f"bash -lc 'cd {rocketmq_dir} && bash ./bin/start.sh namesrv'"
    broker_command = f"bash -lc 'cd {rocketmq_dir} && bash ./bin/start.sh broker'"

    log.logger.debug(f"{namesrv_command=}")
    result, msg = common.exec_command(namesrv_command)
    if result:
        log.logger.debug(f"检测端口: {namesrv_port_list=}")
        if not common.port_exist(namesrv_port_list):
            return_value = error_code
        else:
            log.logger.debug(f"{broker_command=}")
            result, msg = common.exec_command(broker_command)
            if result:
                log.logger.debug(f"检测端口: {broker_port_list=}")
                if not common.port_exist(broker_port_list):
                    return_value = error_code
            else:
                log.logger.error(msg)
                return_value = error_code
    else:
        log.logger.error(msg)
        return_value = error_code
    return return_value
Example #7
0
def stop():
    """关闭
    """
    if server_flag == 1:
        command = f"echo y | gluster volume stop {glusterfs_volume_name} force"
        log.logger.debug(f"关闭volume: {command=}")
        result, msg = common.exec_command(command)
        if result:
            log.logger.debug(f"检测端口: {volume_port}")
            if not common.port_exist([volume_port], exist_or_not=False):
                return error_code
            #else:
            #    command="systemctl stop glusterd"
            #    log.logger.debug(f"关闭glusterd: {command=}")
            #    result, msg=common.exec_command(command)
            #    if result:
            #        log.logger.debug(f"检测端口: {glusterd_port}")
            #        if not common.port_exist([glusterd_port], exist_or_not=False):
            #            return error_code
            #    else:
            #        return error_code
        else:
            return error_code
    elif server_flag == 2:
        command = f"umount {mounted_dir}"
        log.logger.debug(f"执行卸载: {command}")
        result, msg = common.exec_command(command)
        if not result:
            log.logger.error(msg)
            return error_code
    return normal_code
Example #8
0
def db_update(args_dict, log):
    """用于数据库更新
    args_dict={
        "host": "node1", 
        "password": "******", 
        "type": "mysql", 
        "db": "str", 
        ...
        "pkg_file": "str", 
        "delete_flag": True|False,          # 是否删除原项目
    }
    """

    log.logger.info("开始数据更新, 请稍后...")
    db_type = args_dict["type"]
    pkg_file = args_dict.get("pkg_file")
    try:
        log.logger.debug(f"解压'{pkg_file}'至'{update_package_dir}'")
        with tarfile.open(pkg_file, "r", encoding="utf8") as tar:
            for i in tar.getmembers():
                db_file_name = i.name
                break
            tar.extractall(update_package_dir)
        db_file = f"{update_package_dir}/{db_file_name}"
        if db_type == "mysql":
            password = args_dict["password"]
            db_name = args_dict["db"]
            if args_dict["delete_flag"]:
                drop_db_command = "mysqladmin -uroot -p{password} -f drop {db_name}"
                log.logger.debug(f"{drop_db_command=}")
                result, msg = common.exec_command(drop_db_command,
                                                  timeout=3600)
                if not result:
                    self.log.logger.error(msg)
                    return error_code
            source_db_command = f"mysql -uroot -p{password} {db_name} < {db_file}"
            log.logger.debug(f"{source_db_command=}")
            result, msg = common.exec_command(source_db_command, timeout=3600)
            if result:
                return normal_code
            else:
                log.logger.error(msg)
                return error_code
        else:
            log.logger.error(f"{db_type}类型不支持")
            return error_code

        if os.path.exists(db_file):
            log.logger.info("清理更新包...")
            os.remove(db_file)
    except Exception as e:
        log.logger.error(f"更新失败: {str(e)}")
        return error_code
Example #9
0
def init(db_info_dict, mysql_dir, init_password, cluster_info_dict, role, log):
    root_password = db_info_dict.get("root_password")
    change_pass_command = f"{mysql_dir}/bin/mysqladmin  -uroot -p'{init_password}' password {root_password}"
    log.logger.debug(f"更改root密码: {change_pass_command=}")
    result, msg = common.exec_command(change_pass_command)
    if result:
        business_db_list = db_info_dict.get("business_db")
        if business_db_list is not None and len(business_db_list) != 0:
            log.logger.debug("创建账号及数据库")
            init_sql_list = []
            for db_name, user_name, user_password in zip(
                    db_info_dict.get("business_db"),
                    db_info_dict.get("business_user"),
                    db_info_dict.get("business_password")):
                db_sql = f"create database if not exists {db_name};"
                use_sql = f"use {db_name};"
                user_sql = f"create user if not exists '{user_name}'@'%' identified by '{user_password}';"
                grant_sql = f"grant all on {db_name}.* to '{user_name}'@'%';"
                init_sql_list.append(db_sql)
                init_sql_list.append(use_sql)
                init_sql_list.append(user_sql)
                init_sql_list.append(grant_sql)
            init_sql = " ".join(init_sql_list)
            init_commands = f'export MYSQL_PWD="{root_password}" ; echo "{init_sql}" | {mysql_dir}/bin/mysql -uroot'
            log.logger.debug(f"{init_commands=}")
            result, msg = common.exec_command(init_commands)
            if not result:
                log.logger.error(msg)
                return error_code
        if role != "stand-alone":
            log.logger.debug("开始主从配置")
            if role == "master":
                sync_sql = f"create user 'repl'@'%' identified with mysql_native_password by 'DreamSoft_123456'; grant replication slave on *.* to 'repl'@'%';"
            elif role == "slave":
                sync_host, sync_port = cluster_info_dict.get(
                    "sync_host").split(":")
                sync_sql = f"change master to master_host='{sync_host}', master_port={sync_port}, master_user='******', master_password='******', master_auto_position=1; start slave;"
            cluster_commands = f'export MYSQL_PWD="{root_password}" ; echo "{sync_sql}" | {mysql_dir}/bin/mysql -uroot'
            log.logger.debug(f"{cluster_commands=}")
            result, msg = common.exec_command(cluster_commands)
            if result:
                return normal_code
            else:
                log.logger.error(msg)
                return error_code
    else:
        log.logger.error(msg)
        return error_code
Example #10
0
def db_backup(args_dict, log):
    """数据库备份
    """
    db_type = args_dict["type"]
    backup_name = args_dict["backup_name"]
    if db_type.lower() == "mysql":
        root_password = args_dict["password"]
        db_name = args_dict["db"]
        db_file = f"{rollback_dir}/{db_name}"
        command = f"mysqldump -uroot -p'{root_password}' --set-gtid-purged=off {db_name} > {db_file}"
        log.logger.debug(f"{command=}")
        result, msg = common.exec_command(command, timeout=3600)
        if result:
            db_file_size = os.path.getsize(db_file)
            if db_file_size < 1024 * 1024 * 10:
                self.log.logger.warning(
                    f"导出文件过小, {db_file}: {common.format_size(db_file_size)}")
                return error_code
            db_gz_file = f"{rollback_dir}/{backup_name}"
            try:
                with tarfile.open(db_gz_file, "w:gz", encoding="utf8") as tar:
                    tar.add(db_file)
            except Exception as e:
                log.logger.error(str(e))
                return error_code
        else:
            log.logger.error(msg)
            return error_code
    else:
        pass
    return normal_code
Example #11
0
def test():
    """测试
    """
    return_value = normal_code
    result_value = "0"
    if softname == "dameng":
        sql_text = """\
        set HEA off;
        set LINESHOW off;
        set TIMING off;
        select 0;
        exit;
        """
        config_dict = {
            "test_config": {
                "config_file": sql_file,
                "config_context": sql_text,
                "mode": "w"
            }
        }
        result, msg = common.config(config_dict)
        if result:
            test_command = f"su -l {system_user} -c 'disql -S -L {dba_user}/{dba_password} \`{sql_file}'"
        else:
            log.logger.error(msg)
            return error_code
    log.logger.debug(f"test db comand: {test_command}")
    result, msg = common.exec_command(test_command)
    if result and msg.strip() == result_value:
        return normal_code
    else:
        log.logger.error(msg)
        return_value = error_code
    return return_value
Example #12
0
File: sql.py Project: xhsky/autodep
def backup():
    """备份
    """
    backup_version=conf_dict["backup_version"]
    if db_type.lower()=="mysql":
        db_name=sql_info_dict["db_name"]
        db_abs_file=f"{sql_dir}/{db_name}.sql"
        root_password=sql_info_dict["root_password"]
        db_port=sql_info_dict["db_port"]
        dump_db_command=f"mysqldump -uroot -p{root_password} -P {db_port} --set-gtid-purged=OFF {db_name} > {db_abs_file}"
        log.logger.debug(f"{dump_db_command=}")
        log.logger.info(f"{softname}: 数据备份中, 请稍后...")
        result, msg=common.exec_command(dump_db_command, timeout=3600)

    if result:
        log.logger.debug(f"{softname}: 数据压缩, 请稍后...")
        result, msg=common.tar_backup(backup_version, backup_dir, softname, sql_dir, [])
        if os.path.exists(db_abs_file):
            log.logger.info("清理数据包...")
            os.remove(db_abs_file)
        if result:
            return normal_code
        else:
            log.logger.error(msg)
            return error_code
    else:
        log.logger.error(msg)
        return error_code
Example #13
0
File: sql.py Project: xhsky/autodep
def run():
    """运行
    """
    db_file=os.listdir(sql_dir)[0]
    db_abs_file=os.path.abspath(f"{sql_dir}/{db_file}")
    if db_type=="mysql":
        db_name=sql_info_dict["db_name"]
        root_password=sql_info_dict["root_password"]
        db_port=sql_info_dict["db_port"]
        source_db_command=f"mysql -uroot -p{root_password} -P {db_port} {db_name} < {db_abs_file}"
        log.logger.debug(f"{source_db_command=}")
        log.logger.info(f"{softname}: 数据导入中, 请稍后...")
        result, msg=common.exec_command(source_db_command, timeout=3600)
        if result:
            if os.path.exists(db_abs_file):
                log.logger.info("清理数据包...")
                os.remove(db_abs_file)
            return normal_code
        else:
            log.logger.error(msg)
            return error_code
    elif db_type=="dameng":
        from_user=sql_info_dict["from_user"].lower()
        to_user=sql_info_dict["to_user"].lower()

        system_user=conf_dict[f"{db_type}_info"]["system_user"]
        dba_user=conf_dict[f"{db_type}_info"]["dba_user"]
        dba_password=conf_dict[f"{db_type}_info"]["dba_password"]
        db_port=conf_dict[f"{db_type}_info"]["db_port"]

        source_db_command=f"chown -R {system_user} {sql_dir} && su -l {system_user} -c 'dimp userid={dba_user}/{dba_password}:{db_port} file={db_abs_file} log=/tmp/{db_type}_{to_user}.log owner={from_user} dummy=Y LOG_WRITE=Y TABLE_EXISTS_ACTION=REPLACE"
        if from_user!=to_user:
            source_db_command=f"{source_db_command} remap_schema={from_user.upper()}:{to_user.upper()}'"
        else:
            source_db_command=f"{source_db_command}'"
        log.logger.debug(f"{source_db_command=}")
        log.logger.info(f"{softname}: 数据导入中, 请稍后...")
        result, msg=common.exec_command(source_db_command, timeout=3600)
        if result:
            if os.path.exists(db_abs_file):
                log.logger.info("清理数据包...")
                os.remove(db_abs_file)
            return normal_code
        else:
            log.logger.error(msg)
            return error_code
Example #14
0
def main():
    """设置主机名, 填写hosts
    """
    log = Logger({"remote": log_remote_level}, logger_name="set_hosts")
    softname, action, conf_json = sys.argv[1:]
    conf_dict = json.loads(conf_json)
    hosts_info_dict = conf_dict["hosts_info"]
    located = conf_dict["located"]
    return_value = normal_code

    try:
        hostname = hosts_info_dict["hostname"]
        hosts_list = hosts_info_dict["hosts"]

        # 设置主机名
        log.logger.info(f"设置主机名为{hostname}")
        hostname_cmd = f"hostnamectl set-hostname {hostname}"
        log.logger.debug(f"{hostname_cmd=}")
        result, msg = exec_command(hostname_cmd)
        if not result:
            log.logger.error(f"设置主机名失败: {msg}")
            return_value = error_code

        # 配置hosts
        hosts_file = "/etc/hosts"

        config_dict = {
            "hosts": {
                "config_file": hosts_file,
                "config_context": "\n".join(hosts_list),
                "mode": "r+"
            }
        }
        result, msg = config(config_dict)
        if result:
            log.logger.info(f"hosts配置完成")
        else:
            log.logger.error(msg)
            return_value = error_code

        # 建立安装目录
        log.logger.info(f"建立安装目录: {located}")
        os.makedirs(located, exist_ok=1)
        if located != located_dir_link:
            if os.path.exists(located_dir_link):
                if os.path.islink(located_dir_link):
                    if os.readlink(located_dir_link) != located:
                        os.remove(located_dir_link)
                        os.symlink(located, located_dir_link)
                else:
                    log.logger.error(f"{located_dir_link}目录存在, 无法安装, 请移除该目录!")
                    return_value = error_code
            else:
                os.symlink(located, located_dir_link)
    except Exception as e:
        log.logger.error(f"{str(e)}")
        return_value = error_code
    sys.exit(return_value)
Example #15
0
def sendmail():
    """发送巡检信息
    """
    command = f"cd {autocheck_dir} ; {remote_python_exec} ./main.py sendmail"
    log.logger.debug(f"{command=}")
    result, msg = common.exec_command(command)
    if not result:
        log.logger.error(msg)
        return error_code
    return normal_code
Example #16
0
def run():
    if server_flag == 1:  # server
        volume_dir = f"{located}/brick"
        members = glusterfs_info_dict.get("members")
        try:
            log.logger.debug(f"建立volume目录: {volume_dir}")
            os.makedirs(volume_dir, exist_ok=1)

            # 配置集群
            create_volume_command = ""
            for node in members:
                create_volume_command = f"{create_volume_command} {node}:{volume_dir}"
                add_peer_command = f"gluster peer probe {node}"
                log.logger.debug(f"添加节点: {add_peer_command=}")
                result, msg = common.exec_command(add_peer_command)
                if not result:
                    log.logger.error(msg)
                    return error_code
                else:
                    time.sleep(1)  # 迅速添加后会导致创建volume失败...

            # 判读volume是否存在 以决定其它gluster是否去创建volume
            volume_exist_command = f"gluster volume info {glusterfs_volume_name} > /dev/null 2>&1"
            log.logger.debug(f"查看volume是否存在: {volume_exist_command=}")
            result, msg = common.exec_command(volume_exist_command)
            if result:
                log.logger.debug(f"volume({glusterfs_volume_name})已存在")
            else:
                N = len(members)
                create_volume_command = f"gluster volume create {glusterfs_volume_name} replica {N} {create_volume_command} force"
                log.logger.debug(f"创建volume: {create_volume_command=}")
                result, msg = common.exec_command(create_volume_command)
                if result:
                    return volume_start()
                else:
                    log.logger.error(msg)
                    return error_code
        except Exception as e:
            log.logger.error(str(e))
            return error_code
    elif server_flag == 2:  # client
        return start()
    return normal_code
Example #17
0
def run():
    """运行
    将备份任务写入crontab
    """
    crontab_command = f"bash -lc 'crontab {backup_crontab_file}'"
    log.logger.debug(f"{crontab_command=}")
    result, msg = common.exec_command(crontab_command, timeout=5)
    if not result:
        log.logger.error(msg)
        return error_code
    return normal_code
Example #18
0
def run():
    """运行
    """
    command = f"cd {autocheck_dir} ; {remote_python_exec} ./main.py start"
    log.logger.debug(f"{command=}")
    result, msg = common.exec_command(command)
    if result:
        if not os.path.exists(f"{autocheck_dir}/logs/autocheck.pid"):
            return error_code
    else:
        log.logger.error(msg)
        return error_code
    return normal_code
Example #19
0
def start():
    """启动
    """
    log.logger.debug(f"{start_command=}")
    result, msg = common.exec_command(start_command, timeout=600)
    if result:
        log.logger.debug(f"检测端口: {port_list=}")
        if not common.port_exist(port_list):
            return error_code
    else:
        log.logger.error(msg)
        return error_code
    return normal_code
Example #20
0
def stop():
    """停止
    """
    stop_command = f"systemctl stop mysqld"
    log.logger.debug(f"{stop_command=}")
    result, msg = common.exec_command(stop_command, timeout=600)
    if result:
        log.logger.debug(f"检测端口: {port_list=}")
        if not common.port_exist(port_list, exist_or_not=False):
            return error_code
    else:
        log.logger.error(msg)
        return error_code
    return normal_code
Example #21
0
def stop():
    """关闭
    """
    return_value = normal_code
    stop_command = f"bash -lc 'cd {nacos_dir} ; ./bin/shutdown.sh'"
    log.logger.debug(f"{stop_command=}")
    result, msg = common.exec_command(stop_command)
    if result:
        log.logger.debug(f"检测端口: {port_list=}")
        if not common.port_exist(port_list, exist_or_not=False):
            return_value = error_code
    else:
        log.logger.error(msg)
        return_value = error_code
    return return_value
Example #22
0
def run():
    """运行
    """
    return_value = normal_code
    start_command = f"cd {dps_dir} ; ./sbin/dps-server"
    log.logger.debug(f"{start_command=}")
    result, msg = common.exec_command(start_command)
    if result:
        log.logger.debug(f"检测端口: {port_list=}")
        if not common.port_exist(port_list):
            return_value = error_code
    else:
        log.logger.error(msg)
        return_value = error_code
    return return_value
Example #23
0
def volume_start():
    """volume启动
    """
    log.logger.debug(f"检测端口: {volume_port}")
    if not common.port_exist([volume_port], seconds=2):
        start_volume_command = f"gluster volume start {glusterfs_volume_name}"
        log.logger.debug(f"启动volume: {start_volume_command=}")
        result, msg = common.exec_command(start_volume_command)
        if result:
            log.logger.debug(f"检测端口: {volume_port}")
            if not common.port_exist([volume_port]):
                return error_code
        else:
            return error_code
    return normal_code
Example #24
0
def stop():
    """停止
    """
    return_value=normal_code
    stop_command=f"bash -lc 'cd {program_dir} ; bash {program_sh_file} stop'"
    log.logger.debug(f"{stop_command=}")
    result, msg=common.exec_command(stop_command)
    if result:
        log.logger.debug(f"检测端口: {port_list=}")
        if not common.port_exist(port_list, exist_or_not=False):
            return_value=error_code
    else:
        log.logger.error(msg)
        return_value=error_code
    return return_value
Example #25
0
def stop():
    """关闭
    """
    return_value = normal_code
    stop_command = f"cd {dps_dir} ; ./sbin/dps-server -s stop"
    log.logger.debug(f"{stop_command=}")
    result, msg = common.exec_command(stop_command)
    if result:
        log.logger.debug(f"检测端口: {port_list=}")
        if not common.port_exist(port_list, exist_or_not=False):
            return_value = error_code
    else:
        log.logger.error(msg)
        return_value = error_code
    return return_value
Example #26
0
def start():
    """启动
    """
    return_value=normal_code
    start_command=f"bash -lc 'cd {program_dir} ; bash {program_sh_file} start'" 
    log.logger.debug(f"{start_command=}")
    result, msg=common.exec_command(start_command)
    if result:
        log.logger.debug(f"检测端口: {port_list=}")
        if not common.port_exist(port_list, seconds=1200):
            return_value=error_code
    else:
        log.logger.error(msg)
        return_value=error_code
    return return_value
Example #27
0
def heapdump():
    """jvm
    """
    return_value=normal_code
    command=f"jmap -dump:format=b, file=heapdump.dump {pid}"
    log.logger.debug(f"{command=}")
    result, msg=common.exec_command(command)
    if result:
        log.logger.debug(f"检测端口: {port_list=}")
        if not common.port_exist(port_list, seconds=600):
            return_value=error_code
    else:
        log.logger.error(msg)
        return_value=error_code
    return return_value
Example #28
0
def stop():
    """停止
    """
    return_value = normal_code
    #command=f"su elastic --session-command 'cd {es_dir} && kill `cat elasticsearch.pid`'"
    command = f"su elastic -c 'cd {es_dir} && kill `cat elasticsearch.pid`'"
    log.logger.debug(f"{command=}")

    result, msg = common.exec_command(command)
    if result:
        log.logger.debug(f"检测端口: {port_list=}")
        if not common.port_exist(port_list, exist_or_not=False):
            return_value = error_code
    else:
        log.logger.error(msg)
        return_value = error_code
    return return_value
Example #29
0
def run():
    """运行
    """
    return_value = normal_code
    #command=f"su elastic --session-command 'cd {es_dir} && ./bin/elasticsearch -d -p elasticsearch.pid &> /dev/null'"
    command = f"su elastic -lc 'cd {es_dir} && ./bin/elasticsearch -d -p elasticsearch.pid &> /dev/null'"
    log.logger.debug(f"{command=}")

    result, msg = common.exec_command(command, timeout=80)
    if result:
        log.logger.debug(f"检测端口: {port_list=}")
        if not common.port_exist(port_list):
            return_value = error_code
    else:
        log.logger.error(msg)
        return_value = error_code
    return return_value
Example #30
0
def start():
    """启动
    """
    if server_flag == 1:
        result_code = glusterd_start()
        if result_code == normal_code:
            return volume_start()
        else:
            return result_code
    elif server_flag == 2:
        command = "mount -a"
        log.logger.debug(f"执行挂载: {command}")
        result, msg = common.exec_command(command)
        if not result:
            log.logger.error(msg)
            return error_code
    return normal_code