fix sunhpc

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

209
sunhpc
View File

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