Commit c84e5170 authored by one's avatar one
Browse files

[rocHPL] Improve robustness for resolve_ip

parent 01be5357
......@@ -12,6 +12,7 @@ WORKSPACE_DIR="${PWD}" # 修改为主节点的rocHPL目录
# 2. 第一列是物理机hostname或IP,第二列是docker容器hostname
# =====================================================================
MASTER_NODE=$(hostname)
DOCKER_MASTER=node01
WORKER_CONFIG="
node2 node02
node3 node03
......@@ -27,12 +28,12 @@ resolve_ip() {
# Try getent
if command -v getent >/dev/null 2>&1; then
ip=$(getent ahosts "$target" 2>/dev/null | awk '{print $1}' | head -n 1)
ip=$(getent ahosts "$target" 2>/dev/null | awk '{print $1}' | head -n 1 || true)
fi
# Try ping
if [ -z "$ip" ] && command -v ping >/dev/null 2>&1; then
ip=$(ping -c 1 -n "$target" 2>/dev/null | awk -F'[()]' '/PING/{print $2}')
ip=$(ping -c 1 -n "$target" 2>/dev/null | awk -F'[()]' '/PING/{print $2}' || true)
fi
# Fallback to /etc/hosts
......@@ -44,8 +45,8 @@ resolve_ip() {
}
MASTER_IP=$(resolve_ip ${MASTER_NODE})
DOCKER_ADD_HOSTS="--add-host node01:${MASTER_IP}"
echo "Master node: ${MASTER_NODE} -> node01 (${MASTER_IP})"
DOCKER_ADD_HOSTS="--add-host ${DOCKER_MASTER}:${MASTER_IP}"
echo "Master node: ${MASTER_NODE} -> ${DOCKER_MASTER} (${MASTER_IP})"
WORKER_NODE_ARR=()
while read -r phys_host std_name rest; do
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment