fix sunhpc

This commit is contained in:
2026-04-27 07:55:23 +08:00
parent 374c98e192
commit 8fe9eca263

211
sunhpc
View File

@@ -375,7 +375,7 @@ get_subnet_address() {
} }
# ====================== pxe server functions ==================== # ====================== pxe server functions ====================
pxe_http_build() { build_httpd_srv() {
log_debug "当前节点:${GLOBAL_NODES[*]}" log_debug "当前节点:${GLOBAL_NODES[*]}"
log_debug "公共参数:${PUBLIC_ARGS[*]}" log_debug "公共参数:${PUBLIC_ARGS[*]}"
log_debug "私有参数:${PRIVATE_ARGS[*]}" log_debug "私有参数:${PRIVATE_ARGS[*]}"
@@ -420,7 +420,7 @@ pxe_http_build() {
fi fi
} }
pxe_dnsmasq_build() { build_dnsmasq_srv() {
log_debug "当前节点:${GLOBAL_NODES[*]}" log_debug "当前节点:${GLOBAL_NODES[*]}"
log_debug "公共参数:${PUBLIC_ARGS[*]}" log_debug "公共参数:${PUBLIC_ARGS[*]}"
log_debug "私有参数:${PRIVATE_ARGS[*]}" log_debug "私有参数:${PRIVATE_ARGS[*]}"
@@ -471,7 +471,7 @@ pxe_dnsmasq_build() {
} }
# ====================== server functions ======================== # ====================== server functions ========================
slurm_build() { build_slurm_srv() {
log_debug "当前节点:${GLOBAL_NODES[*]}" log_debug "当前节点:${GLOBAL_NODES[*]}"
log_debug "公共参数:${PUBLIC_ARGS[*]}" log_debug "公共参数:${PUBLIC_ARGS[*]}"
log_debug "私有参数:${PRIVATE_ARGS[*]}" log_debug "私有参数:${PRIVATE_ARGS[*]}"
@@ -802,7 +802,7 @@ check_node_status() {
fi fi
} }
list_node() { show_nodes() {
echo "$SSEP" echo "$SSEP"
printf "${G}%-12s %-15s %-8s %s${NC}\n" "Nodename" "Status" "Port" "Days" printf "${G}%-12s %-15s %-8s %s${NC}\n" "Nodename" "Status" "Port" "Days"
echo "$SSEP" echo "$SSEP"
@@ -1066,28 +1066,30 @@ rsync_sync_file() {
# ====================== 帮助文档 ====================== # ====================== 帮助文档 ======================
show_help() { show_help() {
cat <<EOF cat <<EOF
SunHPC 命令行工具 SunHPC command tools
Usage: sunhpc <COMMAND> [OPTIONS] Usage: sunhpc <COMMAND> [OPTIONS]
公共参数: Public Args:
-v, --verbose 详细输出 -v, --verbose Verbose output
-d, --debug 调试模式 -d, --debug Debug Mode
-h, --help 帮助信息 -h, --help Display the help infomation
-n, --nodes <list> 指定节点(all node1,node2,node3 -n, --nodes <list> Specified node (all or node1,node2,node3)
支持命令: Support commands:
sunhpc pxe http 部署http服务 sunhpc exec Batch execute command
sunhpc pxe dnsmasq 部署pxe服务
sunhpc exec 批量执行命令
sunhpc init Execute the init op sunhpc init Execute the init op
sunhpc sync file 执行同步任务 sunhpc sync file Run the synchronize file command
sunhpc list node 查看节点列表
sunhpc show vimrc 显示Vimrc变量 sunhpc show nodes Display nodes list
sunhpc show system 显示系统信息 sunhpc show vimrc Dispaly Vimrc config
sunhpc serv slurm 构建 slurm 服务 sunhpc show system Display the system infomation
sunhpc serv autofs 构建 autofs 服务
sunhpc create syncfile 显示系统信息 sunhpc build httpd Build httpd server
sunhpc build slurm Build slurm server
sunhpc build autofs Build autofs server
sunhpc build dnsmasq Build dnsmasq server
sunhpc create syncfile Display the help infomation
Report bugs to: <support@sunhpc.com> Report bugs to: <support@sunhpc.com>
Htool URL: https://gitea.sunhpc.com Htool URL: https://gitea.sunhpc.com
@@ -1097,19 +1099,19 @@ EOF
show_help_sync() { show_help_sync() {
cat <<EOF cat <<EOF
SunHPC 命令行工具 SunHPC command tools
Usage: sunhpc <COMMAND> [OPTIONS] Usage: sunhpc <COMMAND> [OPTIONS]
公共参数: Public Args:
-v, --verbose 详细输出 -v, --verbose Verbose output
-d, --debug 调试模式 -d, --debug Debug Mode
-h, --help 帮助信息 -h, --help Display the help infomation
-n, --nodes <list> 指定节点(all node1,node2,node3 -n, --nodes <list> Specified node (all or node1,node2,node3)
命令示例: Command Example:
sunhpc sync file -f/--file <filepath> 同步单个文件 sunhpc sync file -f/--file <filepath> Sync a single file
sunhpc sync file -a/--all 同步所有文件 sunhpc sync file -a/--all Sync all files
Report bugs to: <support@sunhpc.com> Report bugs to: <support@sunhpc.com>
Htool URL: https://gitea.sunhpc.com Htool URL: https://gitea.sunhpc.com
@@ -1119,20 +1121,20 @@ EOF
show_help_slurm() { show_help_slurm() {
cat <<EOF cat <<EOF
SunHPC 命令行工具 SunHPC command tools
Usage: sunhpc <COMMAND> [OPTIONS] Usage: sunhpc <COMMAND> [OPTIONS]
公共参数: Public Args:
-v, --verbose 详细输出 -v, --verbose Verbose output
-d, --debug 调试模式 -d, --debug Debug Mode
-h, --help 帮助信息 -h, --help Display the help infomation
-n, --nodes <list> 指定节点(all node1,node2,node3 -n, --nodes <list> Specified node (all or node1,node2,node3)
命令示例: Command Example:
sunhpc serv slurm -b/--build 构建Slurm安装包 sunhpc serv slurm -b/--build Build Slurm rpm packages
sunhpc serv slurm -i/--install -m/master 安装Slurm到管理节点 sunhpc serv slurm -i/--install -m/master Install Slurm to frontend
sunhpc serv slurm -i/--install -c/compute 安装Slurm到计算节点 sunhpc serv slurm -i/--install -c/compute Install Slurm to computes
Report bugs to: <support@sunhpc.com> Report bugs to: <support@sunhpc.com>
Htool URL: https://gitea.sunhpc.com Htool URL: https://gitea.sunhpc.com
@@ -1140,6 +1142,24 @@ Gitea URL: https://gitea.sunhpc.com/htool.git
EOF EOF
} }
show_vimrc() {
cat <<-EOF
" 开启语法高亮
syntax enable
" 设置缩进为4个空格
set tabstop=4
set softtabstop=4
set shiftwidth=4
" 用空格替代Tab键禁止输入真实Tab
set expandtab
" 自动缩进(写代码更方便)
set autoindent
set smartindent
EOF
}
# ====================== Verbose/Debug 输出工具 ====================== # ====================== Verbose/Debug 输出工具 ======================
log_info() { log_info() {
if [[ -n "${GLOBAL_OPTS[v]}" || -n "${GLOBAL_OPTS[verbose]}" ]]; then if [[ -n "${GLOBAL_OPTS[v]}" || -n "${GLOBAL_OPTS[verbose]}" ]]; then
@@ -1154,11 +1174,7 @@ log_debug() {
} }
# ====================== 子命令执行 ====================== # ====================== 子命令执行 ======================
run_pxe_http() { init_run() {
pxe_http_build
}
run_init() {
info "初次使用此工具,需要在当前目录创建一个配置文件." info "初次使用此工具,需要在当前目录创建一个配置文件."
info " 1、手动创建配置文件,e.g., touch $config_file" info " 1、手动创建配置文件,e.g., touch $config_file"
@@ -1172,7 +1188,9 @@ run_init() {
treeinfo=$(find -L $mntroot -name ".treeinfo") treeinfo=$(find -L $mntroot -name ".treeinfo")
parse_treeinfo $treeinfo parse_treeinfo $treeinfo
#for key in "${!global_treeinfo[@]}"; do echo "key: '$key', Value: '${global_treeinfo[$key]}'";done for key in "${!global_treeinfo[@]}"; do
log_debug "key: '$key', Value: '${global_treeinfo[$key]}'";
done
[[ -z "$treeinfo" ]] && warn "提供的 $mntroot 目录为空,或是不被支持的系统." [[ -z "$treeinfo" ]] && warn "提供的 $mntroot 目录为空,或是不被支持的系统."
@@ -1281,8 +1299,7 @@ run_init() {
sed -i "s|@ospath@|$url_os_path|" $pkgs_init sed -i "s|@ospath@|$url_os_path|" $pkgs_init
} }
run_exec() { exec_run() {
log_debug "--------- run_exec----------------"
log_debug "当前节点:${GLOBAL_NODES[*]}" log_debug "当前节点:${GLOBAL_NODES[*]}"
log_debug "公共参数:${PUBLIC_ARGS[*]}" log_debug "公共参数:${PUBLIC_ARGS[*]}"
log_debug "私有参数:${PRIVATE_ARGS[*]}" log_debug "私有参数:${PRIVATE_ARGS[*]}"
@@ -1316,71 +1333,20 @@ run_exec() {
echo "$SSEP" echo "$SSEP"
} }
run_sync() { sync_run() {
log_debug "--------- run_sync----------------"
log_debug "当前节点:${GLOBAL_NODES[*]}" log_debug "当前节点:${GLOBAL_NODES[*]}"
log_debug "公共参数:${PUBLIC_ARGS[*]}" log_debug "公共参数:${PUBLIC_ARGS[*]}"
log_debug "私有参数:${PRIVATE_ARGS[*]}" log_debug "私有参数:${PRIVATE_ARGS[*]}"
case "${PRIVATE_ARGS[@]}" in #case "${PRIVATE_ARGS[@]}" in
-a|--all) sync_file_all ;; case "${GLOBAL_OPTS[@]}" in
-f|--file) sync_file_single ;; all) echo 'all----->' ;;#sync_file_all ;;
*) show_help_sync ;; file) echo 'file---->' ;;#sync_file_single ;;
*) show_help_sync ;;
esac esac
} }
run_list_node() {
log_debug "--------- run_list_node----------------"
log_debug "当前节点:${GLOBAL_NODES[*]}"
log_debug "公共参数:${PUBLIC_ARGS[*]}"
log_debug "私有参数:${PRIVATE_ARGS[*]}"
log_info "执行 list node"
log_info "当前节点列表:${GLOBAL_NODES[*]}"
list_node
}
run_show_vimrc() {
cat <<-EOF
" 开启语法高亮
syntax enable
" 设置缩进为4个空格
set tabstop=4
set softtabstop=4
set shiftwidth=4
" 用空格替代Tab键禁止输入真实Tab
set expandtab
" 自动缩进(写代码更方便)
set autoindent
set smartindent
EOF
}
run_serv_slurm() {
log_debug "--------- run_serv_slurm------------------"
case "${PRIVATE_ARGS[@]}" in
-b|--build) slurm_build ;;
*) show_help_slurm ;;
esac
}
run_serv_autofs() {
log_debug "--------- run_serv_autofs----------------"
log_debug "当前节点:${GLOBAL_NODES[*]}"
log_debug "公共参数:${PUBLIC_ARGS[*]}"
log_debug "私有参数:${PRIVATE_ARGS[*]}"
log_info "执行 server autofs"
if [[ " ${PRIVATE_ARGS[@]} " =~ " --build " ]]; then
log_debug "检测到 --build 参数,开始构建..."
echo "✅ 正在构建 autofs 服务"
fi
}
create_sync_file() { create_sync_file() {
dirspath=( dirspath=(
"/etc/passwd" "/etc/passwd"
@@ -1407,7 +1373,7 @@ create_sync_file() {
fi fi
done done
for n in ${GLOBAL_NODES[@]}; do for n in "${GLOBAL_NODES[@]}"; do
mkdir -p "${base}/${name}/${n}" mkdir -p "${base}/${name}/${n}"
done done
@@ -1426,42 +1392,31 @@ dispatch() {
log_debug "专属参数 ${PRIVATE_ARGS[*]}" log_debug "专属参数 ${PRIVATE_ARGS[*]}"
case "${CMD_STACK[0]}" in case "${CMD_STACK[0]}" in
pxe) exec)
case "${CMD_STACK[1]}" in exec_run "${CMD_STACK[1]}"
http) run_pxe_http;;
dnsmasq) pxe_dnsmasq_build;;
*) show_help;;
esac
;; ;;
init) init)
run_init init_run "${CMD_STACK[1]}"
;;
exec)
run_exec "${CMD_STACK[1]}"
;; ;;
sync) sync)
case "${CMD_STACK[1]}" in case "${CMD_STACK[1]}" in
file) run_sync ;; file) sync_run ;;
*) show_help ;;
esac
;;
list)
case "${CMD_STACK[1]}" in
node) run_list_node ;;
*) show_help ;; *) show_help ;;
esac esac
;; ;;
show) show)
case "${CMD_STACK[1]}" in case "${CMD_STACK[1]}" in
vimrc) run_show_vimrc ;; node) show_nodes ;;
vimrc) show_vimrc ;;
system) show_system_summary ;; system) show_system_summary ;;
*) show_help;; *) show_help;;
esac esac
;; ;;
serv) build)
case "${CMD_STACK[1]}" in case "${CMD_STACK[1]}" in
slurm) run_serv_slurm ;; httpd) build_httpd_srv ;;
autofs) run_serv_autofs ;; slurm) build_slurm_srv ;;
dnsmasq) build_dnsmasq_srv ;;
*) show_help;; *) show_help;;
esac esac
;; ;;
@@ -1487,6 +1442,7 @@ parse_args() {
-m) GLOBAL_OPTS[mntroot]=$2; PUBLIC_ARGS+=("$arg" "$2"); shift 2 ;; -m) GLOBAL_OPTS[mntroot]=$2; PUBLIC_ARGS+=("$arg" "$2"); shift 2 ;;
-w) GLOBAL_OPTS[wwwroot]=$2; PUBLIC_ARGS+=("$arg" "$2"); shift 2 ;; -w) GLOBAL_OPTS[wwwroot]=$2; PUBLIC_ARGS+=("$arg" "$2"); shift 2 ;;
-f) GLOBAL_OPTS[file]=$2; PUBLIC_ARGS+=("$arg" "$2"); shift 2 ;; -f) GLOBAL_OPTS[file]=$2; PUBLIC_ARGS+=("$arg" "$2"); shift 2 ;;
-a) GLOBAL_OPTS[all]=$2; PUBLIC_ARGS+=("$arg" "$2"); shift 2 ;;
-i) GLOBAL_OPTS[interface]=$2; PUBLIC_ARGS+=("$arg" "$2"); shift 2 ;; -i) GLOBAL_OPTS[interface]=$2; PUBLIC_ARGS+=("$arg" "$2"); shift 2 ;;
-n) parse_nodes "$2"; PUBLIC_ARGS+=("$arg" "$2"); shift 2 ;; -n) parse_nodes "$2"; PUBLIC_ARGS+=("$arg" "$2"); shift 2 ;;
@@ -1497,6 +1453,7 @@ parse_args() {
--mntroot) GLOBAL_OPTS[mntroot]=$2; PUBLIC_ARGS+=("$arg" "$2"); shift 2 ;; --mntroot) GLOBAL_OPTS[mntroot]=$2; PUBLIC_ARGS+=("$arg" "$2"); shift 2 ;;
--wwwroot) GLOBAL_OPTS[wwwroot]=$2; PUBLIC_ARGS+=("$arg" "$2"); shift 2 ;; --wwwroot) GLOBAL_OPTS[wwwroot]=$2; PUBLIC_ARGS+=("$arg" "$2"); shift 2 ;;
--file) GLOBAL_OPTS[file]=$2; PUBLIC_ARGS+=("$arg" "$2"); shift 2 ;; --file) GLOBAL_OPTS[file]=$2; PUBLIC_ARGS+=("$arg" "$2"); shift 2 ;;
--all) GLOBAL_OPTS[all]=$2; PUBLIC_ARGS+=("$arg" "$2"); shift 2 ;;
--interface) GLOBAL_OPTS[interface]=$2; PUBLIC_ARGS+=("$arg" "$2"); shift 2 ;; --interface) GLOBAL_OPTS[interface]=$2; PUBLIC_ARGS+=("$arg" "$2"); shift 2 ;;
--nodes) parse_nodes "$2"; PUBLIC_ARGS+=("$arg" "$2"); shift 2 ;; --nodes) parse_nodes "$2"; PUBLIC_ARGS+=("$arg" "$2"); shift 2 ;;