Skip to content
This repository has been archived by the owner on May 17, 2018. It is now read-only.

Setting a persistent hostname and domainname should be in the base OS. #15

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions lib/svc/manifest/network/persistence.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?xml version="1.0"?>
<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">
<!--
Copyright 2012 Every Ware Ltd. All rights reserved.
-->

<service_bundle type='manifest' name='SUNWcsr:network-persistence'>

<service
name='system/network-persistence'
type='service'
version='1'>

<dependency
name='loopback-network'
grouping='require_any'
restart_on='none'
type='service'>
<service_fmri value='svc:/network/loopback' />
</dependency>

<dependency
name='physical-network'
grouping='optional_all'
restart_on='none'
type='service'>
<service_fmri value='svc:/network/physical' />
</dependency>

<dependency
name='fs'
grouping='require_all'
restart_on='none'
type='service'>
<service_fmri value='svc:/system/filesystem/smartdc' />
</dependency>

<exec_method
type='method'
name='stop'
exec=':true'
timeout_seconds='60' />

<property_group name='startd' type='framework'>
<propval name='duration' type='astring' value='transient' />
</property_group>

<instance name='ipnat' enabled='true'>

<exec_method
type='method'
name='start'
exec='/lib/svc/method/persist-ipnat'
timeout_seconds='60' />

</instance>

<instance name='static_routes' enabled='true'>

<exec_method
type='method'
name='start'
exec='/lib/svc/method/persist-static_routes'
timeout_seconds='60' />

</instance>

<stability value='Unstable' />

</service>

</service_bundle>
59 changes: 59 additions & 0 deletions lib/svc/method/identity-domain
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/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 2009 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#

. /lib/svc/share/smf_include.sh

#
# Configure a defaultdomain, if one is set in the config file
#
if smf_is_globalzone && ( [ -n "$(bootparams | grep '^headnode=true')" ] || [ -n "$(bootparams | grep '^smartos=true')" ] ) ; then
configfile="$(svcprop -p 'joyentfs/usb_copy_path' svc:/system/filesystem/smartdc:default)/config"
if [[ ! -f ${configfile} ]]; then
configfile="$(svcprop -p 'joyentfs/usb_mountpoint' svc:/system/filesystem/smartdc:default)/config"
fi
defaultdomain=$(grep '^defaultdomain=' ${configfile} | cut -d'=' -f2-)
if [[ -n ${defaultdomain} ]]; then
printf "${defaultdomain}\n" >/etc/defaultdomain
fi
fi


#
# Set LDAP/NIS domainname if locally configured.
#
if [ -f /etc/defaultdomain ]; then
mydomain=`cat /etc/defaultdomain`
/usr/bin/domainname $mydomain
name_service=""
[ -f /var/ldap/ldap_client_file ] && name_service="LDAP "
[ -d /var/yp/binding/$mydomain ] && name_service="${name_service}NIS "
[ -n "$name_service" ] && \
echo "${name_service}domain name is $mydomain" | smf_console
else
echo "/etc/defaultdomain absent: no domain name set"
fi

exit $SMF_EXIT_OK
150 changes: 150 additions & 0 deletions lib/svc/method/identity-node
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
#!/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.
#

. /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
# 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.
#

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 ;;
esac

# Load sysinfo variables with SYSINFO_ 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
eval $(/usr/bin/sysinfo -p | sed -e "s/^/SYSINFO_/")
if [[ -n ${SYSINFO_NIC_admin} ]]; then
eval "admin_mac=\${SYSINFO_Network_Interface_${SYSINFO_NIC_admin}_MAC_Address}"
fi
if [[ -z ${admin_mac} ]]; then
fallback_mac=$(set | grep "^SYSINFO_Network_Interface_.*_MAC_Address" | head -n1 | cut -d'=' -f2)
fi

if [[ -z $hostname ]]; then
hostname=$SYSINFO_Bootparam_hostname
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
configfile="$(svcprop -p 'joyentfs/usb_copy_path' svc:/system/filesystem/smartdc:default)/config"
if [[ ! -f ${configfile} ]]; then
configfile="$(svcprop -p 'joyentfs/usb_mountpoint' svc:/system/filesystem/smartdc:default)/config"
fi
hostname=$(grep '^hostname=' ${configfile} | cut -d'=' -f2-)
if [ -n "$(bootparams | grep '^headnode=true')" ] && [[ -z ${hostname} ]]; then
hostname="headnode"
elif [[ -z ${hostname} ]]; then
# take admin nic as hostname
if [[ -n ${admin_mac} ]]; then
hostname=$(echo "${admin_mac}" | tr ':' '-')
elif [[ -n ${fallback_mac} ]]; then
hostname=$(echo "${fallback_mac}" | tr ':' '-')
else
hostname="unknown"
fi
fi
else
hostname="unknown"
fi
fi
fi

/sbin/uname -S $hostname
printf "${hostname}\n" >/etc/nodename

# 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
printf "${ipaddr}\t${hostname}\n" >> /etc/hosts
fi

# Reset the library path now that we are past the critical stage
unset LD_LIBRARY_PATH

exit $SMF_EXIT_OK
41 changes: 41 additions & 0 deletions lib/svc/method/persist-ipnat
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License, Version 1.0 only
# (the "License"). You may not use this file except in compliance
# with the License.
#
# You can obtain a copy of the license at COPYING
# 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 COPYING.
# 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) 2010,2011 Joyent Inc.
# Portions Copyright 2012 Every Ware Ltd.

set -o xtrace

. /lib/svc/share/smf_include.sh
. /lib/sdc/config.sh

# first of all, if we aren't the global zone this doesn't make any sense to run

smf_is_globalzone || exit $SMF_EXIT_OK

if [ -f "${CONFIG_config_inc_dir}/ipnat.conf" ] ; then
svccfg -s svc:/network/ipfilter:default setprop \
config/ipnat_config_file=${CONFIG_config_inc_dir}/ipnat.conf
svccfg -s svc:/network/ipfilter:default refresh
fi

exit $SMF_EXIT_OK

47 changes: 47 additions & 0 deletions lib/svc/method/persist-static_routes
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/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) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
# Portions Copyright 2012 Every Ware Ltd.

# This script configures IP routing.

. /lib/svc/share/smf_include.sh
. /lib/sdc/config.sh

#
# Only run in the global zone, because otherwise the config is persistent.
#
smf_is_globalzone || exit $SMF_EXIT_OK

#
# Read /usbkey/config.inc/static_routes and add each route.
#
if [ -f "${CONFIG_config_inc_dir}/static_routes" ]; then
echo "Adding persistent routes:"
/usr/bin/egrep -v "^(#|$)" "${CONFIG_config_inc_dir}/static_routes" | while read line; do
/usr/sbin/route add $line
done
fi

# Clear exit status.
exit $SMF_EXIT_OK