rc revision 41704
140123Sdes#!/bin/sh
241704Sdillon#	$Id: rc,v 1.162 1998/12/11 08:25:12 jb 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
19425339Sjkhecho '.'
19525339Sjkh
19632340Sjoerg# enable dumpdev so that savecore can see it
19732340Sjoerg# /var/crash should be a directory or a symbolic link
19832340Sjoerg# to the crash directory if core dumps are to be saved.
19932340Sjoergif [ "X${dumpdev}" != X"NO" -a -e ${dumpdev} -a -d /var/crash ]; then
20032340Sjoerg	dumpon ${dumpdev}
20132340Sjoerg	echo -n checking for core dump...
20232340Sjoerg	savecore /var/crash
20332340Sjoergfi
20432340Sjoerg
20525184Sjkhif [ -n "$network_pass1_done" ]; then
20639384Sbrian	network_pass2
207857Sdgfi
20837Srgrimes
20918812Speter# Check the quotas (must be after ypbind if using NIS)
21018812Speterif [ "X${check_quotas}" = X"YES" ]; then
21118812Speter	echo -n 'checking quotas:'
21218812Speter	quotacheck -a
21318812Speter	echo ' done.'
21418812Speter	quotaon -a
2157238Sachefi
2167238Sache
21725184Sjkhif [ -n "$network_pass2_done" ]; then
21839384Sbrian	network_pass3
2197477Sachefi
2207477Sache
2217238Sache
2227487Srgrimes# build ps databases
2237487Srgrimeskvm_mkdb 
2247487Srgrimesdev_mkdb
2257487Srgrimes
2267487Srgrimes# check the password temp/lock file
2277487Srgrimesif [ -f /etc/ptmp ]
2287487Srgrimesthen
2297487Srgrimes	logger -s -p auth.err \
2307487Srgrimes	"password file may be incorrect -- /etc/ptmp exists"
2317238Sachefi
2327238Sache
23325184Sjkhif [ "X${accounting_enable}" = X"YES" -a -d /var/account ]; then
23411992Sache	echo 'turning on accounting'
23511992Sache	if [ ! -e /var/account/acct ]; then
23625412Sjkh		touch /var/account/acct
23711992Sache	fi
23811992Sache	accton /var/account/acct
2397238Sachefi
2407238Sache
24127365Sjkh# Make shared lib searching a little faster.  Leave /usr/lib first if you
24227365Sjkh# add your own entries or you may come to grief.
24338512Sgpalmerif [ -x /sbin/ldconfig ]; then
24439329Sjdp	if [ X"`/usr/bin/objformat`" = X"elf" ]; then
24539329Sjdp		_LDC=/usr/lib
24639329Sjdp		for i in $ldconfig_paths; do
24739329Sjdp			if test -d $i; then
24839329Sjdp				_LDC="${_LDC} $i"
24939329Sjdp			fi
25039329Sjdp		done
25139329Sjdp		echo 'setting ELF ldconfig path:' ${_LDC}
25239329Sjdp		ldconfig -elf ${_LDC}
25339329Sjdp	fi
25439329Sjdp
25541648Sjb	# Legacy aout support for i386 only
25641676Sjb	if [ X"`sysctl -n hw.machine`" = X"i386" ]; then
25741648Sjb		# Default the a.out ldconfig path, in case the system's
25841648Sjb		# /etc/rc.conf hasn't been updated.
25941648Sjb		: ${ldconfig_paths_aout=${ldconfig_paths}}
26041648Sjb		_LDC=/usr/lib/aout
26141648Sjb		for i in $ldconfig_paths_aout; do
26241648Sjb			if test -d $i; then
26341648Sjb				_LDC="${_LDC} $i"
26441648Sjb			fi
26541648Sjb		done
26641648Sjb		echo 'setting a.out ldconfig path:' ${_LDC}
26741648Sjb		ldconfig -aout ${_LDC}
26841648Sjb	fi
26938512Sgpalmerfi
2707296Sjkh
27117210Spst# Now start up miscellaneous daemons that don't belong anywhere else
27217210Spst#
27325339Sjkhecho -n starting standard daemons:
27429343Sbrianif [ "X${inetd_enable}" != X"NO" ]; then
27526727Spst	echo -n ' inetd';	inetd ${inetd_flags}
27626727Spstfi
27717210Spst
27829343Sbrianif [ "X${cron_enable}" != X"NO" ]; then
27926727Spst	echo -n ' cron';	cron
28026727Spstfi
28126727Spst
28225184Sjkhif [ "X${lpd_enable}" = X"YES" ]; then
28325916Sjkh	echo -n ' printer';		lpd ${lpd_flags}
28417210Spstfi
28517210Spst
28625184Sjkhif [ "X${sendmail_enable}" = X"YES" -a -r /etc/sendmail.cf ]; then
28725530Sjkh	echo -n ' sendmail';	/usr/sbin/sendmail ${sendmail_flags}
28817161Spstfi
28917161Spst
29017161Spstecho '.'
29117161Spst
2927487Srgrimes# configure implementation specific stuff
2937487Srgrimesarch=`uname -m`
29425469Sandreasif [ -f /etc/rc.${arch} ]; then
29525469Sandreas	. /etc/rc.${arch}
29625469Sandreasfi
2977487Srgrimes
29816671Spst# Recover vi editor files.
29919314Spetervibackup=`echo /var/tmp/vi.recover/vi.*`
30019314Speterif [ "$vibackup" != '/var/tmp/vi.recover/vi.*' ]; then
30116671Spst	echo 'Recovering vi editor sessions'
30219314Speter	for i in $vibackup; do
30319314Speter		# Only test files that are readable.
30419314Speter		if test ! -r $i; then
30519314Speter			continue
30619314Speter		fi
30719314Speter
30819314Speter		# Unmodified nvi editor backup files either have the
30919314Speter		# execute bit set or are zero length.  Delete them.
31019314Speter		if test -x $i -o ! -s $i; then
31119314Speter			rm -f $i
31219314Speter		fi
31316671Spst	done
31419314Speter
31519314Speter	# It is possible to get incomplete recovery files, if the editor
31619314Speter	# crashes at the right time.
31719314Speter	virecovery=`echo /var/tmp/vi.recover/recover.*`
31819314Speter	if [ "$virecovery" != "/var/tmp/vi.recover/recover.*" ]; then
31919314Speter		for i in $virecovery; do
32019314Speter			# Only test files that are readable.
32119314Speter			if test ! -r $i; then
32219314Speter				continue
32319314Speter			fi
32419314Speter
32519314Speter			# Delete any recovery files that are zero length,
32619314Speter			# corrupted, or that have no corresponding backup file.
32719314Speter			# Else send mail to the user.
32819314Speter			recfile=`awk '/^X-vi-recover-path:/{print $2}' < $i`
32919314Speter			if test -n "$recfile" -a -s "$recfile"; then
33019314Speter				sendmail -t < $i
33119314Speter			else
33219314Speter				rm -f $i
33319314Speter			fi
33419314Speter		done
33519314Speter	fi
33616671Spstfi
33716671Spst
33837899Snectar# make a bounds file for msgs(1) if there isn't one already
33937899Snectarif [ ! -f /var/msgs/bounds ]; then
34037899Snectar	echo 0 > /var/msgs/bounds
34137899Snectarfi
34237899Snectar
34313071Sjkh# for each valid dir in $local_startup, search for init scripts matching *.sh
34413071Sjkhif [ "X${local_startup}" != X"NO" ]; then
34527365Sjkh	echo -n 'Local package initialization:'
34613071Sjkh	for dir in ${local_startup}; do
34713071Sjkh		[ -d ${dir} ] && for script in ${dir}/*.sh; do
34839824Scracauer			[ -x ${script} ] && \
34939824Scracauer				(trap 'exit 1' 2 ; ${script} start ; echo -n)
35013071Sjkh		done
35110873Sjkh	done
35216391Sjkh	echo .
3537259Sjkhfi
35437Srgrimes
35541704Sdillonif [ "X${update_motd}" != X"NO" ]; then
35641704Sdillon	T=/tmp/_motd
35741704Sdillon	rm -f $T
35841704Sdillon	uname -v | sed -e 's,^\([^#]*\) #\(.* [1-2][0-9][0-9][0-9]\).*/\([^\]*\) $,\1 (\3) #\2,' > $T
35941704Sdillon	awk '{if (NR == 1) {if ($1 == "FreeBSD") {next} else {print "\n"$0}} else {print}}' < /etc/motd >> $T
36041704Sdillon	cp $T /etc/motd
36141704Sdillon	chmod 644 /etc/motd
36241704Sdillon	rm -f $T
36341704Sdillonfi
36441704Sdillon
36539162Ssos# Run rc.devfs if present to customify devfs
36639162Ssos[ -f /etc/rc.devfs ] && sh /etc/rc.devfs
36739162Ssos
36841704Sdillon# Do traditional (but rather obsolete) rc.local file if it exists.  If you
36941704Sdillon# use this file and want to make it programmatic, source /etc/rc.conf in
37041704Sdillon# /etc/rc.local and add your custom variables to /etc/rc.conf.local, as
37141704Sdillon# shown below.  Please do not put local extensions into /etc/rc itself. 
37241704Sdillon# Use /etc/rc.local
37341704Sdillon#
37441704Sdillon# ---- rc.local  ----
37541704Sdillon#     if [ -f /etc/rc.conf ]; then
37641704Sdillon#             . /etc/rc.conf
37741704Sdillon#     fi
37841704Sdillon#
37941704Sdillon#     ... additional startup conditionals ...
38041704Sdillon# ---- rc.local  ----
38141704Sdillon#
38210873Sjkh
38341704Sdillonif [ -f /etc/rc.local ]; then
38441704Sdillon    echo -n 'starting local daemons:'
38541704Sdillon    sh /etc/rc.local
38641704Sdillon    echo '.'
38741704Sdillonfi
38841704Sdillon
38937106Sjkoshy# Raise kernel security level.  This should be done only after `fsck' has
39037106Sjkoshy# repaired local file systems if you want the securelevel to be greater than 1.
39139030Sjraynardif [ "X${kern_securelevel_enable}" = X"YES" -a "${kern_securelevel}" -ge 0 ]; 
39237106Sjkoshythen
39337106Sjkoshy	echo 'Raising kernel security level'
39437106Sjkoshy	sysctl -w kern.securelevel=${kern_securelevel}
39537106Sjkoshyfi
39637106Sjkoshy
39737Srgrimesdate
39837Srgrimesexit 0
399