Print this page
    
NEX-16134 HostName change using API is not persistent through a reboot
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
Reviewed by: Rick McNeal <rick.mcneal@nexenta.com>
Reviewed by: Rob Gittins <rob.gittins@nexenta.com>
    
      
        | Split | 
	Close | 
      
      | Expand all | 
      | Collapse all | 
    
    
          --- old/usr/src/cmd/svc/milestone/identity-node
          +++ new/usr/src/cmd/svc/milestone/identity-node
   1    1  #!/sbin/sh
   2    2  #
   3    3  # CDDL HEADER START
   4    4  #
   5    5  # The contents of this file are subject to the terms of the
   6    6  # Common Development and Distribution License (the "License").
   7    7  # You may not use this file except in compliance with the License.
   8    8  #
   9    9  # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  10   10  # or http://www.opensolaris.org/os/licensing.
  11   11  # See the License for the specific language governing permissions
  12   12  # and limitations under the License.
  13   13  #
  14   14  # When distributing Covered Code, include this CDDL HEADER in each
  15   15  # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16   16  # If applicable, add the following below this CDDL HEADER, with the
  17   17  # fields enclosed by brackets "[]" replaced with your own identifying
  18   18  # information: Portions Copyright [yyyy] [name of copyright owner]
  19   19  #
  
    | 
      ↓ open down ↓ | 
    19 lines elided | 
    
      ↑ open up ↑ | 
  
  20   20  # CDDL HEADER END
  21   21  #
  22   22  #
  23   23  # Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T.
  24   24  # All rights reserved.
  25   25  #
  26   26  #
  27   27  # Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
  28   28  # Use is subject to license terms.
  29   29  #
  30      -# ident "%Z%%M% %I%     %E% SMI"
       30 +# Copyright 2018 Nexenta Systems Inc. 
  31   31  
  32   32  . /lib/svc/share/smf_include.sh
  33   33  . /lib/svc/share/net_include.sh
  34   34  
  35   35  # Make sure that the libraries essential to this stage of booting can be found.
  36   36  LD_LIBRARY_PATH=/lib; export LD_LIBRARY_PATH
  37   37  
  38   38  #
  39   39  # If DHCP was used on a primary interface then set the hostname
  40   40  # that was returned. If no hostname was returned, set the name
  41   41  # to be "unknown". The hostname must be set to something, because
  42   42  # tooltalk will hang unless the name can be locally resolved.
  43   43  # Sendmail also requires the name to be resolvable locally.
  44   44  # Later, in inetsvc, we create a name "unknown" and create a entry
  45   45  # in the local /etc/inet/hosts file pairing "unknown" with the IP
  46   46  # address assigned by DHCP.  The use of bootparams as a fallback
  
    | 
      ↓ open down ↓ | 
    6 lines elided | 
    
      ↑ open up ↑ | 
  
  47   47  # for all non-DHCP cases provides compatibility with the
  48   48  # behavior of the system before netstrategy was introduced.
  49   49  #
  50   50  # For non-global zones, fall back to the `uname -n` value provided by the
  51   51  # kernel if /etc/nodename does not exist, as is expected on an initial boot.
  52   52  #
  53   53  
  54   54  smf_netstrategy
  55   55  
  56   56  case "$_INIT_NET_STRATEGY" in
  57      -        "dhcp") hostname=`/sbin/dhcpinfo Hostname` ;;
       57 +        "dhcp") if [ -s /etc/nodename ]; then
       58 +                        hostname=`shcat /etc/nodename 2>/dev/null`
       59 +                else
       60 +                        hostname=`/sbin/dhcpinfo Hostname`
       61 +                fi
       62 +                        ;;
  58   63          "rarp") hostname=`/sbin/hostconfig -h -p bootparams`
  59   64                  trap 'intr=1' 2 3
  60   65                  while [ -z "$hostname" -a ! -f /etc/.UNCONFIGURED -a \
  61   66                      -z "$intr" ]; do
  62   67                          echo "re-trying host configuration..."
  63   68                          # Restrict this to IPv4 interfaces.
  64   69                          /sbin/ifconfig -adD4 auto-revarp up
  65   70                          hostname=`/sbin/hostconfig -h -p bootparams`
  66   71                  done
  67   72                  trap 2 3 ;;
  68   73          "none") hostname="`shcat /etc/nodename 2>/dev/null`"
  69   74                  if [ -z "$hostname" ]; then
  70   75                          if smf_is_globalzone; then
  71   76                                  hostname=`/sbin/hostconfig -h -p bootparams`
  72   77                          else
  73   78                                  hostname=`/sbin/uname -n`
  74   79                          fi
  75   80                  fi ;;
  76   81  esac
  77   82  
  78   83  #
  79   84  # If the netstrategy was unsuccessful and we haven't got a locally configured
  80   85  # name, default to "unknown"
  81   86  #
  82   87  if [ -z "$hostname" ]; then
  83   88          hostname="`shcat /etc/nodename 2>/dev/null`"
  84   89          if [ -z "$hostname" ]; then
  85   90                  hostname="unknown"
  86   91          fi
  87   92  fi
  88   93  
  89   94  /sbin/uname -S $hostname
  90   95  
  91   96  echo "Hostname: `/sbin/uname -n`" > /dev/msglog
  92   97  
  93   98  # Reset the library path now that we are past the critical stage
  94   99  unset LD_LIBRARY_PATH
  95  100  
  96  101  exit $SMF_EXIT_OK
  
    | 
      ↓ open down ↓ | 
    29 lines elided | 
    
      ↑ open up ↑ | 
  
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX