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