1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
#!/sbin/sh
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T.
# All rights reserved.
#
#
# Copyright 2006 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
# 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
#
# 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
# in the local /etc/inet/hosts file pairing "unknown" with the IP
# address assigned by DHCP. The use of bootparams as a fallback
# for all non-DHCP cases provides compatibility with the
# behavior of the system before netstrategy was introduced.
#
# For non-global zones, fall back to the `uname -n` value provided by the
# 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 ;;
# /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" ] || [ "$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
# 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
exit $SMF_EXIT_OK
|