rc revision 25184
1709Swollman#!/bin/sh
225184Sjkh#	$Id: rc,v 1.116 1997/04/09 20:14:59 guido 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
8725184Sjkh    . /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
9821197Sphk# Keep a copy of the boot messages around
9925184Sjkhdmesg > /var/run/dmesg.boot
10021197Sphk
1017219Sjkh
10217767Sjkh# Add additional swapfile, if configured.
10319363Sjoergif [ "x$swapfile" != "xNO" -a -w "$swapfile" -a -b /dev/vn0b ]; then
10417767Sjkh	echo "Adding $swapfile as additional swap."
10525184Sjkh	vnconfig /dev/vn0b $swapfile && swapon /dev/vn0b
10617767Sjkhfi
10717767Sjkh
1081675Sache# configure serial devices
1097219Sjkhif [ -f /etc/rc.serial ]; then
1107293Sjkh	. /etc/rc.serial
1111675Sachefi
1121675Sache
11314596Snate# start up PC-card configuration
11414624Snateif [ -f /etc/rc.pccard ]; then
11514624Snate	. /etc/rc.pccard
11614596Snatefi
11714596Snate
11825184Sjkh# start up the initial network configuration.
11925184Sjkhif [ -f /etc/rc.network ]; then
12025184Sjkh	. /etc/rc.network	# We only need to do this once.
12125184Sjkh	network_pass1
1227460Sjkhfi
1237460Sjkh
1248540Srgrimesmount -a -t nfs >/dev/null 2>&1
1257487Srgrimes
1267487Srgrimes# Whack the pty perms back into shape.
12720828Sjoergchmod 666 /dev/tty[pqrsPQRS]*
1287487Srgrimes
1297487Srgrimes# clean up left-over files
1307487Srgrimesrm -f /etc/nologin
1317487Srgrimesrm -f /var/spool/lock/*
1327761Sacherm -rf /var/spool/uucp/.Temp/*
13315684Sjkh(cd /var/run && { cp /dev/null utmp; chmod 644 utmp; })
1347487Srgrimes
13516588Sjoerg#
13616588Sjoerg# Clearing /tmp at boot-time is essentially stupid, but seems to have
13716588Sjoerg# a long tradition.  It doesn't help in any way for long-living systems,
13816588Sjoerg# and it might accidentally clobber files you would rather like to have
13916588Sjoerg# preserved after a crash (if not using mfs /tmp anyway).
14016588Sjoerg#
14116588Sjoerg# See also the commented out example of another cleanup policy in
14216588Sjoerg# /etc/daily.
14316588Sjoerg#
1447487Srgrimesecho clearing /tmp
1457487Srgrimes
1467487Srgrimes# prune quickly with one rm, then use find to clean up /tmp/[lq]*
1477487Srgrimes# (not needed with mfs /tmp, but doesn't hurt there...)
1487487Srgrimes(cd /tmp && rm -rf [a-km-pr-zA-Z]* &&
1497487Srgrimes    find -d . ! -name . ! -name lost+found ! -name quotas -exec rm -rf -- {} \;)
1507487Srgrimes
15116588Sjoerg# The above is even more stupid since it prevents you from restarting
15216588Sjoerg# X11 after a system crash.  If you disable the above, make sure to
15316588Sjoerg# uncomment the line below.
15416588Sjoerg#
15516588Sjoerg# clean up leftover X lock files and local connection sockets
15616588Sjoerg#rm -f /tmp/.X*-lock /tmp/.X11-unix/*
15716588Sjoerg
15816588Sjoerg
1599305Sbde# enable dumpdev so that savecore can see it
1609305Sbdeif [ "X${dumpdev}" != X"NO" ]; then
1619305Sbde	dumpon ${dumpdev}
1629305Sbdefi
1639305Sbde
1647487Srgrimes# /var/crash should be a directory or a symbolic link
1657487Srgrimes# to the crash directory if core dumps are to be saved.
16623939Sjoergif [ -d /var/crash ]; then
1677487Srgrimes	echo -n checking for core dump...
1687487Srgrimes	savecore /var/crash
1697487Srgrimesfi
1707487Srgrimes
1717487Srgrimes# snapshot any kernel -c changes back to disk
1727487Srgrimesecho 'recording kernel -c changes'
1737487Srgrimes/sbin/dset -q
1747487Srgrimes
1757487Srgrimes# start system logging and name service (named needs to start before syslogd
1767487Srgrimes# if you don't have a /etc/resolv.conf)
1777259Sjkh#
1787487Srgrimesecho -n starting system daemons:
1797487Srgrimes
18024463Spst# If syslogdflags == NO, syslog isn't run
18124463Spstif [ "X${syslogdflags}" != X"NO" ] ; then
18224463Spst
18324463Spst	# Transitional symlink (for the next couple of years :) until all
18424463Spst	# binaries had a chance to move towards /var/run/log.
18524463Spst	if [ ! -h /dev/log ] ; then
18624463Spst		# might complain for r/o root f/s
18724463Spst		ln -sf /var/run/log /dev/log
18824463Spst	fi
18924463Spst
19024463Spst	rm -f /var/run/log
19125184Sjkh	echo 'Starting syslogd.';		syslogd ${syslogd_flags}
19219226Sjoergfi
1937487Srgrimes
19425184Sjkhif [ -n "$network_pass1_done" ]; then
19525184Sjkh    network_pass2
196857Sdgfi
19737Srgrimes
19818812Speter# Check the quotas (must be after ypbind if using NIS)
19918812Speterif [ "X${check_quotas}" = X"YES" ]; then
20018812Speter	echo -n 'checking quotas:'
20118812Speter	quotacheck -a
20218812Speter	echo ' done.'
20318812Speter	quotaon -a
2047238Sachefi
2057238Sache
20625184Sjkhif [ -n "$network_pass2_done" ]; then
20725184Sjkh    network_pass3
2087477Sachefi
2097477Sache
2107238Sache
2117487Srgrimes# build ps databases
2127487Srgrimeskvm_mkdb 
2137487Srgrimesdev_mkdb
2147487Srgrimes
2157487Srgrimes# check the password temp/lock file
2167487Srgrimesif [ -f /etc/ptmp ]
2177487Srgrimesthen
2187487Srgrimes	logger -s -p auth.err \
2197487Srgrimes	"password file may be incorrect -- /etc/ptmp exists"
2207238Sachefi
2217238Sache
22225184Sjkhif [ "X${accounting_enable}" = X"YES" -a -d /var/account ]; then
22311992Sache	echo 'turning on accounting'
22411992Sache	if [ ! -e /var/account/acct ]; then
22521751Sjkh		touch /var/account/acct && chmod 600 /var/account/acct
22611992Sache	fi
22711992Sache	accton /var/account/acct
2287238Sachefi
2297238Sache
2307487Srgrimes# Make shared lib searching a little faster.  Leave /usr/lib first if you
2317487Srgrimes# add your own entries or you may come to grief.
23225184Sjkh_LDC=/usr/lib
23325184Sjkhif [ -d /usr/lib/compat ]; then _LDC="${_LDC} /usr/lib/compat" ; fi
23425184Sjkhif [ -d /usr/X11R6/lib ]; then _LDC="${_LDC} /usr/X11R6/lib" ; fi
23525184Sjkhif [ -d /usr/local/lib ]; then _LDC="${_LDC} /usr/local/lib" ; fi
23625184Sjkhecho 'setting ldconfig path:' ${_LDC}
23725184Sjkhldconfig ${_LDC}
2387296Sjkh
23917210Spst# Now start up miscellaneous daemons that don't belong anywhere else
24017210Spst#
24117210Spstecho -n standard daemons:
24218812Speterecho -n ' inetd';		inetd
24317210Spstecho -n ' cron';		cron
24417210Spst
24525184Sjkhif [ "X${lpd_enable}" = X"YES" ]; then
24617210Spst	echo -n ' printer';		lpd
24717210Spstfi
24817210Spst
24925184Sjkhif [ "X${sendmail_enable}" = X"YES" -a -r /etc/sendmail.cf ]; then
25025184Sjkh	echo -n ' sendmail';	sendmail ${sendmail_flags}
25117161Spstfi
25217161Spst
25317161Spstecho '.'
25417161Spst
2557487Srgrimes# configure implementation specific stuff
2567487Srgrimesarch=`uname -m`
25710895Sjkhif [ -f /etc/rc.${arch} ]; then
25810895Sjkh	. /etc/rc.${arch}
2597487Srgrimesfi
2607487Srgrimes
26116671Spst# Recover vi editor files.
26219314Spetervibackup=`echo /var/tmp/vi.recover/vi.*`
26319314Speterif [ "$vibackup" != '/var/tmp/vi.recover/vi.*' ]; then
26416671Spst	echo 'Recovering vi editor sessions'
26519314Speter	for i in $vibackup; do
26619314Speter		# Only test files that are readable.
26719314Speter		if test ! -r $i; then
26819314Speter			continue
26919314Speter		fi
27019314Speter
27119314Speter		# Unmodified nvi editor backup files either have the
27219314Speter		# execute bit set or are zero length.  Delete them.
27319314Speter		if test -x $i -o ! -s $i; then
27419314Speter			rm -f $i
27519314Speter		fi
27616671Spst	done
27719314Speter
27819314Speter	# It is possible to get incomplete recovery files, if the editor
27919314Speter	# crashes at the right time.
28019314Speter	virecovery=`echo /var/tmp/vi.recover/recover.*`
28119314Speter	if [ "$virecovery" != "/var/tmp/vi.recover/recover.*" ]; then
28219314Speter		for i in $virecovery; do
28319314Speter			# Only test files that are readable.
28419314Speter			if test ! -r $i; then
28519314Speter				continue
28619314Speter			fi
28719314Speter
28819314Speter			# Delete any recovery files that are zero length,
28919314Speter			# corrupted, or that have no corresponding backup file.
29019314Speter			# Else send mail to the user.
29119314Speter			recfile=`awk '/^X-vi-recover-path:/{print $2}' < $i`
29219314Speter			if test -n "$recfile" -a -s "$recfile"; then
29319314Speter				sendmail -t < $i
29419314Speter			else
29519314Speter				rm -f $i
29619314Speter			fi
29719314Speter		done
29819314Speter	fi
29916671Spstfi
30016671Spst
30113071Sjkh# for each valid dir in $local_startup, search for init scripts matching *.sh
30213071Sjkhif [ "X${local_startup}" != X"NO" ]; then
30316391Sjkh	echo -n 'Local package startup:'
30413071Sjkh	for dir in ${local_startup}; do
30513071Sjkh		[ -d ${dir} ] && for script in ${dir}/*.sh; do
30613071Sjkh			[ -x ${script} ] && ${script} start
30713071Sjkh		done
30810873Sjkh	done
30916391Sjkh	echo .
3107259Sjkhfi
31137Srgrimes
31210873Sjkh# Do traditional (but rather obsolete) rc.local file if it exists.
31310898Sjkh[ -f /etc/rc.local ] && sh /etc/rc.local
31410873Sjkh
31537Srgrimesdate
31637Srgrimesexit 0
317