diff --git a/templates/common/baremetal/files/NetworkManager-mdns-hostname.yaml b/templates/common/baremetal/files/NetworkManager-mdns-hostname.yaml new file mode 100644 index 0000000000..cd3219a97c --- /dev/null +++ b/templates/common/baremetal/files/NetworkManager-mdns-hostname.yaml @@ -0,0 +1,22 @@ +filesystem: "root" +mode: 0755 +path: "/etc/NetworkManager/dispatcher.d/40-mdns-hostname" +contents: + inline: | + #!/bin/bash + STATUS=$2 + case "$STATUS" in + up|down|dhcp4-change|dhcp6-change|hostname) + logger -s "NM mdns-hostname triggered by ${2}." + set +e + t_hostname=$(hostname) + if [ -z "${t_hostname}" ]; then + t_hostname="localhost" + fi + mkdir -p /etc/mdns + echo "${t_hostname}">/etc/mdns/hostname + logger -s "Hostname changed: ${t_hostname}" + ;; + *) + ;; + esac diff --git a/templates/common/baremetal/files/baremetal-mdns-publisher.yaml b/templates/common/baremetal/files/baremetal-mdns-publisher.yaml index a3ec0eaa41..217cb35ceb 100644 --- a/templates/common/baremetal/files/baremetal-mdns-publisher.yaml +++ b/templates/common/baremetal/files/baremetal-mdns-publisher.yaml @@ -29,18 +29,35 @@ contents: env: - name: DEFAULT_LOCAL_HOSTNAME value: "localhost" + - name: RUNTIMECFG_HOSTNAME_PATH + value: "/etc/mdns/hostname" command: - "/bin/bash" - "-c" - | #/bin/bash - while [ "$(hostname)" == "$DEFAULT_LOCAL_HOSTNAME" ] + function get_hostname() + { + if [[ -s $RUNTIMECFG_HOSTNAME_PATH ]]; then + cat $RUNTIMECFG_HOSTNAME_PATH + else + # if hostname wasn't updated by NM script, read hostname + hostname + fi + } + while [ "$(get_hostname)" == "$DEFAULT_LOCAL_HOSTNAME" ] do echo "hostname is still ${DEFAULT_LOCAL_HOSTNAME}" - sleep 10 + sleep 1 done + volumeMounts: + - name: conf-dir + mountPath: "/etc/mdns" - name: render-config image: {{ .Images.baremetalRuntimeCfgImage }} + env: + - name: RUNTIMECFG_HOSTNAME_PATH + value: "/etc/mdns/hostname" command: - runtimecfg - render