diff --git a/pkg/deploy/action/appctl.sh b/pkg/deploy/action/appctl.sh index cab027ebe5c214ff5b14f30c4142620b37a08ed4..1ed3bd0a4ecb39ffaeb1641b5ec9aa8373f5522f 100644 --- a/pkg/deploy/action/appctl.sh +++ b/pkg/deploy/action/appctl.sh @@ -174,6 +174,7 @@ function upgrade_lock() { exit 1 fi upgrade_lock_by_dbstor + touch "${upgrade_path}"/"${upgrade_flag}" && chmod 600 "${upgrade_path}"/"${upgrade_flag}" update_remote_status_file_path_by_dbstor "${upgrade_path}"/"${upgrade_flag}" } @@ -409,6 +410,7 @@ case "$ACTION" in CONFIG_PATH=$3 lock_file=${PRE_UPGRADE} FAIL_FLAG=/opt/cantian/pre_upgrade_${INSTALL_TYPE}.fail + chown -hR "${cantian_user}":"${cantian_group}" "${CURRENT_PATH}"/* clear_history_flag do_deploy ${PRE_UPGRADE} ${INSTALL_TYPE} ${CONFIG_PATH} if [ $? -ne 0 ]; then @@ -422,6 +424,11 @@ case "$ACTION" in if [[ "$(find ${SUCCESS_FLAG_PATH} -type f -name pre_upgrade_"${INSTALL_TYPE}".success)" ]]; then UPGRADE_IP_PORT=$3 lock_file=${UPGRADE_NAME} + deploy_mode=$(python3 ${CURRENT_PATH}/get_config_info.py "deploy") + chown -hR "${cantian_user}":"${cantian_group}" "${CURRENT_PATH}"/* + if [[ "${deploy_mode}" == "dss" ]]; then + sh /opt/cantian/action/dss/appctl.sh start + fi create_upgrade_flag upgrade_lock do_deploy ${UPGRADE_NAME} ${INSTALL_TYPE} ${UPGRADE_IP_PORT} @@ -439,6 +446,7 @@ case "$ACTION" in ;; upgrade_commit) upgrade_init_flag + chown -hR "${cantian_user}":"${cantian_group}" "${CURRENT_PATH}"/* upgrade_lock lock_file=${UPGRADE_COMMIT_NAME} do_deploy ${UPGRADE_COMMIT_NAME} ${INSTALL_TYPE} diff --git a/pkg/deploy/action/cantian/appctl.sh b/pkg/deploy/action/cantian/appctl.sh index 0f0d465710a7ee15bad4febe7c5a420f49b01445..b30d17731cd2f34389cd4f171ed711263516d772 100644 --- a/pkg/deploy/action/cantian/appctl.sh +++ b/pkg/deploy/action/cantian/appctl.sh @@ -390,6 +390,13 @@ function safety_upgrade_backup() cp -arf ${cantian_local}/* ${backup_dir}/cantian/cantian_local record_cantian_info ${backup_dir} + deploy_mode=$(python3 ${CURRENT_PATH}/get_config_info.py "deploy_mode") + if [[ ${deploy_mode} == "dss" ]]; then + rm -rf /mnt/dbdata/local/cantian/tmp/data/data + mkdir -p /mnt/dbdata/local/cantian/tmp/data/data + chmod 750 /mnt/dbdata/local/cantian/tmp/data/data + chown ${cantian_user} /mnt/dbdata/local/cantian/tmp/data/data + fi echo "check that all files are backed up to ensure that no data is lost for safety upgrade and rollback" check_backup_files ${backup_dir}/cantian/cantian_home_files_list.txt ${backup_dir}/cantian/cantian_home ${cantian_home} @@ -403,7 +410,7 @@ function safety_upgrade_backup() function copy_cantian_dbstor_cfg() { - if [[ x"${deploy_mode}" == x"file" ]]; then + if [[ x"${deploy_mode}" == x"file" ]] || [[ ${deploy_mode} == "dss" ]]; then return 0 fi echo "update the cantian local config files for dbstor in ${cantian_local}" @@ -449,8 +456,8 @@ function update_cantian_server() rm -rf ${cantian_home}/server/* cp -arf ${cantian_pkg_file}/add-ons ${cantian_pkg_file}/admin ${cantian_pkg_file}/bin \ ${cantian_pkg_file}/cfg ${cantian_pkg_file}/lib ${cantian_pkg_file}/package.xml ${cantian_home}/server - - if [[ x"${deploy_mode}" == x"file" ]]; then + rm -rf ${cantian_home}/server/bin/cms + if [[ x"${deploy_mode}" == x"file" ]] || [[ x"${deploy_mode}" == x"dss" ]];then return 0 fi @@ -466,6 +473,7 @@ function update_cantian_server() echo "link_type is rdma_1823" fi cp -arf ${cantian_home}/server/add-ons/kmc_shared/lib* ${cantian_home}/server/add-ons/ + rm -rf ${cantian_home}/server/bin/cms return 0 } @@ -542,6 +550,7 @@ function safety_rollback() fi rm -rf ${cantian_local}/* cp -arf ${backup_dir}/cantian/cantian_local/* ${cantian_local} + rm -rf ${cantian_home}/server/bin/cms echo "check that all files are rolled back to ensure that no data is lost for safety rollback" check_rollback_files ${backup_dir}/cantian/cantian_home_files_list.txt ${backup_dir}/cantian/cantian_home ${cantian_home} diff --git a/pkg/deploy/action/cantian/cantian_install.py b/pkg/deploy/action/cantian/cantian_install.py index b8f854e2655305718d1b557d41c3659f9f0b7b45..96db5af5973e499dc6aa89b39575816a4ddb97a8 100644 --- a/pkg/deploy/action/cantian/cantian_install.py +++ b/pkg/deploy/action/cantian/cantian_install.py @@ -1155,12 +1155,13 @@ class Installer: chown data and gcc dirs :return: """ - cmd = "chown %s:%s -hR \"%s\";" % (self.user, self.group, self.data) - LOGGER.info("Change owner cmd: %s" % cmd) - ret_code, _, stderr = _exec_popen(cmd) - if ret_code: - raise Exception( - "chown to %s:%s return: %s%s%s" % (self.user, self.group, str(ret_code), os.linesep, stderr)) + if os.getuid() == 0: + cmd = "chown %s:%s -hR \"%s\";" % (self.user, self.group, self.data) + LOGGER.info("Change owner cmd: %s" % cmd) + ret_code, _, stderr = _exec_popen(cmd) + if ret_code: + raise Exception( + "chown to %s:%s return: %s%s%s" % (self.user, self.group, str(ret_code), os.linesep, stderr)) ########################################################################### # Is there a database installed by the user? If right, raise error diff --git a/pkg/deploy/action/cantian_common/env_lun.sh b/pkg/deploy/action/cantian_common/env_lun.sh index a580a453a674e8f88c29952fc30bc0886272d18a..1994b8bf4ca1b0b4c8dfe220b68ce4fe19ebefcb 100644 --- a/pkg/deploy/action/cantian_common/env_lun.sh +++ b/pkg/deploy/action/cantian_common/env_lun.sh @@ -9,16 +9,16 @@ cantian_user="cantian" cantian_group="cantian" cantian_common_group="cantiangroup" -PRE_INSTALL_ORDER=("cantian" "cms" "dbstor" "dss") -INSTALL_ORDER=("dbstor" "cms" "dss" "cantian" "ct_om" "cantian_exporter" "mysql" "logicrep") -START_ORDER=("cms" "dss" "cantian" "ct_om" "cantian_exporter" "logicrep") -STOP_ORDER=("logicrep" "cms" "dss" "cantian" "ct_om" "cantian_exporter") -UNINSTALL_ORDER=("ct_om" "cantian" "dss" "cms" "dbstor" "logicrep") -BACKUP_ORDER=("cantian" "dss" "cms" "ct_om" "dbstor" ) +PRE_INSTALL_ORDER=("cantian" "cms" "dss") +INSTALL_ORDER=( "cms" "dss" "cantian" "ct_om" "cantian_exporter" "mysql") +START_ORDER=("cms" "dss" "cantian" "ct_om" "cantian_exporter") +STOP_ORDER=("cms" "dss" "cantian" "ct_om" "cantian_exporter") +UNINSTALL_ORDER=("ct_om" "cantian" "dss" "cms") +BACKUP_ORDER=("cantian" "dss" "cms" "ct_om") CHECK_STATUS=("cantian" "cms" "dss" "ct_om" "cantian_exporter") -PRE_UPGRADE_ORDER=("ct_om" "cantian_exporter" "dbstor" "cms" "dss" "cantian" "mysql" "logicrep") -UPGRADE_ORDER=("ct_om" "cantian_exporter" "dbstor" "cms" "dss" "cantian" "mysql" "logicrep") -POST_UPGRADE_ORDER=("ct_om" "cantian_exporter" "dbstor" "cms" "dss" "cantian" "mysql") -ROLLBACK_ORDER=("dbstor" "cms" "cantian" "mysql" "ct_om" "cantian_exporter" "logicrep") -INIT_CONTAINER_ORDER=("dbstor" "cms" "cantian" "logicrep") +PRE_UPGRADE_ORDER=("ct_om" "cantian_exporter" "cms" "cantian" "mysql") +UPGRADE_ORDER=("ct_om" "cantian_exporter" "cms" "cantian" "mysql") +POST_UPGRADE_ORDER=("ct_om" "cantian_exporter" "cms" "cantian" "mysql") +ROLLBACK_ORDER=("cms" "cantian" "mysql" "ct_om" "cantian_exporter") +INIT_CONTAINER_ORDER=("cms" "cantian" "logicrep") DIR_LIST=(/opt/cantian/cms /opt/cantian/cantian /opt/cantian/dbstor /opt/cantian/mysql ${CURRENT_FILE_PATH}/inspection/inspection_scripts/kernal ${CURRENT_FILE_PATH}/inspection/inspection_scripts/cms ${CURRENT_FILE_PATH}/inspection/inspection_scripts/ct_om) \ No newline at end of file diff --git a/pkg/deploy/action/cms/appctl.sh b/pkg/deploy/action/cms/appctl.sh index c768026454e5a646032b32c9901f02d45c9e6168..986f56e8c547dafdcc0d4e78f7e8c8d584727b98 100644 --- a/pkg/deploy/action/cms/appctl.sh +++ b/pkg/deploy/action/cms/appctl.sh @@ -300,7 +300,7 @@ function pre_upgrade() return 1 fi - if [[ x"${deploy_mode}" != x"dbstor" && x"${deploy_mode}" != x"combined" ]]; then + if [[ x"${deploy_mode}" == x"file" ]]; then echo "check gcc home: /mnt/dbdata/remote/share_${storage_share_fs}" if [ ! -d /mnt/dbdata/remote/share_${storage_share_fs}/gcc_home ];then echo "Error: gcc home does not exist!" @@ -345,7 +345,7 @@ function post_upgrade() fi ls -l ${cms_scripts} - if [[ x"${deploy_mode}" != x"dbstor" && x"${deploy_mode}" != x"combined" ]]; then + if [[ x"${deploy_mode}" == x"file" ]]; then echo "check gcc home: /mnt/dbdata/remote/share_${storage_share_fs}" if [ ! -d /mnt/dbdata/remote/share_${storage_share_fs}/gcc_home ];then echo "Error: gcc home does not exist!" @@ -445,7 +445,7 @@ function update_cms_service() { ${cms_pkg_file}/cfg ${cms_pkg_file}/lib ${cms_pkg_file}/package.xml ${cantian_home}/server deploy_mode=$(python3 ${CURRENT_PATH}/get_config_info.py "deploy_mode") - if [[ x"${deploy_mode}" == x"file" ]]; then + if [[ x"${deploy_mode}" == x"file" ]] || [[ ${deploy_mode} == "dss" ]]; then return 0 fi @@ -482,6 +482,10 @@ function chown_mod_cms_service() find ${cantian_home}/server/lib -type f | xargs chmod 500 find ${cantian_home}/server/cfg -type f | xargs chmod 400 + if [[ x"${deploy_mode}" == x"dss" ]]; then + sudo setcap CAP_SYS_RAWIO+ep "${cms_home}"/service/bin/cms + fi + chmod 400 ${cms_home}/service/package.xml chmod 400 ${cantian_home}/server/package.xml return 0 diff --git a/pkg/deploy/action/docker/dbstor_tool_opt_common.sh b/pkg/deploy/action/docker/dbstor_tool_opt_common.sh index dcc5bf3e682fa48e730e9637b8fadfc81da74d0c..3e82c25aa154a4e873b82653c3d55bb6940ddbce 100644 --- a/pkg/deploy/action/docker/dbstor_tool_opt_common.sh +++ b/pkg/deploy/action/docker/dbstor_tool_opt_common.sh @@ -149,7 +149,16 @@ function create_file_in_filesystem() { } function update_local_status_file_path_by_dbstor() { - if [[ "${deploy_mode}" != "dbstor" ]];then + if [[ "${deploy_mode}" == "dss" ]];then + mkdir -p "${METADATA_FS_PATH}"/upgrade/cluster_and_node_status + chown "${cantian_user}":"${cantian_group}" "${METADATA_FS_PATH}"/upgrade + chown "${cantian_user}":"${cantian_group}" "${METADATA_FS_PATH}"/upgrade/cluster_and_node_status + su -s /bin/bash - "${cantian_user}" -c "python3 -B "${CURRENT_PATH}/dss/common/dss_upgrade_local_status_file.py"" + result_local=$? + if [[ $? -ne 0 ]];then + logAndEchoError "file to local failed." + exit 0 + fi return 0 fi chown "${cantian_user}":"${cantian_group}" ${METADATA_FS_PATH} @@ -202,12 +211,19 @@ function update_local_status_file_path_by_dbstor() { } function update_remote_status_file_path_by_dbstor() { - if [[ "${deploy_mode}" != "dbstor" ]];then + cluster_or_node_status_file_path=$1 + if [[ "${deploy_mode}" == "dss" ]];then + chown -hR "${cantian_user}":"${cantian_group}" ${METADATA_FS_PATH}/upgrade + su -s /bin/bash - "${cantian_user}" -c "python3 -B ${CURRENT_PATH}/dss/common/dss_upgrade_remote_status_file.py ${cluster_or_node_status_file_path}" + result_remote=$? + if [[ $? -ne 0 ]];then + logAndEchoError "file to remote failed." + exit 0 + fi return 0 fi get_dbs_version dbs_vs=$? - cluster_or_node_status_file_path=$1 chown -hR "${cantian_user}":"${cantian_group}" ${METADATA_FS_PATH}/upgrade if [[ -d ${cluster_or_node_status_file_path} ]];then relative_path=$(realpath --relative-to="${METADATA_FS_PATH}"/upgrade "${dir_path}") @@ -239,10 +255,16 @@ function update_remote_status_file_path_by_dbstor() { } function delete_fs_upgrade_file_or_path_by_dbstor() { - if [[ "${deploy_mode}" != "dbstor" ]];then + local file_name=$1 + if [[ "${deploy_mode}" == "dss" ]];then + su -s /bin/bash - "${cantian_user}" -c "python3 -B ${CURRENT_PATH}/dss/common/dss_upgrade_delete.py ${file_name}" + result_yml=$? + if [[ $? -ne 0 ]];then + logAndEchoError "file to delete failed." + exit 1 + fi return 0 fi - local file_name=$1 logAndEchoInfo "Start to delete ${file_name} in file path ${file_path}" declare -a upgrade_dirs # shellcheck disable=SC2207 @@ -261,7 +283,14 @@ function delete_fs_upgrade_file_or_path_by_dbstor() { } function update_version_yml_by_dbstor() { - if [[ "${deploy_mode}" != "dbstor" ]];then + if [[ "${deploy_mode}" == "dss" ]];then + chown "${cantian_user}":"${cantian_group}" "${PKG_PATH}/${VERSION_FILE}" + su -s /bin/bash - "${cantian_user}" -c "python3 -B ${CURRENT_PATH}/dss/common/dss_upgrade_yaml.py ${PKG_PATH}/${VERSION_FILE}" + result_yml=$? + if [[ $? -ne 0 ]];then + logAndEchoError "file to yml failed." + exit 1 + fi return 0 fi chown "${cantian_user}":"${cantian_group}" "${PKG_PATH}/${VERSION_FILE}" @@ -276,10 +305,17 @@ function update_version_yml_by_dbstor() { } function upgrade_lock_by_dbstor() { - if [[ "${deploy_mode}" != "dbstor" ]];then + node_lock_file=${lock_file_prefix}${node_id} + if [[ "${deploy_mode}" == "dss" ]];then + touch /mnt/dbdata/remote/metadata_/upgrade/${node_lock_file} + su -s /bin/bash - "${cantian_user}" -c "python3 -B ${CURRENT_PATH}/dss/common/dss_upgrade_lock.py ${node_lock_file}" + result_lock=$? + if [[ $? -ne 0 ]];then + logAndEchoError "file to lock failed." + exit 1 + fi return 0 fi - node_lock_file=${lock_file_prefix}${node_id} get_dbs_version dbs_vs=$? upgrade_nodes=$(query_filesystem ${dbs_vs} ${storage_share_fs} "/upgrade" | grep -E "${lock_file_prefix}" | wc -l) @@ -305,12 +341,19 @@ function upgrade_lock_by_dbstor() { } function upgrade_unlock_by_dbstor() { - if [[ "${deploy_mode}" != "dbstor" ]];then + node_lock_file=${lock_file_prefix}${node_id} + if [[ "${deploy_mode}" == "dss" ]];then + su -s /bin/bash - "${cantian_user}" -c "python3 -B "${CURRENT_PATH}/dss/common/dss_upgrade_unlock.py" ${node_lock_file}" + result_unlock=$? + if [[ $? -ne 0 ]];then + logAndEchoError "file to rempte failed." + exit 1 + fi return 0 fi get_dbs_version dbs_vs=$? - node_lock_file=${lock_file_prefix}${node_id} + lock_file=$(query_filesystem ${dbs_vs} ${storage_share_fs} "upgrade" | grep "${node_lock_file}" | wc -l) if [[ ${lock_file} -eq 0 ]];then diff --git a/pkg/deploy/action/dss/appctl.sh b/pkg/deploy/action/dss/appctl.sh index 98c5e062f3488f5b0fd52a5454f51500e5670097..ca6b7560a170718876ab7e20e600839b9ab30af2 100644 --- a/pkg/deploy/action/dss/appctl.sh +++ b/pkg/deploy/action/dss/appctl.sh @@ -63,7 +63,7 @@ function do_deploy() function permission_opt() { chmod 500 "${DSS_SOURCE}"/bin/* chown -hR "${cantian_user}":"${cantian_group}" "${DSS_SOURCE}" - chown "${cantian_user}":"${cantian_group}" "${CURRENT_PATH}"/* + chown -hR "${cantian_user}":"${cantian_group}" "${CURRENT_PATH}"/* chown root:root "${CURRENT_PATH}"/appctl.sh mkdir -p /opt/cantian/log/dss touch /opt/cantian/log/dss/dss_deploy.log diff --git a/pkg/deploy/action/dss/common/dss_upgrade_commit.py b/pkg/deploy/action/dss/common/dss_upgrade_commit.py new file mode 100644 index 0000000000000000000000000000000000000000..26f1fa2a57e856e507f3702ba83dabc98324c642 --- /dev/null +++ b/pkg/deploy/action/dss/common/dss_upgrade_commit.py @@ -0,0 +1,81 @@ +import os +import sys +from file_utils import read_dss_file +CURRENT_PATH = os.path.dirname(os.path.abspath(__file__)) +sys.path.append(os.path.join(CURRENT_PATH, "..", "..")) +from update_config import _exec_popen +sys.path.append(os.path.join(CURRENT_PATH, "..")) +from dssctl import LOG + + +class DssUpgradeCommit(object): + def __init__(self): + self.node_status_num = 0 + self.node_ip_num = 0 + + def file_exits(self): + ''' + 检查cluster_and_node_status下是否有文件存在 + ''' + cmd = "dsscmd ls -p +vg1/upgrade/cluster_and_node_status" + code, stdout, stderr = _exec_popen(cmd) + + if code != 0: + raise Exception(f"dsscmd ls commit failed: {stderr}") + + lines = stdout.strip().splitlines() + if len(lines) < 2: + LOG.error(f"cluster_and_node_status file is not complete") + sys.exit(1) + + for line in lines: + if "status.txt" in line and "cluster" not in line: + self.node_status_num += 1 + + def check_nodes(self, cms_status="127.0.0.0"): + ''' + 检查节点状态文件和cms的ip数量是否相同 + ''' + self.node_ip_num = len(cms_status.split(";")) + if self.node_ip_num != self.node_status_num: + LOG.error(f"txt num is {self.node_status_num}, ip num is {self.node_ip_num}") + if self.node_ip_num < self.node_status_num: + LOG.error(f"the txt in cluster_and_node_status is not enough") + sys.exit(1) + sys.exit(1) + + def check_status_file(self): + ''' + 检查节点状态文件内容 + ''' + context = [] + for i in range(self.node_ip_num): + node_status_file = os.path.join("+vg1/upgrade/cluster_and_node_status", f"node{i}_status.txt") + context.append(read_dss_file(node_status_file)) + for rollup_result in context: + if rollup_result != "rollup_success": + LOG.error(f"rollup result is error {rollup_result}") + sys.exit(1) + + def upgrade_commit(self, input_status=None): + self.file_exits() + self.check_nodes(input_status) + self.check_status_file() + + +def main(): + dss_commit = DssUpgradeCommit() + if len(sys.argv) < 1: + raise Exception("remote not input") + input_status = sys.argv[1] + try: + dss_commit.upgrade_commit(input_status) + except Exception as e: + LOG.error(f"cluster file check error") + sys.exit(1) + +if __name__ == "__main__": + try: + main() + except Exception as err: + exit(str(err)) \ No newline at end of file diff --git a/pkg/deploy/action/dss/common/dss_upgrade_detele.py b/pkg/deploy/action/dss/common/dss_upgrade_detele.py new file mode 100644 index 0000000000000000000000000000000000000000..3516b18db25b15a1357eb20c6fa36263beb2d65f --- /dev/null +++ b/pkg/deploy/action/dss/common/dss_upgrade_detele.py @@ -0,0 +1,91 @@ +import os +import sys +from get_config_info import get_value +CURRENT_PATH = os.path.dirname(os.path.abspath(__file__)) +sys.path.append(os.path.join(CURRENT_PATH, "..", "..")) +from update_config import _exec_popen +sys.path.append(os.path.join(CURRENT_PATH, "..")) +from dssctl import LOG + + +class DssDetele(object): + def __init__(self): + self.node_id = None + self.node_lock_file_name = None + self.node_lock_file_path = None + self.cantian_user = None + self.vg_lock_file_path = None + + def file_exits(self, input_file=None): + cmd = f'dsscmd ls -p +vg1/upgrade' + code, stdout, _ = _exec_popen(cmd) + + if code != 0: + return True + + lines = stdout.strip().splitlines() + + for line in lines: + if input_file in line: + return True + return False + + def delete_file(self, input_file=None): + cmd = f'dsscmd rm -p +vg1/{input_file}' + code, _, stderr = _exec_popen(cmd) + + if code != 0: + raise RuntimeError(f"`dsscmd rm delete` failed: {stderr}") + + def delete_special_file(self, file_name, vg_path_name): + cmd = f'dsscmd ls -p {vg_path_name}' + code, stdout, _ = _exec_popen(cmd) + + if code != 0: + return + + lines = stdout.strip().splitlines() + + for line in lines: + if file_name in line[5]: + self.delete_file(line[5]) + + def delete_dir(self, input_file=None): + cmd = f'dsscmd rmdir -p +vg1/upgrade/{input_file} -r' + code, _, stderr = _exec_popen(cmd) + + if code != 0: + raise RuntimeError(f"`dsscmd rmdir delete` failed: {stderr}") + + def upgrade_detele_by_dss(self, input_file=None): + if "updatesys" in input_file: + self.delete_special_file("updatesys", "+vg1/upgrade") + elif input_file == "cluster_and_node_status": + self.delete_dir("cluster_and_node_status") + elif "cluster_and_node_status/node" in input_file: + self.delete_special_file("node", "+vg1/upgrade/cluster_and_node_status") + elif "upgrade_node" in input_file: + self.delete_special_file("upgrade_node", "+vg1/upgrade") + else: + if not self.file_exits(input_file): + return + self.delete_file(input_file) + + +def main(): + dss_delete = DssDetele() + if len(sys.argv) < 1: + raise Exception("Failed to delete dss when upgrade input") + input_file = sys.argv[1] + try: + dss_delete.upgrade_detele_by_dss(input_file) + except Exception as e: + LOG.error(f"Failed to delete dss file when upgrade") + sys.exit(1) + + +if __name__ == "__main__": + try: + main() + except Exception as err: + exit(str(err)) \ No newline at end of file diff --git a/pkg/deploy/action/dss/common/dss_upgrade_local_status_file.py b/pkg/deploy/action/dss/common/dss_upgrade_local_status_file.py new file mode 100644 index 0000000000000000000000000000000000000000..4f7cdf0a2ae76fce17b877e57c24acb1d5d489ac --- /dev/null +++ b/pkg/deploy/action/dss/common/dss_upgrade_local_status_file.py @@ -0,0 +1,53 @@ +import os +import sys +CURRENT_PATH = os.path.dirname(os.path.abspath(__file__)) +sys.path.append(os.path.join(CURRENT_PATH, "..", "..")) +from update_config import _exec_popen +sys.path.append(os.path.join(CURRENT_PATH, "..")) +from dssctl import LOG + + +class DssLocalStatusfile(object): + def dir_exists(self, exists_path, exists_dir): + cmd = f"dsscmd ls -p {exists_path}" + code, stdout, stderr = _exec_popen(cmd) + + if code != 0: + raise Exception(f"dsscmd ls local failed: {stderr}") + + lines = stdout.strip().splitlines() + if len(lines) < 2: + return False + + for line in lines: + if exists_dir in line: + return True + + def mkdir_local_status_file_to_path(self, mkdir_path, mkdir_dir): + if self.dir_exists(mkdir_path, mkdir_dir): + return + cmd = f"dsscmd mkdir -p {mkdir_path} -d {mkdir_dir}" + code, _, stderr = _exec_popen(cmd) + + if code != 0: + raise Exception(f"dsscmd mkdir local failed: {stderr}") + + def upgrade_local_status_file_by_dss(self): + self.mkdir_local_status_file_to_path("+vg1", "upgrade") + self.mkdir_local_status_file_to_path("+vg1/upgrade", "cluster_and_node_status") + + +def main(): + dss_local_status = DssLocalStatusfile() + try: + dss_local_status.upgrade_local_status_file_by_dss() + except Exception as e: + LOG.error(f"Failed with local file when upgrade") + sys.exit(1) + + +if __name__ == "__main__": + try: + main() + except Exception as err: + exit(str(err)) \ No newline at end of file diff --git a/pkg/deploy/action/dss/common/dss_upgrade_lock.py b/pkg/deploy/action/dss/common/dss_upgrade_lock.py new file mode 100644 index 0000000000000000000000000000000000000000..fc3a11610f971e98683928ffb814061f1b5e6994 --- /dev/null +++ b/pkg/deploy/action/dss/common/dss_upgrade_lock.py @@ -0,0 +1,86 @@ +import os +import sys +from file_utils import pad_file_to_512 +CURRENT_PATH = os.path.dirname(os.path.abspath(__file__)) +sys.path.append(os.path.join(CURRENT_PATH, "..", "..")) +from update_config import _exec_popen +sys.path.append(os.path.join(CURRENT_PATH, "..")) +from dssctl import LOG + + +class DssLock(object): + def __init__(self): + self.node_lock_file_name = None + self.node_lock_file_path = None + self.vg_lock_file_path = None + self.lock_res = None + + def create_vg_upgrade_path(self): + + cmd = f'dsscmd mkdir -p +vg1 -d upgrade' + code, _, stderr = _exec_popen(cmd) + + if code != 0: + raise RuntimeError(f"dsscmd mkdir lock failed: {stderr}") + + def cp_node_lock_file_to_path(self): + + cmd = f'dsscmd cp -s {self.node_lock_file_path} -d {self.vg_lock_file_path}' + code, _, stderr = _exec_popen(cmd) + + if code != 0: + raise RuntimeError(f"dsscmd cp lock failed: {stderr}") + + def is_locked_new(self): + cmd = f'dsscmd ls -p +vg1/upgrade' + code, stdout, _ = _exec_popen(cmd) + + if code != 0: + self.lock_res = "upgrade no exists" + return + + lines = stdout.strip().splitlines() + if len(lines) < 2: + self.lock_res = "upgrade is empty" + return + + for line in lines: + if self.node_lock_file_name in line: + self.lock_res = "node lock is existing" + return + if "upgrade_lock_" in line[5]: + raise RuntimeError(f"other lock is using, {line[5]}") + self.lock_res = "upgrade not lock" + + def upgrade_lock_by_dss(self, input_file=None): + self.node_lock_file_name = os.path.basename(input_file) + self.node_lock_file_path = os.path.join("/mnt/dbdata/remote/metadata_/upgrade", self.node_lock_file_name) + self.vg_lock_file_path = os.path.join("+vg1/upgrade", self.node_lock_file_name) + + self.is_locked_new() + if self.lock_res == "upgrade no exists": + self.create_vg_upgrade_path() + elif self.lock_res == "node lock is existing": + return + pad_file_to_512(self.node_lock_file_path) + self.cp_node_lock_file_to_path() + LOG.info(f"{self.node_lock_file_name} success") + + +def main(): + dss_lock = DssLock() + if len(sys.argv) < 1: + raise Exception("upgrade lock no input") + input_file = sys.argv[1] + try: + dss_lock.upgrade_lock_by_dss(input_file) + except Exception as e: + LOG.error(f"Failed to lock dss when upgrade") + sys.exit(1) + + +if __name__ == "__main__": + try: + main() + except Exception as err: + exit(str(err)) \ No newline at end of file diff --git a/pkg/deploy/action/dss/common/dss_upgrade_remote_status_file.py b/pkg/deploy/action/dss/common/dss_upgrade_remote_status_file.py new file mode 100644 index 0000000000000000000000000000000000000000..5821e48890ce5ad6a584e03f258445ea7b28460d --- /dev/null +++ b/pkg/deploy/action/dss/common/dss_upgrade_remote_status_file.py @@ -0,0 +1,90 @@ +import os +import sys +from get_config_info import get_value +from file_utils import pad_file_to_512 +CURRENT_PATH = os.path.dirname(os.path.abspath(__file__)) +sys.path.append(os.path.join(CURRENT_PATH, "..", "..")) +from update_config import _exec_popen +sys.path.append(os.path.join(CURRENT_PATH, "..")) +from dssctl import LOG + + +class DssRemoteStatusfile(object): + def __init__(self): + self.node_remote_status_file_name = None + self.node_remote_status_file_path = None + self.vg_remote_file_path = None + + def file_exits(self, vg_path): + cmd = f'dsscmd ls -p {vg_path}' + code, _, _ = _exec_popen(cmd) + + if code == 0: + return True + return False + + def detele_file(self, vg_path): + cmd = f'dsscmd rm -p {vg_path}' + code, _, stderr = _exec_popen(cmd) + + if code != 0: + LOG.error(f"`dsscmd rm remote` failed: {stderr}") + sys.exit(1) + + def cp_remote_status_file_to_path(self): + + if self.file_exits(self.vg_remote_file_path): + self.detele_file(self.vg_remote_file_path) + cmd = f'dsscmd cp -s {self.node_remote_status_file_path} -d {self.vg_remote_file_path}' + code, _, stderr = _exec_popen(cmd) + + if code != 0: + LOG.error(f"`dsscmd cp remote` failed: {stderr}") + sys.exit(1) + + def mkdir_vg_path(self): + if self.file_exits("+vg1/upgrade/cluster_and_node_status"): + return + cmd = f'dsscmd mkdir -p +vg1/upgrade -d cluster_and_node_status' + code, _, stderr = _exec_popen(cmd) + + if code != 0: + LOG.error(f"`dsscmd mkdir remote` failed: {stderr}") + sys.exit(1) + + def upgrade_remote_status_file_by_dss(self, remote_status_file): + if "cluster_and_node_status" in remote_status_file: + self.node_remote_status_file_name = os.path.basename(remote_status_file) + self.node_remote_status_file_path = remote_status_file + self.vg_remote_file_path = os.path.join("+vg1/upgrade/cluster_and_node_status", + self.node_remote_status_file_name) + self.mkdir_vg_path() + pad_file_to_512(self.node_remote_status_file_path) + self.cp_remote_status_file_to_path() + else: + self.node_remote_status_file_name = os.path.basename(remote_status_file) + self.node_remote_status_file_path = remote_status_file + self.vg_remote_file_path = os.path.join("+vg1/upgrade", self.node_remote_status_file_name) + + pad_file_to_512(self.node_remote_status_file_path) + self.cp_remote_status_file_to_path() + return + + +def main(): + dss_remote_status = DssRemoteStatusfile() + if len(sys.argv) < 1: + raise Exception("remote not input") + input_file = sys.argv[1] + try: + dss_remote_status.upgrade_remote_status_file_by_dss(input_file) + except Exception as e: + LOG.error(f"Failed to input file when upgrade") + sys.exit(1) + + +if __name__ == "__main__": + try: + main() + except Exception as err: + exit(str(err)) \ No newline at end of file diff --git a/pkg/deploy/action/dss/common/dss_upgrade_unlock.py b/pkg/deploy/action/dss/common/dss_upgrade_unlock.py new file mode 100644 index 0000000000000000000000000000000000000000..34fb0c48a7a6f4fdcf84741ea7e5d05027371f9a --- /dev/null +++ b/pkg/deploy/action/dss/common/dss_upgrade_unlock.py @@ -0,0 +1,63 @@ +import os +import sys +CURRENT_PATH = os.path.dirname(os.path.abspath(__file__)) +sys.path.append(os.path.join(CURRENT_PATH, "..", "..")) +from update_config import _exec_popen +sys.path.append(os.path.join(CURRENT_PATH, "..")) +from dssctl import LOG + + +class DssUnLock(object): + def __init__(self): + self.node_lock_file_name = None + self.vg_lock_file_path = None + + def is_locked(self): + cmd = f'dsscmd ls -p +vg1/upgrade' + code, stdout, stderr = _exec_popen(cmd) + + if code != 0: + raise RuntimeError(f"`dsscmd ls unlock` failed: {stderr}") + + lines = stdout.strip().splitlines() + if len(lines) < 2: + LOG.error(f"no file with lock") + sys.exit(1) + + for line in lines: + if self.node_lock_file_name in line: + return True + return False + + def unlock_node(self): + cmd = f'dsscmd rm -p {self.vg_lock_file_path}' + code, _, stderr = _exec_popen(cmd) + + if code != 0: + raise RuntimeError(f"`dsscmd rm unlock` failed: {stderr}") + + def upgrade_unlock_by_dss(self, input_file=None): + self.node_lock_file_name = os.path.basename(input_file) + self.vg_lock_file_path = os.path.join("+vg1/upgrade", self.node_lock_file_name) + if self.is_locked(): + self.unlock_node() + return + + +def main(): + dss_unlock = DssUnLock() + if len(sys.argv) < 1: + raise Exception("Failed to unlock dss when upgrade input") + input_file = sys.argv[1] + try: + dss_unlock.upgrade_unlock_by_dss(input_file) + except Exception as e: + LOG.error(f"Failed to unlock dss when upgrade") + sys.exit(1) + + +if __name__ == "__main__": + try: + main() + except Exception as err: + exit(str(err)) \ No newline at end of file diff --git a/pkg/deploy/action/dss/common/dss_upgrade_yaml.py b/pkg/deploy/action/dss/common/dss_upgrade_yaml.py new file mode 100644 index 0000000000000000000000000000000000000000..d9c23034029974f2e5af5e59db69cc5bacaa567d --- /dev/null +++ b/pkg/deploy/action/dss/common/dss_upgrade_yaml.py @@ -0,0 +1,69 @@ +import os +import sys +CURRENT_PATH = os.path.dirname(os.path.abspath(__file__)) +sys.path.append(os.path.join(CURRENT_PATH, "..", "..")) +from update_config import _exec_popen +sys.path.append(os.path.join(CURRENT_PATH, "..")) +from dssctl import LOG + + +class DssYaml(object): + def __init__(self): + self.node_yaml_file_name = None + self.node_yaml_file_path = None + self.vg_yaml_file_path = None + + def detele_file(self, vg_path): + cmd = f'dsscmd rm -p {vg_path}' + code, _, stderr = _exec_popen(cmd) + + if code != 0: + LOG.error(f"`dsscmd rm yaml` failed: {stderr}") + sys.exit(1) + + def file_exits(self): + cmd = f'dsscmd ls -p +vg1' + code, stdout, _ = _exec_popen(cmd) + + if code != 0: + return + + lines = stdout.strip().splitlines() + + for line in lines: + if self.node_yaml_file_name in line: + self.detele_file(self.vg_yaml_file_path) + break + + def cp_yaml_file_to_path(self): + + cmd = f'dsscmd cp -s {self.node_yaml_file_path} -d {self.vg_yaml_file_path}' + code, _, stderr = _exec_popen(cmd) + + if code != 0: + raise RuntimeError(f"`dsscmd cp yaml` failed: {stderr}") + + def upgrade_yaml_by_dss(self, input_file=None): + self.node_yaml_file_name = os.path.basename(input_file) + self.node_yaml_file_path = input_file + self.vg_yaml_file_path = os.path.join("+vg1", self.node_yaml_file_name) + self.cp_yaml_file_to_path() + return + + +def main(): + dss_yaml = DssYaml() + if len(sys.argv) < 1: + raise Exception("Failed to cp yaml when upgrade input") + input_file = sys.argv[1] + try: + dss_yaml.upgrade_yaml_by_dss(input_file) + except Exception as e: + LOG.error(f"Failed to cp yaml when upgrade") + sys.exit(1) + +if __name__ == "__main__": + try: + main() + except Exception as err: + exit(str(err)) \ No newline at end of file diff --git a/pkg/deploy/action/dss/common/exec_cmd.py b/pkg/deploy/action/dss/common/exec_cmd.py new file mode 100644 index 0000000000000000000000000000000000000000..c5763d1cd0b9f75b9bbafee6d3e3fa5d59b2dfec --- /dev/null +++ b/pkg/deploy/action/dss/common/exec_cmd.py @@ -0,0 +1,49 @@ +import os +import signal +import subprocess + +TIME_OUT = 60 +FAIL = 1 + + +def close_child_process(proc): + try: + os.killpg(proc.pid, signal.SIGKILL) + except ProcessLookupError as err: + _ = err + return 'success' + except Exception as err: + return str(err) + + return 'success' + + +def exec_popen(cmd): + """ + subprocess.Popen in python3. + param cmd: commands need to execute + return: status code, standard output, error output + """ + bash_cmd = ["bash"] + pobj = subprocess.Popen(bash_cmd, shell=False, stdin=subprocess.PIPE, + stdout=subprocess.PIPE, stderr=subprocess.PIPE, preexec_fn=os.setsid) + pobj.stdin.write(cmd.encode()) + pobj.stdin.write(os.linesep.encode()) + try: + stdout, stderr = pobj.communicate(timeout=TIME_OUT) + except Exception as err: + return pobj.returncode, "", str(err) + finally: + return_code = pobj.returncode + kill_fork_process_res = close_child_process(pobj) + + if kill_fork_process_res != "success": + return FAIL, "", "kill fork process failed, err_details: {}".format(kill_fork_process_res) + + stdout, stderr = stdout.decode(), stderr.decode() + if stdout[-1:] == os.linesep: + stdout = stdout[:-1] + if stderr[-1:] == os.linesep: + stderr = stderr[:-1] + + return return_code, stdout, stderr \ No newline at end of file diff --git a/pkg/deploy/action/dss/common/file_utils.py b/pkg/deploy/action/dss/common/file_utils.py new file mode 100644 index 0000000000000000000000000000000000000000..065a2c417273718e459e2b4c30594c36d639b7d6 --- /dev/null +++ b/pkg/deploy/action/dss/common/file_utils.py @@ -0,0 +1,126 @@ +import os +import re +from exec_cmd import exec_popen +from get_config_info import get_value + +cantian_user = get_value("deploy_user") + + +def pad_file_to_512(input_file, output_file=None): + """ + Pads a file to 512-byte alignment with zero bytes. + + Args: + input_file (str): Source file path. + output_file (str, optional): Destination file path . If None, overwrites the input file. + + Returns: + int: Final file size in bytes. + + Raises: + FileNotFoundError: If the input file does not exist. + IOError: If read/write fails. + """ + try: + if not os.path.isfile(input_file): + raise FileNotFoundError(f"Input file '{input_file}' not found.") + + with open(input_file, 'rb') as f: + data = f.read() + + original_size = len(data) + pad_size = (512 - original_size % 512) % 512 + if pad_size: + data += b'\x00' * pad_size + + if output_file is None: + output_file = input_file + + with open(output_file, 'wb') as f: + f.write(data) + + total_size = len(data) + return total_size + + except Exception as e: + raise IOError(f"Failed to pad file '{input_file}': {e}") + + +def parse_numeric(val: str) -> int: + try: + return int(float(val)) + except ValueError: + raise ValueError(f"Cannot convert '{val}' to integer.") + + +def get_written_size(vg_file_path: str) -> int: + cmd = f'su -s /bin/bash - {cantian_user} -c "dsscmd ls -p {vg_file_path} -w 0"' + code, stdout, stderr = exec_popen(cmd) + + no_file_result = " ".join(["The path", vg_file_path, "is not exsit."]) + + if stdout == no_file_result: + return 0 + + if code != 0: + raise RuntimeError(f"`dsscmd ls` failed: {stderr}") + + lines = stdout.strip().splitlines() + if len(lines) < 2: + raise ValueError("Unexpected `dsscmd ls` output: too few lines.") + + headers = lines[0].split() + values = lines[1].split() + + if 'written_size' not in headers: + raise ValueError("'written_size' column not found.") + + index = headers.index('written_size') + return parse_numeric(values[index]) + + +def parse_hex_dump(raw_output: str) -> str: + hex_bytes = [] + + for line in raw_output.strip().splitlines(): + # Extract exactly 16 hex bytes using regex: 2-digit hex tokens + matches = re.findall(r'\b[0-9a-fA-F]{2}\b', line) + if matches: + hex_bytes.extend(matches) + + try: + byte_data = bytes.fromhex(''.join(hex_bytes)) + return byte_data.replace(b'\x00', b'').decode('utf-8', errors='replace').strip() + except Exception as e: + raise ValueError(f"Failed to decode hex dump: {e}") + + +def read_dss_content(vg_file_path: str, size: int) -> str: + cmd = f'su -s /bin/bash - {cantian_user} -c "dsscmd examine -p {vg_file_path} -o 0 -f x -s {size}"' + code, stdout, stderr = exec_popen(cmd) + + if code != 0: + raise RuntimeError(f"`dsscmd examine` failed: {stderr}") + + return parse_hex_dump(stdout) + + +def read_dss_file(vg_file_path: str) -> str: + written_size = get_written_size(vg_file_path) + if written_size == 0: + return "[Empty] No actual data written to this DSS file." + return read_dss_content(vg_file_path, written_size) + + +# Example usage: +if __name__ == "__main__": + # Example usage for padding file to 512-byte alignment + try: + pad_file_to_512("./example.txt") + except Exception as e: + print(f"Operation failed: {e}") + + # Example usage for reading DSS file content + path = '+vg1/testfile.txt' + content = read_dss_file(path) + print(content) diff --git a/pkg/deploy/action/dss/common/get_config_info.py b/pkg/deploy/action/dss/common/get_config_info.py new file mode 100644 index 0000000000000000000000000000000000000000..1f0022230e5bcccaf4050d54048e6315f794ee43 --- /dev/null +++ b/pkg/deploy/action/dss/common/get_config_info.py @@ -0,0 +1,36 @@ +# -*- coding: UTF-8 -*- +import sys +import os +import json +from pathlib import Path + +CUR_PATH = os.path.dirname(os.path.realpath(__file__)) +INSTALL_FILE = str(Path(os.path.join(CUR_PATH, "../../../config/deploy_param.json"))) + + +def get_value(param): + with open(INSTALL_FILE, encoding="utf-8") as f: + _tmp = f.read() + info = json.loads(_tmp) + # deploy_user 格式为:用户:用户组 + if param == 'deploy_user': + return info.get('deploy_user').split(':')[0] + + if param == 'deploy_group': + return info.get('deploy_user').split(':')[1] + + if param == "cluster_scale": + return len(info.get("cms_ip").split(";")) + + if param == "deploy_mode": + if info.get('deploy_mode', ""): + return info.get('deploy_mode') + return "dbstor" if info.get('deploy_policy', "") in ["ModeB", "ModeC"] else "file" + + return info.get(param, "") + + +if __name__ == "__main__": + _param = sys.argv[1] + res = get_value(_param) + print(res) diff --git a/pkg/deploy/action/dss/dssctl.py b/pkg/deploy/action/dss/dssctl.py index e414507a6506ae12697292321c5e029eb3f4d9ef..fe8e6d04a7a88f9adbc657da61cd080f6aa37325 100644 --- a/pkg/deploy/action/dss/dssctl.py +++ b/pkg/deploy/action/dss/dssctl.py @@ -198,7 +198,7 @@ class DssCtl(object): LOG.info("start to init lun.") init_cmd = "dd if=/dev/zero of=%s bs=1M count=1 conv=notrunc" for key, value in VG_CONFIG.items(): - return_code, stdout, stderr = exec_popen(init_cmd % value, timeout=TIMEOUT) + return_code, stdout, stderr = exec_popen(init_cmd % value, timeout=120) if return_code: output = stdout + stderr err_msg = "Init lun cmd[%s] exec failed, details: %s" % (init_cmd % value, str(output)) @@ -436,13 +436,17 @@ class DssCtl(object): else: LOG.info("dssserver is offline.") return False + + def upgrade_backup(self, *args) -> None: + LOG.info("Start to upgrade_backup dss.") + LOG.info("Success to upgrade_backup dss.") def main(): parse = argparse.ArgumentParser() parse.add_argument("--action", type=str, choices=["install", "uninstall", "start", "stop", "pre_install", - "upgrade", "rollback", "pre_upgrade"]) + "upgrade", "rollback", "pre_upgrade", "check_status", "upgrade_backup"]) parse.add_argument("--mode", required=False, dest="mode", default="") arg = parse.parse_args() act = arg.action diff --git a/pkg/deploy/action/pre_upgrade.sh b/pkg/deploy/action/pre_upgrade.sh index 0233fc211fa82a3a889b2e7da315654f0326d547..bab96de39fdadf77114f114b7cccd16ff4cc2c2c 100644 --- a/pkg/deploy/action/pre_upgrade.sh +++ b/pkg/deploy/action/pre_upgrade.sh @@ -14,6 +14,11 @@ UPGRADE_MODE_LIS=("offline" "rollup") UPDATESYS_FLAG=/opt/cantian/updatesys.true upgrade_module_correct=false +deploy_mode=$(python3 ${CURRENT_PATH}/get_config_info.py "deploy_mode") + +if [[ x"${deploy_mode}" == x"dss" ]]; then + cp -arf ${CURRENT_PATH}/cantian_common/env_lun.sh ${CURRENT_PATH}/env.sh +fi source ${CURRENT_PATH}/log4sh.sh source ${CURRENT_PATH}/env.sh @@ -264,7 +269,6 @@ function gen_upgrade_plan() { } function check_dbstor_client_compatibility() { - deploy_mode=$(python3 ${CURRENT_PATH}/get_config_info.py "deploy_mode") if [[ x"${deploy_mode}" == x"file" || "${source_version}" == "2.0.0"* ]]; then return 0 fi @@ -321,7 +325,9 @@ function offline_upgrade() { check_cms_stat check_mem_avail check_upgrade_version - check_dbstor_client_compatibility + if [[ x"${deploy_mode}" == x"dbstor" ]]; then + check_dbstor_client_compatibility + fi call_each_pre_upgrade gen_upgrade_plan } @@ -332,7 +338,9 @@ function rollup_upgrade() { local_node_health_check cantian_database_health_status_check component_version_dependency_check - check_dbstor_client_compatibility + if [[ x"${deploy_mode}" == x"dbstor" ]]; then + check_dbstor_client_compatibility + fi call_each_pre_upgrade gen_upgrade_plan } diff --git a/pkg/deploy/action/rollback.sh b/pkg/deploy/action/rollback.sh index a7a69b7dbdc6cee78e4a804c2b96f2d311386dab..276ecc0170b226e77bbf2c542f936ecf0647ecfa 100644 --- a/pkg/deploy/action/rollback.sh +++ b/pkg/deploy/action/rollback.sh @@ -835,6 +835,9 @@ function main() { get_current_node modify_env source ${CURRENT_PATH}/docker/dbstor_tool_opt_common.sh + if [[ x"${deploy_mode}" == x"dss" ]]; then + cp -arf ${CURRENT_PATH}/cantian_common/env_lun.sh ${CURRENT_PATH}/env.sh + fi source ${CURRENT_PATH}/env.sh user=${cantian_user} diff --git a/pkg/deploy/action/upgrade.sh b/pkg/deploy/action/upgrade.sh index a4507cc2748ab4a1d5c94a33105437634c592f34..8fee752fc2933faaeec71b2f53e57567dd783c5a 100644 --- a/pkg/deploy/action/upgrade.sh +++ b/pkg/deploy/action/upgrade.sh @@ -50,12 +50,16 @@ if [[ x"${deploy_mode}" == x"file" ]];then fi fi +if [[ x"${deploy_mode}" == x"dss" ]]; then + cp -arf ${CURRENT_PATH}/cantian_common/env_lun.sh ${CURRENT_PATH}/env.sh +fi + source ${CURRENT_PATH}/docker/dbstor_tool_opt_common.sh source ${CURRENT_PATH}/env.sh function rpm_check(){ local count=2 - if [ x"${deploy_mode}" != x"file" ];then + if [ x"${deploy_mode}" != x"file" ] && [ x"${deploy_mode}" != x"dss" ];then count=3 fi rpm_pkg_count=$(ls "${CURRENT_PATH}"/../repo | wc -l) @@ -79,7 +83,7 @@ function input_params_check() { fi # 离线升级需要检查阵列侧ip - if [ "${UPGRADE_MODE}" == "offline" ]; then + if [[ "${UPGRADE_MODE}" == "offline" ]]; then if [ -z "${DORADO_IP}" ]; then logAndEchoError "storage array ip must be provided" exit 1 @@ -293,7 +297,13 @@ function do_backup() { for upgrade_module in "${UPGRADE_ORDER[@]}"; do logAndEchoInfo "begin to backup ${upgrade_module}" - sh "${CURRENT_PATH}/${upgrade_module}/appctl.sh" upgrade_backup ${dircetory_path} + if [ "${upgrade_module}" == "dbstor" ]; then + if [ "${deploy_mode}" == "dss" ]; then + sh "${CURRENT_PATH}/dss/appctl.sh" upgrade_backup ${dircetory_path} + fi + else + sh "${CURRENT_PATH}/${upgrade_module}/appctl.sh" upgrade_backup ${dircetory_path} + fi if [ $? -ne 0 ]; then logAndEchoError "${upgrade_module} upgrade_backup failed" logAndEchoError "For details, see the /opt/cantian/log/${upgrade_module}. [Line:${LINENO}, File:${SCRIPT_NAME}]" @@ -403,7 +413,7 @@ function install_rpm() rpm -ivh --replacepkgs ${RPM_PATH} --nodeps --force tar -zxf ${RPM_UNPACK_PATH_FILE}/Cantian-RUN-CENTOS-64bit.tar.gz -C ${RPM_PACK_ORG_PATH} - if [ x"${deploy_mode}" != x"file" ];then + if [ x"${deploy_mode}" != x"file" ] && [ x"${deploy_mode}" != x"dss" ];then echo "start replace rpm package" install_dbstor if [ $? -ne 0 ];then @@ -873,6 +883,9 @@ function do_rollup_upgrade() { stop_cantian stop_cms + if [[ "${deploy_mode}" == "dss" ]]; then + sh /opt/cantian/action/dss/appctl.sh start + fi # 生成调用ct_backup成功的标记文件,避免重入调用时失败 touch "${storage_metadata_fs_path}/call_ctback_tool.success" && chmod 600 "${storage_metadata_fs_path}/call_ctback_tool.success" @@ -937,11 +950,16 @@ function post_upgrade_nodes_status() { cms_ip=$(python3 ${CURRENT_PATH}/get_config_info.py "cms_ip") node_count=$(expr "$(echo "${cms_ip}" | grep -o ";" | wc -l)" + 1) - cms_res=$(su -s /bin/bash - "${cantian_user}" -c "cms stat") - # step1: 统计节点拉起情况 start_array=() - readarray -t start_array <<< "$(echo "${cms_res}" | awk '{print $3}' | tail -n +$"2")" + if [[ "${deploy_mode}" == "dss" ]]; then + cms_res=$(su -s /bin/bash - "${cantian_user}" -c "cms stat | grep dss") + readarray -t start_array <<< "$(echo "${cms_res}" | awk '{print $3}')" + else + cms_res=$(su -s /bin/bash - "${cantian_user}" -c "cms stat") + readarray -t start_array <<< "$(echo "${cms_res}" | awk '{print $3}' | tail -n +$"2")" + fi + if [ ${#start_array[@]} != "${node_count}" ]; then logAndEchoError "only ${#start_array[@]} nodes were detected, totals:${node_count}" && exit 1 fi @@ -982,7 +1000,7 @@ function get_back_version() { function offline_upgrade() { cantian_status_check do_backup - if [[ ${node_id} == '0' ]] && [[ ${deploy_mode} != "file" ]]; then + if [[ ${node_id} == '0' ]] && [[ ${deploy_mode} != "file" ]] && [[ ${deploy_mode} != "dss" ]]; then creat_snapshot fi get_back_version @@ -1069,6 +1087,9 @@ function main() { # 升级成功后更新版本信息 show_cantian_version cp -fp ${CURRENT_PATH}/../versions.yml /opt/cantian + if [[ ${node_id} != '0' ]]; then + rm -rf /mnt/dbdata/remote/metadata_${storage_metadata_fs}/upgrade/upgrade_node* + fi logAndEchoInfo ">>>>> ${UPGRADE_MODE} upgrade performed successfully <<<<<" return 0 } diff --git a/pkg/deploy/action/upgrade_commit.sh b/pkg/deploy/action/upgrade_commit.sh index 17f7e27ac9acca17dba55db7eeb8fee8f52b0a59..10480ae9e7a25b5d9a09149c500988880c2556a3 100644 --- a/pkg/deploy/action/upgrade_commit.sh +++ b/pkg/deploy/action/upgrade_commit.sh @@ -69,6 +69,27 @@ function init_cluster_status_flag() { function node_status_check() { logAndEchoInfo "begin to check cluster upgrade status" + deploy_mode=$(python3 ${CURRENT_PATH}/get_config_info.py "deploy_mode") + if [[ x"${deploy_mode}" == x"dss" ]];then + cms_status_nums=$(python3 ${CURRENT_PATH}/get_config_info.py "cms_ip") + su -s /bin/bash - "${cantian_user}" -c "python3 -B ${CURRENT_PATH}/dss/common/dss_upgrade_commit.py ${cms_status_nums}" + result_python=$? + if [ $result_python -eq 0 ];then + return 3 + else + exit 1 + fi + fi + + if [[ x"${deploy_mode}" != x"dss" ]];then + python3 -B "${CURRENT_PATH}/dss/common/dss_upgrade_commit.py" + result_python=$? + if [ $result_python -eq 0 ];then + return 3 + else + exit 1 + fi + fi # 统计当前节点数目 node_count=$(expr "$(echo "${cms_ip}" | grep -o ";" | wc -l)" + 1) @@ -231,7 +252,7 @@ function clear_upgrade_residual_data() { delete_fs_upgrade_file_or_path_by_dbstor call_ctback_tool.success delete_fs_upgrade_file_or_path_by_dbstor cluster_and_node_status delete_fs_upgrade_file_or_path_by_dbstor updatesys.* - delete_fs_upgrade_file_or_path_by_dbstor upgrade_node.*."${target_version}" + delete_fs_upgrade_file_or_path_by_dbstor upgrade_node*."${target_version}" logAndEchoInfo "clear residual data success" } @@ -263,7 +284,7 @@ function offline_upgrade_commit() { fi raise_version_num deploy_mode=$(python3 ${CURRENT_PATH}/get_config_info.py "deploy_mode") - if [[ x"${deploy_mode}" != x"file" ]];then + if [[ x"${deploy_mode}" != x"file" ]] && [[ x"${deploy_mode}" != x"dss" ]];then read -p "Please input dorado_ip:" dorado_ip echo "dorado_ip is: ${dorado_ip}" ping -c 1 "${dorado_ip}" > /dev/null 2>&1