xref: /illumos-gate/usr/src/cmd/initpkg/rcS.sh (revision bbf21555)
17c478bd9Sstevel@tonic-gate#!/sbin/sh
27c478bd9Sstevel@tonic-gate#
37c478bd9Sstevel@tonic-gate# CDDL HEADER START
47c478bd9Sstevel@tonic-gate#
57c478bd9Sstevel@tonic-gate# The contents of this file are subject to the terms of the
66927f468Sdp# Common Development and Distribution License (the "License").
76927f468Sdp# You may not use this file except in compliance with the License.
87c478bd9Sstevel@tonic-gate#
97c478bd9Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate# See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate# and limitations under the License.
137c478bd9Sstevel@tonic-gate#
147c478bd9Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate#
207c478bd9Sstevel@tonic-gate# CDDL HEADER END
217c478bd9Sstevel@tonic-gate#
227c478bd9Sstevel@tonic-gate#
236927f468Sdp# Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate# Use is subject to license terms.
257c478bd9Sstevel@tonic-gate#
26*bbf21555SRichard Lowe
277c478bd9Sstevel@tonic-gate#
287c478bd9Sstevel@tonic-gate# Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T.
297c478bd9Sstevel@tonic-gate# All rights reserved.
307c478bd9Sstevel@tonic-gate#
317c478bd9Sstevel@tonic-gate#
327c478bd9Sstevel@tonic-gate
337c478bd9Sstevel@tonic-gate# This file executes the commands in the rcS.d directory, which are necessary
347c478bd9Sstevel@tonic-gate# to get the system to single user mode:
357c478bd9Sstevel@tonic-gate#
367c478bd9Sstevel@tonic-gate# 	establish minimal network plumbing (for diskless and dataless)
377c478bd9Sstevel@tonic-gate#	mount /usr (if a separate file system)
387c478bd9Sstevel@tonic-gate#	set the system name
397c478bd9Sstevel@tonic-gate#	check the root (/) and /usr file systems
407c478bd9Sstevel@tonic-gate#	check and mount /var and /var/adm (if a separate file system)
417c478bd9Sstevel@tonic-gate#	mount pseudo file systems (/dev/fd)
427c478bd9Sstevel@tonic-gate#	if this is a reconfiguration boot, [re]build the device entries
437c478bd9Sstevel@tonic-gate#	check and mount other file systems to be mounted in single user mode
447c478bd9Sstevel@tonic-gate
457c478bd9Sstevel@tonic-gateif [ -z "$SMF_RESTARTER" ]; then
46*bbf21555SRichard Lowe	echo "Cannot be run outside smf(7)"
477c478bd9Sstevel@tonic-gate	exit 1
487c478bd9Sstevel@tonic-gatefi
497c478bd9Sstevel@tonic-gate
507c478bd9Sstevel@tonic-gate. /lib/svc/share/smf_include.sh
517c478bd9Sstevel@tonic-gate
527c478bd9Sstevel@tonic-gate#
537c478bd9Sstevel@tonic-gate# Default definitions:
547c478bd9Sstevel@tonic-gate#
557c478bd9Sstevel@tonic-gatePATH=/usr/sbin:/usr/bin:/sbin
567c478bd9Sstevel@tonic-gatevfstab=/etc/vfstab
577c478bd9Sstevel@tonic-gatemnttab=/etc/mnttab
587c478bd9Sstevel@tonic-gatemntlist=
597c478bd9Sstevel@tonic-gateoption=
607c478bd9Sstevel@tonic-gateotherops=
617c478bd9Sstevel@tonic-gate
627c478bd9Sstevel@tonic-gateaction=$1
637c478bd9Sstevel@tonic-gate
647c478bd9Sstevel@tonic-gate# Export boot parameters to rc scripts
657c478bd9Sstevel@tonic-gate
667c478bd9Sstevel@tonic-gateif [ "x$1" != xsysinit -a -d /usr/bin ]; then
677c478bd9Sstevel@tonic-gate	set -- `/usr/bin/who -r`
687c478bd9Sstevel@tonic-gate
697c478bd9Sstevel@tonic-gate	_INIT_RUN_LEVEL=${7:-S}   # Current run-level
707c478bd9Sstevel@tonic-gate	_INIT_RUN_NPREV=${8:-0}   # Number of times previously at current level
717c478bd9Sstevel@tonic-gate	_INIT_PREV_LEVEL=${9:-0}  # Previous run-level
727c478bd9Sstevel@tonic-gateelse
737c478bd9Sstevel@tonic-gate	_INIT_RUN_LEVEL=S
747c478bd9Sstevel@tonic-gate	_INIT_RUN_NPREV=0
757c478bd9Sstevel@tonic-gate	_INIT_PREV_LEVEL=0
767c478bd9Sstevel@tonic-gatefi
777c478bd9Sstevel@tonic-gate
787c478bd9Sstevel@tonic-gateset -- `/sbin/uname -a`
797c478bd9Sstevel@tonic-gate
807c478bd9Sstevel@tonic-gate#
817c478bd9Sstevel@tonic-gate# If we're booting, uname -a will produce one fewer token than usual because
827c478bd9Sstevel@tonic-gate# the hostname has not yet been configured.  Leave NODENAME empty in this case.
837c478bd9Sstevel@tonic-gate#
847c478bd9Sstevel@tonic-gateif [ $# -eq 7 ]; then
857c478bd9Sstevel@tonic-gate	_INIT_UTS_SYSNAME="$1"  # Operating system name (uname -s)
867c478bd9Sstevel@tonic-gate	_INIT_UTS_NODENAME="$2" # Node name (uname -n)
877c478bd9Sstevel@tonic-gate	shift 2
887c478bd9Sstevel@tonic-gateelse
897c478bd9Sstevel@tonic-gate	_INIT_UTS_SYSNAME="$1"  # Operating system name (uname -s)
907c478bd9Sstevel@tonic-gate	_INIT_UTS_NODENAME=	# Node name is not yet configured
917c478bd9Sstevel@tonic-gate	shift 1
927c478bd9Sstevel@tonic-gatefi
937c478bd9Sstevel@tonic-gate
947c478bd9Sstevel@tonic-gate_INIT_UTS_RELEASE="$1"  # Operating system release (uname -r)
957c478bd9Sstevel@tonic-gate_INIT_UTS_VERSION="$2"  # Operating system version (uname -v)
967c478bd9Sstevel@tonic-gate_INIT_UTS_MACHINE="$3"  # Machine class (uname -m)
977c478bd9Sstevel@tonic-gate_INIT_UTS_ISA="$4"      # Instruction set architecture (uname -p)
987c478bd9Sstevel@tonic-gate_INIT_UTS_PLATFORM="$5" # Platform string (uname -i)
997c478bd9Sstevel@tonic-gate
1007c478bd9Sstevel@tonic-gateexport _INIT_RUN_LEVEL _INIT_RUN_NPREV _INIT_PREV_LEVEL \
1017c478bd9Sstevel@tonic-gate    _INIT_UTS_SYSNAME _INIT_UTS_NODENAME _INIT_UTS_RELEASE _INIT_UTS_VERSION \
1027c478bd9Sstevel@tonic-gate    _INIT_UTS_MACHINE _INIT_UTS_ISA _INIT_UTS_PLATFORM
1037c478bd9Sstevel@tonic-gate
1047c478bd9Sstevel@tonic-gate#
1056927f468Sdp# Set _INIT_NET_STRATEGY and _INIT_NET_IF variables from /sbin/netstrategy
1067c478bd9Sstevel@tonic-gate#
1076927f468Sdpsmf_netstrategy
1087c478bd9Sstevel@tonic-gate
1097c478bd9Sstevel@tonic-gate. /lib/svc/share/fs_include.sh
1107c478bd9Sstevel@tonic-gate
1117c478bd9Sstevel@tonic-gate#
1127c478bd9Sstevel@tonic-gate# Make the old, deprecated environment variable (_DVFS_RECONFIG) and the new
1137c478bd9Sstevel@tonic-gate# supported environment variable (_INIT_RECONFIG) to be synonyms.  Set both
1147c478bd9Sstevel@tonic-gate# if the svc.startd reconfigure property is set.  Note that for complete
1157c478bd9Sstevel@tonic-gate# backwards compatibility the value "YES" is significant with _DVFS_RECONFIG.
1167c478bd9Sstevel@tonic-gate# The # value associated with _INIT_RECONFIG is insignificant.  What is
1177c478bd9Sstevel@tonic-gate# significant is only that the environment variable is defined.
1187c478bd9Sstevel@tonic-gate#
1197c478bd9Sstevel@tonic-gate
1207c478bd9Sstevel@tonic-gatesvcprop -q -p system/reconfigure system/svc/restarter:default
1217c478bd9Sstevel@tonic-gateif [ $? -eq 0 ]
1227c478bd9Sstevel@tonic-gatethen
1237c478bd9Sstevel@tonic-gate	echo "Setting _INIT_RECONFIG."
1247c478bd9Sstevel@tonic-gate	_DVFS_RECONFIG=YES; export _DVFS_RECONFIG
1257c478bd9Sstevel@tonic-gate	_INIT_RECONFIG=set; export _INIT_RECONFIG
1267c478bd9Sstevel@tonic-gatefi
1277c478bd9Sstevel@tonic-gate
1287c478bd9Sstevel@tonic-gate
1297c478bd9Sstevel@tonic-gatecase $action in
1307c478bd9Sstevel@tonic-gate	stop)
1317c478bd9Sstevel@tonic-gate		>/etc/nologin
1327c478bd9Sstevel@tonic-gate
1337c478bd9Sstevel@tonic-gate		# All remote filesystem services must be explicitly disabled
1347c478bd9Sstevel@tonic-gate		# at the single-user milestone.  There's no need to unmount
1357c478bd9Sstevel@tonic-gate		# remote filesystems here.
1367c478bd9Sstevel@tonic-gate
1377c478bd9Sstevel@tonic-gate		if [ -d /etc/rcS.d ]; then
1387c478bd9Sstevel@tonic-gate			for f in /etc/rcS.d/K*; do
1397c478bd9Sstevel@tonic-gate				if [ ! -s $f ]; then
1407c478bd9Sstevel@tonic-gate					continue
1417c478bd9Sstevel@tonic-gate				fi
1427c478bd9Sstevel@tonic-gate
1437c478bd9Sstevel@tonic-gate				case $f in
1447c478bd9Sstevel@tonic-gate					*.sh)	/lib/svc/bin/lsvcrun -s $f stop
1457c478bd9Sstevel@tonic-gate						;;
1467c478bd9Sstevel@tonic-gate					*)	/lib/svc/bin/lsvcrun $f stop ;;
1477c478bd9Sstevel@tonic-gate				esac
1487c478bd9Sstevel@tonic-gate			done
1497c478bd9Sstevel@tonic-gate		fi
1507c478bd9Sstevel@tonic-gate
1517c478bd9Sstevel@tonic-gate		;;
1527c478bd9Sstevel@tonic-gate
1537c478bd9Sstevel@tonic-gate	start)
1547c478bd9Sstevel@tonic-gate		if [ -d /etc/rcS.d ]; then
1557c478bd9Sstevel@tonic-gate			for f in /etc/rcS.d/S*; do
1567c478bd9Sstevel@tonic-gate				if [ ! -s $f ]; then
1577c478bd9Sstevel@tonic-gate					continue
1587c478bd9Sstevel@tonic-gate				fi
1597c478bd9Sstevel@tonic-gate
1607c478bd9Sstevel@tonic-gate				case $f in
1617c478bd9Sstevel@tonic-gate					*.sh)	/lib/svc/bin/lsvcrun -s $f start
1627c478bd9Sstevel@tonic-gate						;;
1637c478bd9Sstevel@tonic-gate					*)	/lib/svc/bin/lsvcrun $f start ;;
1647c478bd9Sstevel@tonic-gate				esac
1657c478bd9Sstevel@tonic-gate			done
1667c478bd9Sstevel@tonic-gate		fi
1677c478bd9Sstevel@tonic-gate
1687c478bd9Sstevel@tonic-gate		#
1697c478bd9Sstevel@tonic-gate		# Clean up the /reconfigure file and sync the new entries to
1707c478bd9Sstevel@tonic-gate		# stable media.
1717c478bd9Sstevel@tonic-gate		#
1727c478bd9Sstevel@tonic-gate
1737c478bd9Sstevel@tonic-gate		# GLXXX - svc.startd should do this?
1747c478bd9Sstevel@tonic-gate		if [ -n "$_INIT_RECONFIG" ]; then
1757c478bd9Sstevel@tonic-gate			[ -f /reconfigure  ] && /usr/bin/rm -f /reconfigure
1767c478bd9Sstevel@tonic-gate			/sbin/sync
1777c478bd9Sstevel@tonic-gate		fi
1787c478bd9Sstevel@tonic-gate		;;
1797c478bd9Sstevel@tonic-gate
1807c478bd9Sstevel@tonic-gate	*)
1817c478bd9Sstevel@tonic-gate		echo "Usage: $0 { start | stop }"
1827c478bd9Sstevel@tonic-gate		exit $SMF_EXIT_ERR_CONFIG
1837c478bd9Sstevel@tonic-gate		;;
1847c478bd9Sstevel@tonic-gateesac
1857c478bd9Sstevel@tonic-gate
1867c478bd9Sstevel@tonic-gateexit $SMF_EXIT_OK
187