rc revision 39384
1709Swollman#!/bin/sh
239384Sbrian#	$Id: rc,v 1.156 1998/09/16 05:42:37 jdp 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
1125184Sjkh# this file, but rather in /etc/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
2515568Sasami# Configure ccd devices.
2625184Sjkhif [ -f /etc/ccd.conf ]; then
2715568Sasami	ccdconfig -C
2815568Sasamifi
2915568Sasami
303843Sdgswapon -a
313843Sdg
3225184Sjkhif [ $1x = autobootx ]; then
3337Srgrimes	echo Automatic reboot in progress...
3437Srgrimes	fsck -p
3537Srgrimes	case $? in
3637Srgrimes	0)
3737Srgrimes		;;
3837Srgrimes	2)
3937Srgrimes		exit 1
4037Srgrimes		;;
4137Srgrimes	4)
4237Srgrimes		reboot
4337Srgrimes		echo "reboot failed... help!"
4437Srgrimes		exit 1
4537Srgrimes		;;
4637Srgrimes	8)
4737Srgrimes		echo "Automatic file system check failed... help!"
4837Srgrimes		exit 1
4937Srgrimes		;;
5037Srgrimes	12)
5137Srgrimes		echo "Reboot interrupted"
5237Srgrimes		exit 1
5337Srgrimes		;;
5437Srgrimes	130)
5537Srgrimes		# interrupt before catcher installed
5637Srgrimes		exit 1
5737Srgrimes		;;
5837Srgrimes	*)
5937Srgrimes		echo "Unknown error in reboot"
6037Srgrimes		exit 1
6137Srgrimes		;;
6237Srgrimes	esac
632164Sdgelse
642164Sdg	echo Skipping disk checks ...
6537Srgrimesfi
6637Srgrimes
6737Srgrimestrap "echo 'Reboot interrupted'; exit 1" 3
6837Srgrimes
693036Sdg# root must be read/write both for NFS diskless and for VFS LKMs before
703036Sdg# proceeding any further.
713036Sdgmount -u -o rw /
728530Sdgif [ $? != 0 ]; then
738530Sdg	echo "Filesystem mount failed, startup aborted"
748530Sdg	exit 1
758530Sdgfi
761692Sphk
7737Srgrimesumount -a >/dev/null 2>&1
788530Sdg
7937Srgrimesmount -a -t nonfs
808530Sdgif [ $? != 0 ]; then
818530Sdg	echo "Filesystem mount failed, startup aborted"
828530Sdg	exit 1
838530Sdgfi
8437Srgrimes
8525184Sjkh# If there is a global system configuration file, suck it in.
8625184Sjkhif [ -f /etc/rc.conf ]; then
8739384Sbrian	. /etc/rc.conf
8825184Sjkhfi
8925184Sjkh
9025184Sjkh# If old file exists, whine until they fix it.
9125184Sjkhif [ -f /etc/sysconfig ]; then
9225184Sjkh	echo "Warning: /etc/sysconfig has been replaced by /etc/rc.conf."
9325184Sjkh	echo "You should switch to /etc/rc.conf ASAP to eliminate this warning."
9425184Sjkhfi
9525184Sjkh
964091Sacheadjkerntz -i
97872Sache
9838237Sbrianclean_var() {
9939384Sbrian	if [ ! -f /var/run/clean_var ]; then
10039384Sbrian		rm -rf /var/run/*
10139384Sbrian		rm -f /var/spool/lock/*
10239384Sbrian		rm -rf /var/spool/uucp/.Temp/*
10339384Sbrian		# Keep a copy of the boot messages around
10439384Sbrian		dmesg >/var/run/dmesg.boot
10539384Sbrian		# And an initial utmp file
10639384Sbrian		(cd /var/run && cp /dev/null utmp && chmod 644 utmp; )
10739384Sbrian		>/var/run/clean_var
10839384Sbrian	fi
10938237Sbrian}
11026450Sache
11138237Sbrianif [ -d /var/run -a -d /var/spool/lock -a -d /var/spool/uucp/.Temp ]; then
11239384Sbrian	# network_pass1() *may* end up writing stuff to /var - we don't want to
11339384Sbrian	# remove it immediately afterwards - *nor* to we want to fail to clean
11439384Sbrian	# an nfs-mounted /var.
11539384Sbrian	clean_var
11638237Sbrianfi
11721197Sphk
11817767Sjkh# Add additional swapfile, if configured.
11919363Sjoergif [ "x$swapfile" != "xNO" -a -w "$swapfile" -a -b /dev/vn0b ]; then
12017767Sjkh	echo "Adding $swapfile as additional swap."
12125184Sjkh	vnconfig /dev/vn0b $swapfile && swapon /dev/vn0b
12217767Sjkhfi
12317767Sjkh
1241675Sache# configure serial devices
1257219Sjkhif [ -f /etc/rc.serial ]; then
1267293Sjkh	. /etc/rc.serial
1271675Sachefi
1281675Sache
12914596Snate# start up PC-card configuration
13014624Snateif [ -f /etc/rc.pccard ]; then
13114624Snate	. /etc/rc.pccard
13214596Snatefi
13314596Snate
13425184Sjkh# start up the initial network configuration.
13525184Sjkhif [ -f /etc/rc.network ]; then
13625184Sjkh	. /etc/rc.network	# We only need to do this once.
13725184Sjkh	network_pass1
1387460Sjkhfi
1397460Sjkh
14038456Sphkecho -n "Mounting NFS file systems"
14129319Sbrianmount -a -t nfs
14238456Sphkecho .
1437487Srgrimes
1447487Srgrimes# Whack the pty perms back into shape.
14520828Sjoergchmod 666 /dev/tty[pqrsPQRS]*
1467487Srgrimes
1477487Srgrimes# clean up left-over files
1487487Srgrimesrm -f /etc/nologin
1497487Srgrimes
15038237Sbrianclean_var			# If it hasn't already been done
15138237Sbrianrm /var/run/clean_var
15238237Sbrian
15331192Ssteve#
15431192Ssteve# Clearing /tmp at boot-time seems to have a long tradition.  It doesn't
15531192Ssteve# help in any way for long-living systems, and it might accidentally
15631192Ssteve# clobber files you would rather like to have preserved after a crash
15731192Ssteve# (if not using mfs /tmp anyway).
15831192Ssteve#
15931192Ssteve# See also the example of another cleanup policy in /etc/periodic/daily.
16031192Ssteve#
16131192Ssteveif [ "X${clear_tmp_enable}" = X"YES" ]; then
16231192Ssteve	echo clearing /tmp
16331192Ssteve
16431192Ssteve	# prune quickly with one rm, then use find to clean up /tmp/[lq]*
16531192Ssteve	# (not needed with mfs /tmp, but doesn't hurt there...)
16631192Ssteve	(cd /tmp && rm -rf [a-km-pr-zA-Z]* &&
16739384Sbrian		find -d . ! -name . ! -name lost+found ! -name quotas -exec rm -rf -- {} \;)
16831192Ssteve
16931192Sstevefi
17031192Ssteve
17138915Scracauer# Remove X lock files, since they will prevent you from restarting X11 
17238915Scracauer# after a system crash.
17338915Scracauerrm -f /tmp/.X*-lock /tmp/.X11-unix/*
17438915Scracauer
1757487Srgrimes# snapshot any kernel -c changes back to disk
1767487Srgrimesecho 'recording kernel -c changes'
17725339Sjkhdset -q
1787487Srgrimes
17925339Sjkhecho -n 'additional daemons:'
1807487Srgrimes# start system logging and name service (named needs to start before syslogd
1817487Srgrimes# if you don't have a /etc/resolv.conf)
1827259Sjkh#
18325412Sjkhif [ "X${syslogd_enable}" = X"YES" ]; then
18424463Spst	# Transitional symlink (for the next couple of years :) until all
18524463Spst	# binaries had a chance to move towards /var/run/log.
18624463Spst	if [ ! -h /dev/log ] ; then
18724463Spst		# might complain for r/o root f/s
18824463Spst		ln -sf /var/run/log /dev/log
18924463Spst	fi
19024463Spst
19124463Spst	rm -f /var/run/log
19225339Sjkh	echo -n ' syslogd';		syslogd ${syslogd_flags}
19319226Sjoergfi
1947487Srgrimes
19525339Sjkhif [ "X${tickadj_enable}" = X"YES" ]; then
19625412Sjkh	echo -n ' tickadj';	tickadj ${tickadj_flags--Aq}
19725339Sjkhfi
19825339Sjkhecho '.'
19925339Sjkh
20032340Sjoerg# enable dumpdev so that savecore can see it
20132340Sjoerg# /var/crash should be a directory or a symbolic link
20232340Sjoerg# to the crash directory if core dumps are to be saved.
20332340Sjoergif [ "X${dumpdev}" != X"NO" -a -e ${dumpdev} -a -d /var/crash ]; then
20432340Sjoerg	dumpon ${dumpdev}
20532340Sjoerg	echo -n checking for core dump...
20632340Sjoerg	savecore /var/crash
20732340Sjoergfi
20832340Sjoerg
20925184Sjkhif [ -n "$network_pass1_done" ]; then
21039384Sbrian	network_pass2
211857Sdgfi
21237Srgrimes
21318812Speter# Check the quotas (must be after ypbind if using NIS)
21418812Speterif [ "X${check_quotas}" = X"YES" ]; then
21518812Speter	echo -n 'checking quotas:'
21618812Speter	quotacheck -a
21718812Speter	echo ' done.'
21818812Speter	quotaon -a
2197238Sachefi
2207238Sache
22125184Sjkhif [ -n "$network_pass2_done" ]; then
22239384Sbrian	network_pass3
2237477Sachefi
2247477Sache
2257238Sache
2267487Srgrimes# build ps databases
2277487Srgrimeskvm_mkdb 
2287487Srgrimesdev_mkdb
2297487Srgrimes
2307487Srgrimes# check the password temp/lock file
2317487Srgrimesif [ -f /etc/ptmp ]
2327487Srgrimesthen
2337487Srgrimes	logger -s -p auth.err \
2347487Srgrimes	"password file may be incorrect -- /etc/ptmp exists"
2357238Sachefi
2367238Sache
23725184Sjkhif [ "X${accounting_enable}" = X"YES" -a -d /var/account ]; then
23811992Sache	echo 'turning on accounting'
23911992Sache	if [ ! -e /var/account/acct ]; then
24025412Sjkh		touch /var/account/acct
24111992Sache	fi
24211992Sache	accton /var/account/acct
2437238Sachefi
2447238Sache
24527365Sjkh# Make shared lib searching a little faster.  Leave /usr/lib first if you
24627365Sjkh# add your own entries or you may come to grief.
24738512Sgpalmerif [ -x /sbin/ldconfig ]; then
24839329Sjdp	if [ X"`/usr/bin/objformat`" = X"elf" ]; then
24939329Sjdp		_LDC=/usr/lib
25039329Sjdp		for i in $ldconfig_paths; do
25139329Sjdp			if test -d $i; then
25239329Sjdp				_LDC="${_LDC} $i"
25339329Sjdp			fi
25439329Sjdp		done
25539329Sjdp		echo 'setting ELF ldconfig path:' ${_LDC}
25639329Sjdp		ldconfig -elf ${_LDC}
25739329Sjdp	fi
25839329Sjdp
25939329Sjdp	# Default the a.out ldconfig path, in case the system's
26039329Sjdp	# /etc/rc.conf hasn't been updated.
26139329Sjdp	: ${ldconfig_paths_aout=${ldconfig_paths}}
26238512Sgpalmer	_LDC=/usr/lib/aout
26339329Sjdp	for i in $ldconfig_paths_aout; do
26438512Sgpalmer		if test -d $i; then
26538512Sgpalmer			_LDC="${_LDC} $i"
26638512Sgpalmer		fi
26738512Sgpalmer	done
26838837Sjdp	echo 'setting a.out ldconfig path:' ${_LDC}
26938837Sjdp	ldconfig -aout ${_LDC}
27038512Sgpalmerfi
2717296Sjkh
27217210Spst# Now start up miscellaneous daemons that don't belong anywhere else
27317210Spst#
27425339Sjkhecho -n starting standard daemons:
27529343Sbrianif [ "X${inetd_enable}" != X"NO" ]; then
27626727Spst	echo -n ' inetd';	inetd ${inetd_flags}
27726727Spstfi
27817210Spst
27929343Sbrianif [ "X${cron_enable}" != X"NO" ]; then
28026727Spst	echo -n ' cron';	cron
28126727Spstfi
28226727Spst
28325184Sjkhif [ "X${lpd_enable}" = X"YES" ]; then
28425916Sjkh	echo -n ' printer';		lpd ${lpd_flags}
28517210Spstfi
28617210Spst
28725184Sjkhif [ "X${sendmail_enable}" = X"YES" -a -r /etc/sendmail.cf ]; then
28825530Sjkh	echo -n ' sendmail';	/usr/sbin/sendmail ${sendmail_flags}
28917161Spstfi
29017161Spst
29117161Spstecho '.'
29217161Spst
2937487Srgrimes# configure implementation specific stuff
2947487Srgrimesarch=`uname -m`
29525469Sandreasif [ -f /etc/rc.${arch} ]; then
29625469Sandreas	. /etc/rc.${arch}
29725469Sandreasfi
2987487Srgrimes
29916671Spst# Recover vi editor files.
30019314Spetervibackup=`echo /var/tmp/vi.recover/vi.*`
30119314Speterif [ "$vibackup" != '/var/tmp/vi.recover/vi.*' ]; then
30216671Spst	echo 'Recovering vi editor sessions'
30319314Speter	for i in $vibackup; do
30419314Speter		# Only test files that are readable.
30519314Speter		if test ! -r $i; then
30619314Speter			continue
30719314Speter		fi
30819314Speter
30919314Speter		# Unmodified nvi editor backup files either have the
31019314Speter		# execute bit set or are zero length.  Delete them.
31119314Speter		if test -x $i -o ! -s $i; then
31219314Speter			rm -f $i
31319314Speter		fi
31416671Spst	done
31519314Speter
31619314Speter	# It is possible to get incomplete recovery files, if the editor
31719314Speter	# crashes at the right time.
31819314Speter	virecovery=`echo /var/tmp/vi.recover/recover.*`
31919314Speter	if [ "$virecovery" != "/var/tmp/vi.recover/recover.*" ]; then
32019314Speter		for i in $virecovery; do
32119314Speter			# Only test files that are readable.
32219314Speter			if test ! -r $i; then
32319314Speter				continue
32419314Speter			fi
32519314Speter
32619314Speter			# Delete any recovery files that are zero length,
32719314Speter			# corrupted, or that have no corresponding backup file.
32819314Speter			# Else send mail to the user.
32919314Speter			recfile=`awk '/^X-vi-recover-path:/{print $2}' < $i`
33019314Speter			if test -n "$recfile" -a -s "$recfile"; then
33119314Speter				sendmail -t < $i
33219314Speter			else
33319314Speter				rm -f $i
33419314Speter			fi
33519314Speter		done
33619314Speter	fi
33716671Spstfi
33816671Spst
33937899Snectar# make a bounds file for msgs(1) if there isn't one already
34037899Snectarif [ ! -f /var/msgs/bounds ]; then
34137899Snectar	echo 0 > /var/msgs/bounds
34237899Snectarfi
34337899Snectar
34413071Sjkh# for each valid dir in $local_startup, search for init scripts matching *.sh
34513071Sjkhif [ "X${local_startup}" != X"NO" ]; then
34627365Sjkh	echo -n 'Local package initialization:'
34713071Sjkh	for dir in ${local_startup}; do
34813071Sjkh		[ -d ${dir} ] && for script in ${dir}/*.sh; do
34913071Sjkh			[ -x ${script} ] && ${script} start
35013071Sjkh		done
35110873Sjkh	done
35216391Sjkh	echo .
3537259Sjkhfi
35437Srgrimes
35539162Ssos# Run rc.devfs if present to customify devfs
35639162Ssos[ -f /etc/rc.devfs ] && sh /etc/rc.devfs
35739162Ssos
35810873Sjkh# Do traditional (but rather obsolete) rc.local file if it exists.
35926934Spst[ -f /etc/rc.local ] && sh /etc/rc.local
36010873Sjkh
36137106Sjkoshy# Raise kernel security level.  This should be done only after `fsck' has
36237106Sjkoshy# repaired local file systems if you want the securelevel to be greater than 1.
36339030Sjraynardif [ "X${kern_securelevel_enable}" = X"YES" -a "${kern_securelevel}" -ge 0 ]; 
36437106Sjkoshythen
36537106Sjkoshy	echo 'Raising kernel security level'
36637106Sjkoshy	sysctl -w kern.securelevel=${kern_securelevel}
36737106Sjkoshyfi
36837106Sjkoshy
36937Srgrimesdate
37037Srgrimesexit 0
371