diff options
Diffstat (limited to 'usr/src/cmd/svc/milestone/identity-node')
-rw-r--r-- | usr/src/cmd/svc/milestone/identity-node | 150 |
1 files changed, 121 insertions, 29 deletions
diff --git a/usr/src/cmd/svc/milestone/identity-node b/usr/src/cmd/svc/milestone/identity-node index c9b20ba669..6b740f3dd1 100644 --- a/usr/src/cmd/svc/milestone/identity-node +++ b/usr/src/cmd/svc/milestone/identity-node @@ -27,18 +27,30 @@ # Copyright 2006 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # -# ident "%Z%%M% %I% %E% SMI" +# Copyright 2019 Joyent, Inc. +# . /lib/svc/share/smf_include.sh . /lib/svc/share/net_include.sh +set -o xtrace + # Make sure that the libraries essential to this stage of booting can be found. LD_LIBRARY_PATH=/lib; export LD_LIBRARY_PATH # -# If DHCP was used on a primary interface then set the hostname -# that was returned. If no hostname was returned, set the name -# to be "unknown". The hostname must be set to something, because +# For the GZ, use one of the following values for hostname, in order: +# * DHCP hostname (if set on a primary interface) +# * hostname value from config file +# * hostname bootparam +# * if not a headnode: +# * admin MAC address +# * any other MAC address +# +# If none of the above could be found, default to "headnode" for headnodes, and +# "unknown" for non-headnodes. +# +# The hostname must be set to something, because # tooltalk will hang unless the name can be locally resolved. # Sendmail also requires the name to be resolvable locally. # Later, in inetsvc, we create a name "unknown" and create a entry @@ -51,44 +63,124 @@ LD_LIBRARY_PATH=/lib; export LD_LIBRARY_PATH # kernel if /etc/nodename does not exist, as is expected on an initial boot. # +set_gz_hostname() { + hostname=${CONFIG_hostname} + if [ -z "$hostname" ] || [ "$hostname" == "unknown" ]; then + hostname=$SYSINFO_Bootparam_hostname + fi + + if [ -n "$hostname" ] && [ "$hostname" != "unknown" ]; then + return + fi + + # $headnode is set by load_sdc_config() + if [ "$headnode" == "true" ]; then + hostname="headnode" + return + fi + + if [[ -n ${SYSINFO_NIC_admin} ]]; then + eval "admin_mac=\${SYSINFO_Network_Interface_${SYSINFO_NIC_admin}_MAC_Address}" + if [[ -n ${admin_mac} ]]; then + hostname=$(echo "${admin_mac}" | tr ':' '-') + return + fi + fi + + fallback_mac=$(set | grep "^SYSINFO_Network_Interface_.*_MAC_Address" | head -n1 | cut -d'=' -f2) + if [[ -n ${fallback_mac} ]]; then + hostname=$(echo "${fallback_mac}" | tr ':' '-') + return + fi + + hostname="unknown" +} + + smf_netstrategy case "$_INIT_NET_STRATEGY" in - "dhcp") hostname=`/sbin/dhcpinfo Hostname` ;; - "rarp") hostname=`/sbin/hostconfig -h -p bootparams` - trap 'intr=1' 2 3 - while [ -z "$hostname" -a ! -f /etc/.UNCONFIGURED -a \ - -z "$intr" ]; do - echo "re-trying host configuration..." - # Restrict this to IPv4 interfaces. - /sbin/ifconfig -adD4 auto-revarp up - hostname=`/sbin/hostconfig -h -p bootparams` - done - trap 2 3 ;; - "none") hostname="`shcat /etc/nodename 2>/dev/null`" - if [ -z "$hostname" ]; then - if smf_is_globalzone; then - hostname=`/sbin/hostconfig -h -p bootparams` - else - hostname=`/sbin/uname -n` - fi - fi ;; + "dhcp") hostname=`/sbin/dhcpinfo Hostname` ;; + "rarp") hostname=`/sbin/hostconfig -h -p bootparams` + trap 'intr=1' 2 3 + while [ -z "$hostname" -a ! -f /etc/.UNCONFIGURED -a \ + -z "$intr" ]; do + echo "re-trying host configuration..." + # Restrict this to IPv4 interfaces. + /sbin/ifconfig -adD4 auto-revarp up + hostname=`/sbin/hostconfig -h -p bootparams` + done + trap 2 3 ;; + # /etc/nodename defaults to "unknown" on SmartOS + "none") hostname="`shcat /etc/nodename 2>/dev/null`" + if [ -z "$hostname" ]; then + if smf_is_globalzone; then + hostname=`/sbin/hostconfig -h -p bootparams` + else + hostname=`/sbin/uname -n` + fi + fi ;; esac +# Load sysinfo variables with SYSINFO_ prefix and config variables with +# CONFIG_ prefix. +# Note: since we're still starting up, "soft" values like network IP and such could +# not be set yet. + +if smf_is_globalzone; then + . /lib/sdc/config.sh + + load_sdc_sysinfo + + if boot_file_config_enabled; then + load_boot_file_config + else + load_sdc_config + fi +fi + # # If the netstrategy was unsuccessful and we haven't got a locally configured # name, default to "unknown" # -if [ -z "$hostname" ]; then - hostname="`shcat /etc/nodename 2>/dev/null`" - if [ -z "$hostname" ]; then - hostname="unknown" - fi +if [ -z "$hostname" ] || [ "$hostname" == "unknown" ]; then + hostname="`shcat /etc/nodename 2>/dev/null`" + if [ -z "$hostname" ] || [ "$hostname" == "unknown" ]; then + if smf_is_globalzone; then + set_gz_hostname + else + hostname="unknown" + fi + fi +fi + +if smf_is_globalzone; then + echo "$hostname" > /etc/nodename fi /sbin/uname -S $hostname -echo "Hostname: `/sbin/uname -n`" > /dev/msglog +# Reloading sysinfo here serves two purposes: +# - getting the IP info (which should exist now) +# - updating the host info (which we just set) +eval $(/usr/bin/sysinfo -f -p | sed -e "s/^/SYSINFO_/") + +# Try to add the /etc/hosts entry if we can find an IP +if [[ -n ${SYSINFO_NIC_admin} ]]; then + eval "ipaddr=\${SYSINFO_Network_Interface_${SYSINFO_NIC_admin}_IPv4_Address}" +fi +if [[ -z ${ipaddr} ]]; then + ipaddr=$(set | grep "^SYSINFO_Network_Interface_.*_IPv4_Address" | head -n1 | cut -d'=' -f2) +fi +if [[ -n ${ipaddr} ]]; then + fullname="" + + if [ -n "$CONFIG_dns_domain" ]; then + fullname=" ${hostname}.${CONFIG_dns_domain}" + fi + + printf "${ipaddr}\t${hostname}${fullname}\n" >> /etc/hosts +fi # Reset the library path now that we are past the critical stage unset LD_LIBRARY_PATH |