rc revision 45239
140123Sdes#!/bin/sh
245239Sgrog#	$Id: rc,v 1.185 1999/04/01 13:30:29 cracauer Exp $
3709Swollman#	From: @(#)rc	5.27 (Berkeley) 6/5/91
437Srgrimes
537Srgrimes# System startup script run by init on autoboot
637Srgrimes# or after single-user.
737Srgrimes# Output and error are redirected to console by init,
837Srgrimes# and the console is the controlling terminal.
937Srgrimes
108460Sjkh# Note that almost all the user-configurable behavior is no longer in
1143951Sjkh# this file, but rather in /etc/defaults/rc.conf.  Please check this file
128460Sjkh# first before contemplating any changes here.
138460Sjkh
1437Srgrimesstty status '^T'
1537Srgrimes
1637Srgrimes# Set shell to ignore SIGINT (2), but not children;
1737Srgrimes# shell catches SIGQUIT (3) and returns to single user after fsck.
1837Srgrimestrap : 2
1937Srgrimestrap : 3	# shouldn't be needed
2037Srgrimes
2137SrgrimesHOME=/; export HOME
2220684SjoergPATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin
2337Srgrimesexport PATH
2437Srgrimes
2543179Sdillon# BOOTP diskless boot.  We have to run the rc file early in order to
2643803Sdillon# retarget various config files.
2743179Sdillon#
2843803Sdillonif [ -f /etc/rc.diskless1 ]; then
2943375Sdillon	dlv=`/sbin/sysctl -n vfs.nfs.diskless_valid 2> /dev/null`
3043375Sdillon	if [ ${dlv:=0} != 0 ]; then
3143803Sdillon		. /etc/rc.diskless1
3243179Sdillon	fi
3343179Sdillonfi
3443179Sdillon
3543219Speter# If there is a global system configuration file, suck it in.
3643219Speter#
3743849Sjkhif [ -f /etc/defaults/rc.conf ]; then
3843849Sjkh	. /etc/defaults/rc.conf
3943849Sjkhelif [ -f /etc/rc.conf ]; then
4043219Speter	. /etc/rc.conf
4143219Speterfi
4243219Speter
4315568Sasami# Configure ccd devices.
4443803Sdillonif [ -f /etc/ccd.conf ]; then
4515568Sasami	ccdconfig -C
4615568Sasamifi
4715568Sasami
4845239Sgrogif [ X$start_vinum = XYES ]; then
4945239Sgrog	vinum start
5045239Sgrogelif [ -n "$vinum_drives" ]; then
5143454Sgrog	vinum read $vinum_drives
5242741Sgrogfi
5342741Sgrog
5443803Sdillonswapon -a
553843Sdg
5643803Sdillonif [ $1x = autobootx ]; then
5737Srgrimes	echo Automatic reboot in progress...
5837Srgrimes	fsck -p
5937Srgrimes	case $? in
6037Srgrimes	0)
6137Srgrimes		;;
6237Srgrimes	2)
6337Srgrimes		exit 1
6437Srgrimes		;;
6537Srgrimes	4)
6637Srgrimes		reboot
6737Srgrimes		echo "reboot failed... help!"
6837Srgrimes		exit 1
6937Srgrimes		;;
7037Srgrimes	8)
7137Srgrimes		echo "Automatic file system check failed... help!"
7237Srgrimes		exit 1
7337Srgrimes		;;
7437Srgrimes	12)
7537Srgrimes		echo "Reboot interrupted"
7637Srgrimes		exit 1
7737Srgrimes		;;
7837Srgrimes	130)
7937Srgrimes		# interrupt before catcher installed
8037Srgrimes		exit 1
8137Srgrimes		;;
8237Srgrimes	*)
8337Srgrimes		echo "Unknown error in reboot"
8437Srgrimes		exit 1
8537Srgrimes		;;
8637Srgrimes	esac
872164Sdgelse
882164Sdg	echo Skipping disk checks ...
8937Srgrimesfi
9037Srgrimes
9145222Scracauerset -T
9237Srgrimestrap "echo 'Reboot interrupted'; exit 1" 3
9337Srgrimes
9443197Sdillon# root normally must be read/write, but if this is a BOOTP NFS
9543197Sdillon# diskless boot it does not have to be.
9643197Sdillon#
971692Sphk
9843803Sdillonif [ "X$root_rw_mount" != "XNO" ]; then
9943197Sdillon	mount -u -o rw /
10043803Sdillonfi
1018530Sdg
10243803Sdillonif [ $? != 0 ]; then
10343803Sdillon	echo "Filesystem mount failed, startup aborted"
10443803Sdillon	exit 1
10543803Sdillonfi
10643197Sdillon
10743803Sdillonumount -a >/dev/null 2>&1
10843197Sdillon
10943803Sdillonif [ "X$early_nfs_mounts" != "XYES" ]; then
11043197Sdillon	mount -a -t nonfs
11143803Sdillonelse
11243803Sdillon	mount -a
1138530Sdgfi
11443803Sdillonif [ $? != 0 ]; then
11543803Sdillon	echo "Filesystem mount failed, startup aborted"
11643803Sdillon	exit 1
11743803Sdillonfi
11837Srgrimes
11943197Sdillon# Run custom disk mounting function here
12043197Sdillon#
12143197Sdillon
12243803Sdillonif [ "X$diskless_mount" != "X" ]; then
12343803Sdillon	if [ -f $diskless_mount ]; then
12443803Sdillon		sh $diskless_mount
12543803Sdillon	fi
12643197Sdillonfi
12743197Sdillon
1284091Sacheadjkerntz -i
129872Sache
13038237Sbrianclean_var() {
13139384Sbrian	if [ ! -f /var/run/clean_var ]; then
13239384Sbrian		rm -rf /var/run/*
13339384Sbrian		rm -f /var/spool/lock/*
13439384Sbrian		rm -rf /var/spool/uucp/.Temp/*
13539384Sbrian		# Keep a copy of the boot messages around
13639384Sbrian		dmesg >/var/run/dmesg.boot
13739384Sbrian		# And an initial utmp file
13839384Sbrian		(cd /var/run && cp /dev/null utmp && chmod 644 utmp; )
13939384Sbrian		>/var/run/clean_var
14039384Sbrian	fi
14138237Sbrian}
14226450Sache
14338237Sbrianif [ -d /var/run -a -d /var/spool/lock -a -d /var/spool/uucp/.Temp ]; then
14439384Sbrian	# network_pass1() *may* end up writing stuff to /var - we don't want to
14539384Sbrian	# remove it immediately afterwards - *nor* to we want to fail to clean
14639384Sbrian	# an nfs-mounted /var.
14739384Sbrian	clean_var
14838237Sbrianfi
14921197Sphk
15017767Sjkh# Add additional swapfile, if configured.
15119363Sjoergif [ "x$swapfile" != "xNO" -a -w "$swapfile" -a -b /dev/vn0b ]; then
15217767Sjkh	echo "Adding $swapfile as additional swap."
15325184Sjkh	vnconfig /dev/vn0b $swapfile && swapon /dev/vn0b
15417767Sjkhfi
15517767Sjkh
15645096Simp# set sysctl variables early as we can
15745096Simpif [ -f /etc/rc.sysctl ]; then
15845096Simp	. /etc/rc.sysctl
15945096Simpfi
16045096Simp
1611675Sache# configure serial devices
1627219Sjkhif [ -f /etc/rc.serial ]; then
1637293Sjkh	. /etc/rc.serial
1641675Sachefi
1651675Sache
16614596Snate# start up PC-card configuration
16714624Snateif [ -f /etc/rc.pccard ]; then
16814624Snate	. /etc/rc.pccard
16914596Snatefi
17014596Snate
17125184Sjkh# start up the initial network configuration.
17225184Sjkhif [ -f /etc/rc.network ]; then
17325184Sjkh	. /etc/rc.network	# We only need to do this once.
17425184Sjkh	network_pass1
1757460Sjkhfi
1767460Sjkh
17738456Sphkecho -n "Mounting NFS file systems"
17829319Sbrianmount -a -t nfs
17938456Sphkecho .
1807487Srgrimes
1817487Srgrimes# Whack the pty perms back into shape.
18220828Sjoergchmod 666 /dev/tty[pqrsPQRS]*
18344752Sdeschown root:wheel /dev/tty[pqrsPQRS]*
1847487Srgrimes
1857487Srgrimes# clean up left-over files
18638237Sbrianclean_var			# If it hasn't already been done
18738237Sbrianrm /var/run/clean_var
18838237Sbrian
18931192Ssteve#
19031192Ssteve# Clearing /tmp at boot-time seems to have a long tradition.  It doesn't
19131192Ssteve# help in any way for long-living systems, and it might accidentally
19231192Ssteve# clobber files you would rather like to have preserved after a crash
19331192Ssteve# (if not using mfs /tmp anyway).
19431192Ssteve#
19531192Ssteve# See also the example of another cleanup policy in /etc/periodic/daily.
19631192Ssteve#
19731192Ssteveif [ "X${clear_tmp_enable}" = X"YES" ]; then
19831192Ssteve	echo clearing /tmp
19931192Ssteve
20031192Ssteve	# prune quickly with one rm, then use find to clean up /tmp/[lq]*
20131192Ssteve	# (not needed with mfs /tmp, but doesn't hurt there...)
20231192Ssteve	(cd /tmp && rm -rf [a-km-pr-zA-Z]* &&
20339384Sbrian		find -d . ! -name . ! -name lost+found ! -name quotas -exec rm -rf -- {} \;)
20431192Ssteve
20531192Sstevefi
20631192Ssteve
20738915Scracauer# Remove X lock files, since they will prevent you from restarting X11 
20838915Scracauer# after a system crash.
20938915Scracauerrm -f /tmp/.X*-lock /tmp/.X11-unix/*
21038915Scracauer
21142897Sjkh# snapshot any kernel -c changes back to disk here <someday>
21242897Sjkh# this has changed with ELF and /kernel.config.
2137487Srgrimes
21425339Sjkhecho -n 'additional daemons:'
2157487Srgrimes# start system logging and name service (named needs to start before syslogd
2167487Srgrimes# if you don't have a /etc/resolv.conf)
2177259Sjkh#
21825412Sjkhif [ "X${syslogd_enable}" = X"YES" ]; then
21924463Spst	# Transitional symlink (for the next couple of years :) until all
22024463Spst	# binaries had a chance to move towards /var/run/log.
22124463Spst	if [ ! -h /dev/log ] ; then
22224463Spst		# might complain for r/o root f/s
22324463Spst		ln -sf /var/run/log /dev/log
22424463Spst	fi
22524463Spst
22624463Spst	rm -f /var/run/log
22725339Sjkh	echo -n ' syslogd';		syslogd ${syslogd_flags}
22819226Sjoergfi
22925339Sjkhecho '.'
23025339Sjkh
23132340Sjoerg# enable dumpdev so that savecore can see it
23232340Sjoerg# /var/crash should be a directory or a symbolic link
23332340Sjoerg# to the crash directory if core dumps are to be saved.
23432340Sjoergif [ "X${dumpdev}" != X"NO" -a -e ${dumpdev} -a -d /var/crash ]; then
23532340Sjoerg	dumpon ${dumpdev}
23632340Sjoerg	echo -n checking for core dump...
23732340Sjoerg	savecore /var/crash
23832340Sjoergfi
23932340Sjoerg
24025184Sjkhif [ -n "$network_pass1_done" ]; then
24139384Sbrian	network_pass2
242857Sdgfi
24337Srgrimes
24444818Sbillf# Enable/Check the quotas (must be after ypbind if using NIS)
24544818Sbillfif [ "X${enable_quotas}" = X"YES" ]; then
24644818Sbillf
24744818Sbillf    # Only check quotas if they have been previously enabled, and requested
24844818Sbillf    if [ "X${check_quotas}" = X"YES" ]; then
24944818Sbillf            echo -n 'checking quotas:'
25044818Sbillf            quotacheck -a
25144818Sbillf            echo ' done.'
25244818Sbillf    fi
25344818Sbillf
25444818Sbillf        echo -n 'enabling quotas:'
25544818Sbillf        quotaon -a
25644818Sbillf        echo ' done.'
2577238Sachefi
2587238Sache
25925184Sjkhif [ -n "$network_pass2_done" ]; then
26039384Sbrian	network_pass3
2617477Sachefi
2627477Sache
2637238Sache
2647487Srgrimes# build ps databases
2657487Srgrimeskvm_mkdb 
2667487Srgrimesdev_mkdb
2677487Srgrimes
2687487Srgrimes# check the password temp/lock file
2697487Srgrimesif [ -f /etc/ptmp ]
2707487Srgrimesthen
2717487Srgrimes	logger -s -p auth.err \
2727487Srgrimes	"password file may be incorrect -- /etc/ptmp exists"
2737238Sachefi
2747238Sache
27525184Sjkhif [ "X${accounting_enable}" = X"YES" -a -d /var/account ]; then
27611992Sache	echo 'turning on accounting'
27711992Sache	if [ ! -e /var/account/acct ]; then
27825412Sjkh		touch /var/account/acct
27911992Sache	fi
28011992Sache	accton /var/account/acct
2817238Sachefi
2827238Sache
28327365Sjkh# Make shared lib searching a little faster.  Leave /usr/lib first if you
28427365Sjkh# add your own entries or you may come to grief.
28538512Sgpalmerif [ -x /sbin/ldconfig ]; then
28639329Sjdp	if [ X"`/usr/bin/objformat`" = X"elf" ]; then
28739329Sjdp		_LDC=/usr/lib
28839329Sjdp		for i in $ldconfig_paths; do
28939329Sjdp			if test -d $i; then
29039329Sjdp				_LDC="${_LDC} $i"
29139329Sjdp			fi
29239329Sjdp		done
29339329Sjdp		echo 'setting ELF ldconfig path:' ${_LDC}
29439329Sjdp		ldconfig -elf ${_LDC}
29539329Sjdp	fi
29639329Sjdp
29741648Sjb	# Legacy aout support for i386 only
29841676Sjb	if [ X"`sysctl -n hw.machine`" = X"i386" ]; then
29943951Sjkh		# Default the a.out ldconfig path.
30041648Sjb		: ${ldconfig_paths_aout=${ldconfig_paths}}
30141648Sjb		_LDC=/usr/lib/aout
30241648Sjb		for i in $ldconfig_paths_aout; do
30341648Sjb			if test -d $i; then
30441648Sjb				_LDC="${_LDC} $i"
30541648Sjb			fi
30641648Sjb		done
30741648Sjb		echo 'setting a.out ldconfig path:' ${_LDC}
30841648Sjb		ldconfig -aout ${_LDC}
30941648Sjb	fi
31038512Sgpalmerfi
3117296Sjkh
31217210Spst# Now start up miscellaneous daemons that don't belong anywhere else
31317210Spst#
31425339Sjkhecho -n starting standard daemons:
31529343Sbrianif [ "X${inetd_enable}" != X"NO" ]; then
31626727Spst	echo -n ' inetd';	inetd ${inetd_flags}
31726727Spstfi
31817210Spst
31929343Sbrianif [ "X${cron_enable}" != X"NO" ]; then
32026727Spst	echo -n ' cron';	cron
32126727Spstfi
32226727Spst
32325184Sjkhif [ "X${lpd_enable}" = X"YES" ]; then
32444668Sjfitz	echo -n ' printer';		${lpd_program} ${lpd_flags}
32517210Spstfi
32617210Spst
32725184Sjkhif [ "X${sendmail_enable}" = X"YES" -a -r /etc/sendmail.cf ]; then
32825530Sjkh	echo -n ' sendmail';	/usr/sbin/sendmail ${sendmail_flags}
32917161Spstfi
33017161Spst
33142498Sn_hibmaif [ "X${usbd_enable}" = X"YES" ]; then
33242498Sn_hibma	echo -n ' usbd';	/usr/sbin/usbd ${usbd_flags}
33342498Sn_hibmafi
33442498Sn_hibma
33517161Spstecho '.'
33617161Spst
3377487Srgrimes# configure implementation specific stuff
3387487Srgrimesarch=`uname -m`
33925469Sandreasif [ -f /etc/rc.${arch} ]; then
34025469Sandreas	. /etc/rc.${arch}
34125469Sandreasfi
3427487Srgrimes
34316671Spst# Recover vi editor files.
34419314Spetervibackup=`echo /var/tmp/vi.recover/vi.*`
34519314Speterif [ "$vibackup" != '/var/tmp/vi.recover/vi.*' ]; then
34616671Spst	echo 'Recovering vi editor sessions'
34719314Speter	for i in $vibackup; do
34819314Speter		# Only test files that are readable.
34919314Speter		if test ! -r $i; then
35019314Speter			continue
35119314Speter		fi
35219314Speter
35319314Speter		# Unmodified nvi editor backup files either have the
35419314Speter		# execute bit set or are zero length.  Delete them.
35519314Speter		if test -x $i -o ! -s $i; then
35619314Speter			rm -f $i
35719314Speter		fi
35816671Spst	done
35919314Speter
36019314Speter	# It is possible to get incomplete recovery files, if the editor
36119314Speter	# crashes at the right time.
36219314Speter	virecovery=`echo /var/tmp/vi.recover/recover.*`
36319314Speter	if [ "$virecovery" != "/var/tmp/vi.recover/recover.*" ]; then
36419314Speter		for i in $virecovery; do
36519314Speter			# Only test files that are readable.
36619314Speter			if test ! -r $i; then
36719314Speter				continue
36819314Speter			fi
36919314Speter
37019314Speter			# Delete any recovery files that are zero length,
37119314Speter			# corrupted, or that have no corresponding backup file.
37219314Speter			# Else send mail to the user.
37319314Speter			recfile=`awk '/^X-vi-recover-path:/{print $2}' < $i`
37419314Speter			if test -n "$recfile" -a -s "$recfile"; then
37519314Speter				sendmail -t < $i
37619314Speter			else
37719314Speter				rm -f $i
37819314Speter			fi
37919314Speter		done
38019314Speter	fi
38116671Spstfi
38216671Spst
38337899Snectar# make a bounds file for msgs(1) if there isn't one already
38437899Snectarif [ ! -f /var/msgs/bounds ]; then
38537899Snectar	echo 0 > /var/msgs/bounds
38637899Snectarfi
38737899Snectar
38813071Sjkh# for each valid dir in $local_startup, search for init scripts matching *.sh
38913071Sjkhif [ "X${local_startup}" != X"NO" ]; then
39027365Sjkh	echo -n 'Local package initialization:'
39113071Sjkh	for dir in ${local_startup}; do
39213071Sjkh		[ -d ${dir} ] && for script in ${dir}/*.sh; do
39345222Scracauer			[ -x ${script} ] && (set -T ; trap 'exit 1' 2 ; ${script} start)
39413071Sjkh		done
39510873Sjkh	done
39616391Sjkh	echo .
3977259Sjkhfi
39837Srgrimes
39941704Sdillonif [ "X${update_motd}" != X"NO" ]; then
40041704Sdillon	T=/tmp/_motd
40141704Sdillon	rm -f $T
40241704Sdillon	uname -v | sed -e 's,^\([^#]*\) #\(.* [1-2][0-9][0-9][0-9]\).*/\([^\]*\) $,\1 (\3) #\2,' > $T
40341704Sdillon	awk '{if (NR == 1) {if ($1 == "FreeBSD") {next} else {print "\n"$0}} else {print}}' < /etc/motd >> $T
40441704Sdillon	cp $T /etc/motd
40541704Sdillon	chmod 644 /etc/motd
40641704Sdillon	rm -f $T
40741704Sdillonfi
40841704Sdillon
40939162Ssos# Run rc.devfs if present to customify devfs
41039162Ssos[ -f /etc/rc.devfs ] && sh /etc/rc.devfs
41139162Ssos
41241704Sdillon# Do traditional (but rather obsolete) rc.local file if it exists.  If you
41343951Sjkh# use this file and want to make it programmatic, source /etc/defaults/rc.conf
41443951Sjkh# in /etc/rc.local and add your custom variables to /etc/rc.conf, as
41543951Sjkh# shown below.  Please do not put local extensions into /etc/rc itself.
41641704Sdillon# Use /etc/rc.local
41741704Sdillon#
41841704Sdillon# ---- rc.local  ----
41943951Sjkh#     if [ -f /etc/defaults/rc.conf ]; then
42043951Sjkh#             . /etc/defaults/rc.conf
42141704Sdillon#     fi
42243951Sjkh# 
42341704Sdillon#     ... additional startup conditionals ...
42443951Sjkh# ---- rc.local  ---- 
42543197Sdillon# 
42643797Sdillonif [ -f /etc/rc.local ]; then
42743197Sdillon	echo -n 'starting local daemons:'
42843797Sdillon        sh /etc/rc.local
42943197Sdillon	echo '.'
43041704Sdillonfi
43141704Sdillon
43237106Sjkoshy# Raise kernel security level.  This should be done only after `fsck' has
43337106Sjkoshy# repaired local file systems if you want the securelevel to be greater than 1.
43439030Sjraynardif [ "X${kern_securelevel_enable}" = X"YES" -a "${kern_securelevel}" -ge 0 ]; 
43537106Sjkoshythen
43637106Sjkoshy	echo 'Raising kernel security level'
43737106Sjkoshy	sysctl -w kern.securelevel=${kern_securelevel}
43837106Sjkoshyfi
43937106Sjkoshy
44037Srgrimesdate
44137Srgrimesexit 0
442