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