xref: /titanic_52/usr/src/cmd/initpkg/rcS.sh (revision 06e46062ef4f5f4b687cbafb4518fb123fe23920)
1#!/sbin/sh
2#
3# CDDL HEADER START
4#
5# The contents of this file are subject to the terms of the
6# Common Development and Distribution License, Version 1.0 only
7# (the "License").  You may not use this file except in compliance
8# with the License.
9#
10# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11# or http://www.opensolaris.org/os/licensing.
12# See the License for the specific language governing permissions
13# and limitations under the License.
14#
15# When distributing Covered Code, include this CDDL HEADER in each
16# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17# If applicable, add the following below this CDDL HEADER, with the
18# fields enclosed by brackets "[]" replaced with your own identifying
19# information: Portions Copyright [yyyy] [name of copyright owner]
20#
21# CDDL HEADER END
22#
23#
24# Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26#
27# ident	"%Z%%M%	%I%	%E% SMI"
28#
29# Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T.
30# All rights reserved.
31#
32#
33
34# This file executes the commands in the rcS.d directory, which are necessary
35# to get the system to single user mode:
36#
37# 	establish minimal network plumbing (for diskless and dataless)
38#	mount /usr (if a separate file system)
39#	set the system name
40#	check the root (/) and /usr file systems
41#	check and mount /var and /var/adm (if a separate file system)
42#	mount pseudo file systems (/dev/fd)
43#	if this is a reconfiguration boot, [re]build the device entries
44#	check and mount other file systems to be mounted in single user mode
45
46if [ -z "$SMF_RESTARTER" ]; then
47	echo "Cannot be run outside smf(5)"
48	exit 1
49fi
50
51. /lib/svc/share/smf_include.sh
52
53#
54# Default definitions:
55#
56PATH=/usr/sbin:/usr/bin:/sbin
57vfstab=/etc/vfstab
58mnttab=/etc/mnttab
59mntlist=
60option=
61otherops=
62
63action=$1
64
65# Export boot parameters to rc scripts
66
67if [ "x$1" != xsysinit -a -d /usr/bin ]; then
68	set -- `/usr/bin/who -r`
69
70	_INIT_RUN_LEVEL=${7:-S}   # Current run-level
71	_INIT_RUN_NPREV=${8:-0}   # Number of times previously at current level
72	_INIT_PREV_LEVEL=${9:-0}  # Previous run-level
73else
74	_INIT_RUN_LEVEL=S
75	_INIT_RUN_NPREV=0
76	_INIT_PREV_LEVEL=0
77fi
78
79set -- `/sbin/uname -a`
80
81#
82# If we're booting, uname -a will produce one fewer token than usual because
83# the hostname has not yet been configured.  Leave NODENAME empty in this case.
84#
85if [ $# -eq 7 ]; then
86	_INIT_UTS_SYSNAME="$1"  # Operating system name (uname -s)
87	_INIT_UTS_NODENAME="$2" # Node name (uname -n)
88	shift 2
89else
90	_INIT_UTS_SYSNAME="$1"  # Operating system name (uname -s)
91	_INIT_UTS_NODENAME=	# Node name is not yet configured
92	shift 1
93fi
94
95_INIT_UTS_RELEASE="$1"  # Operating system release (uname -r)
96_INIT_UTS_VERSION="$2"  # Operating system version (uname -v)
97_INIT_UTS_MACHINE="$3"  # Machine class (uname -m)
98_INIT_UTS_ISA="$4"      # Instruction set architecture (uname -p)
99_INIT_UTS_PLATFORM="$5" # Platform string (uname -i)
100
101export _INIT_RUN_LEVEL _INIT_RUN_NPREV _INIT_PREV_LEVEL \
102    _INIT_UTS_SYSNAME _INIT_UTS_NODENAME _INIT_UTS_RELEASE _INIT_UTS_VERSION \
103    _INIT_UTS_MACHINE _INIT_UTS_ISA _INIT_UTS_PLATFORM
104
105_INIT_ZONENAME=`/sbin/zonename`
106
107export _INIT_ZONENAME
108
109if [ "$_INIT_ZONENAME" = "global" ]; then
110	# Export net boot configuration strategy. _INIT_NET_IF is set to the
111	# interface name of the netbooted interface if this is a net boot.
112	# _INIT_NET_STRATEGY is set to the network configuration strategy.
113	set -- `/sbin/netstrategy`
114	if [ $? -eq 0 ]; then
115		if [ "$1" = "nfs" -o "$1" = "cachefs" ]; then
116			_INIT_NET_IF="$2"
117			export _INIT_NET_IF
118		fi
119		_INIT_NET_STRATEGY="$3"
120	fi
121else
122	# Special case for zones since netstrategy needs /dev/ip which does
123	# not exist in a non-global zone.  Also, the _IF variable is only
124	# consumed in the global zone.
125	_INIT_NET_STRATEGY="none"
126fi
127export _INIT_NET_STRATEGY
128
129#
130# Useful shell functions:
131#
132
133#
134#	shcat file
135#
136# Simulates cat in sh so it doesn't need to be on the root filesystem.
137#
138shcat() {
139	while [ $# -ge 1 ]; do
140		while read i; do
141                        echo "$i"
142		done < $1
143		shift
144	done
145}
146
147. /lib/svc/share/fs_include.sh
148
149#
150# Make the old, deprecated environment variable (_DVFS_RECONFIG) and the new
151# supported environment variable (_INIT_RECONFIG) to be synonyms.  Set both
152# if the svc.startd reconfigure property is set.  Note that for complete
153# backwards compatibility the value "YES" is significant with _DVFS_RECONFIG.
154# The # value associated with _INIT_RECONFIG is insignificant.  What is
155# significant is only that the environment variable is defined.
156#
157
158svcprop -q -p system/reconfigure system/svc/restarter:default
159if [ $? -eq 0 ]
160then
161	echo "Setting _INIT_RECONFIG."
162	_DVFS_RECONFIG=YES; export _DVFS_RECONFIG
163	_INIT_RECONFIG=set; export _INIT_RECONFIG
164fi
165
166
167case $action in
168	stop)
169		>/etc/nologin
170
171		# All remote filesystem services must be explicitly disabled
172		# at the single-user milestone.  There's no need to unmount
173		# remote filesystems here.
174
175		if [ -d /etc/rcS.d ]; then
176			for f in /etc/rcS.d/K*; do
177				if [ ! -s $f ]; then
178					continue
179				fi
180
181				case $f in
182					*.sh)	/lib/svc/bin/lsvcrun -s $f stop
183						;;
184					*)	/lib/svc/bin/lsvcrun $f stop ;;
185				esac
186			done
187		fi
188
189		;;
190
191	start)
192		if [ -d /etc/rcS.d ]; then
193			for f in /etc/rcS.d/S*; do
194				if [ ! -s $f ]; then
195					continue
196				fi
197
198				case $f in
199					*.sh)	/lib/svc/bin/lsvcrun -s $f start
200						;;
201					*)	/lib/svc/bin/lsvcrun $f start ;;
202				esac
203			done
204		fi
205
206		#
207		# Clean up the /reconfigure file and sync the new entries to
208		# stable media.
209		#
210
211		# GLXXX - svc.startd should do this?
212		if [ -n "$_INIT_RECONFIG" ]; then
213			[ -f /reconfigure  ] && /usr/bin/rm -f /reconfigure
214			/sbin/sync
215		fi
216		;;
217
218	*)
219		echo "Usage: $0 { start | stop }"
220		exit $SMF_EXIT_ERR_CONFIG
221		;;
222esac
223
224exit $SMF_EXIT_OK
225