rc revision 20828
160812Sps#!/bin/sh
260786Sps#	$Id: rc,v 1.107 1996/12/19 18:06:35 joerg Exp $
360786Sps#	From: @(#)rc	5.27 (Berkeley) 6/5/91
460786Sps
560786Sps# System startup script run by init on autoboot
660786Sps# or after single-user.
760786Sps# Output and error are redirected to console by init,
860786Sps# and the console is the controlling terminal.
960786Sps
1060786Sps# Note that almost all the user-configurable behavior is no longer in
1160786Sps# this file, but rather in /etc/sysconfig.  Please check this file
1260786Sps# first before contemplating any changes here.
1360786Sps
1460786Spsstty status '^T'
1560786Sps
1660786Sps# Set shell to ignore SIGINT (2), but not children;
1760786Sps# shell catches SIGQUIT (3) and returns to single user after fsck.
1860786Spstrap : 2
1960786Spstrap : 3	# shouldn't be needed
2060786Sps
2160786SpsHOME=/; export HOME
2260786SpsPATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin
2360786Spsexport PATH
2460786Sps
2560786Sps# Configure ccd devices.
2660812Spsif [ -f /etc/ccd.conf ]
2760786Spsthen
2860786Sps	ccdconfig -C
2960786Spsfi
3060786Sps
3160786Spsswapon -a
3260786Sps
3360786Spsif [ $1x = autobootx ]
3460786Spsthen
3560786Sps	echo Automatic reboot in progress...
3660786Sps	fsck -p
3760786Sps	case $? in
3860786Sps	0)
3960786Sps		;;
4060786Sps	2)
4160786Sps		exit 1
4260786Sps		;;
4360786Sps	4)
4460786Sps		reboot
4560786Sps		echo "reboot failed... help!"
4660786Sps		exit 1
4760786Sps		;;
4860786Sps	8)
4960786Sps		echo "Automatic file system check failed... help!"
5060786Sps		exit 1
5160786Sps		;;
5260786Sps	12)
5360786Sps		echo "Reboot interrupted"
5460786Sps		exit 1
5560786Sps		;;
5660812Sps	130)
5763131Sps		# interrupt before catcher installed
5860786Sps		exit 1
5960786Sps		;;
6060786Sps	*)
6160786Sps		echo "Unknown error in reboot"
6260786Sps		exit 1
6360786Sps		;;
6460786Sps	esac
6560786Spselse
6660786Sps	echo Skipping disk checks ...
6760786Spsfi
6860786Sps
6960786Spstrap "echo 'Reboot interrupted'; exit 1" 3
7060786Sps
7160786Sps# root must be read/write both for NFS diskless and for VFS LKMs before
7260786Sps# proceeding any further.
7360786Spsmount -u -o rw /
7460786Spsif [ $? != 0 ]; then
7560786Sps	echo "Filesystem mount failed, startup aborted"
7660786Sps	exit 1
7760786Spsfi
7860786Sps
7960786Spsumount -a >/dev/null 2>&1
8060786Sps
8160786Spsmount -a -t nonfs
8260786Spsif [ $? != 0 ]; then
8360786Sps	echo "Filesystem mount failed, startup aborted"
8460786Sps	exit 1
8560786Spsfi
8660786Sps
8760786Spsadjkerntz -i
8860786Sps
8960786Sps# If there is a global system configuration file, suck it in.
9060786Spsif [ -f /etc/sysconfig ]; then
9160786Sps	. /etc/sysconfig
9260786Spsfi
9360786Sps
9460786Sps# Add additional swapfile, if configured.
9560786Spsif [ "x$swapfile" != "xNO" -a -w "$swapfile" -a -b /dev/vn0b ]; then
9660786Sps	echo "Adding $swapfile as additional swap."
9760786Sps	/usr/sbin/vnconfig /dev/vn0b $swapfile && swapon /dev/vn0b
9860786Spsfi
9960786Sps
10060786Sps# configure serial devices
10160786Spsif [ -f /etc/rc.serial ]; then
10260786Sps	. /etc/rc.serial
10360786Spsfi
10460786Sps
10560786Sps# start up PC-card configuration
10660786Spsif [ -f /etc/rc.pccard ]; then
10760786Sps	. /etc/rc.pccard
10860786Spsfi
10960786Sps
11060786Sps# start up the network
11160786Spsif [ -f /etc/netstart ]; then
11260786Sps	sh /etc/netstart
11360786Spsfi
11460786Sps
11560786Spsmount -a -t nfs >/dev/null 2>&1
11660786Sps
11760786Sps# Whack the pty perms back into shape.
11860786Spschmod 666 /dev/tty[pqrsPQRS]*
11960786Sps
12060786Sps# clean up left-over files
12160786Spsrm -f /etc/nologin
12260786Spsrm -f /var/spool/lock/*
12360786Spsrm -rf /var/spool/uucp/.Temp/*
12460786Sps(cd /var/run && { cp /dev/null utmp; chmod 644 utmp; })
12560786Sps
12660786Sps#
12760786Sps# Clearing /tmp at boot-time is essentially stupid, but seems to have
12860786Sps# a long tradition.  It doesn't help in any way for long-living systems,
12960786Sps# and it might accidentally clobber files you would rather like to have
13060786Sps# preserved after a crash (if not using mfs /tmp anyway).
13160786Sps#
13260786Sps# See also the commented out example of another cleanup policy in
13360786Sps# /etc/daily.
13460786Sps#
13560786Spsecho clearing /tmp
13660786Sps
13760786Sps# prune quickly with one rm, then use find to clean up /tmp/[lq]*
13860786Sps# (not needed with mfs /tmp, but doesn't hurt there...)
13960786Sps(cd /tmp && rm -rf [a-km-pr-zA-Z]* &&
14060786Sps    find -d . ! -name . ! -name lost+found ! -name quotas -exec rm -rf -- {} \;)
14160786Sps
14260786Sps# The above is even more stupid since it prevents you from restarting
14360786Sps# X11 after a system crash.  If you disable the above, make sure to
14460786Sps# uncomment the line below.
14560786Sps#
14660786Sps# clean up leftover X lock files and local connection sockets
14760786Sps#rm -f /tmp/.X*-lock /tmp/.X11-unix/*
14860786Sps
14960786Sps
15060786Sps# enable dumpdev so that savecore can see it
15160786Spsif [ "X${dumpdev}" != X"NO" ]; then
15260786Sps	dumpon ${dumpdev}
15360786Spsfi
15460786Sps
15560786Sps# /var/crash should be a directory or a symbolic link
15660786Sps# to the crash directory if core dumps are to be saved.
15760786Spsif [ "X${savecore}" = X"YES" -a -d /var/crash ]; then
15860786Sps	echo -n checking for core dump...
15960786Sps	savecore /var/crash
16060786Spsfi
16160786Sps
16260786Sps# snapshot any kernel -c changes back to disk
16360786Spsecho 'recording kernel -c changes'
16460786Sps/sbin/dset -q
16560786Sps
16660786Sps# start system logging and name service (named needs to start before syslogd
16760786Sps# if you don't have a /etc/resolv.conf)
16860786Sps#
16960786Spsecho -n starting system daemons:
17060786Sps
17160786Sps# Transitional symlink (for the next couple of years :) until all
17260786Sps# binaries had a chance to move towards /var/run/log.
17360786Spsif [ ! -h /dev/log ] ; then
17460786Sps	# might complain for r/o root f/s
17560786Sps	ln -sf /var/run/log /dev/log
17660786Spsfi
17760786Spsrm -f /var/run/log
17860786Spsecho ' syslogd.';			syslogd
17960786Sps
18060786Spsecho -n starting early network daemons:
18160786Sps
18260786Sps# $namedflags is imported from /etc/sysconfig
18360786Spsif [ "X${namedflags}" != X"NO" ]; then
18460786Sps	echo -n ' named';		named $namedflags
18560786Spsfi
18660786Sps
18760786Sps# $ntpdate and $xntpdflags are imported from /etc/sysconfig.
18860786Sps# If $ntpdate != NO, run ntpdate $ntpdate to set the date correctly.
18960786Sps# If $xntpdflags != NO, start xntpd.
19060786Spsif [ "X${ntpdate}" != X"NO" -o "X${xntpdflags}" != X"NO" ]; then
19160786Sps	if [ "X${tickadjflags}" != X"NO" ]; then
19260786Sps		echo -n ' tickadj';	tickadj ${tickadjflags--Aq}
19360786Sps	fi
19460786Sps
19560786Sps	if [ "X${ntpdate}" != X"NO" ]; then
19660786Sps		echo -n ' ntpdate';	ntpdate ${ntpdate} >/dev/null 2>&1
19760786Sps	fi
19860786Sps
19960786Sps	if [ "X${xntpdflags}" != X"NO" ]; then
20060786Sps		echo -n ' xntpd';	xntpd ${xntpdflags}
20160786Sps	fi
20260786Spsfi
20360786Sps
20460786Sps# $timedflags is imported from /etc/sysconfig;
20560786Sps# if $timedflags == NO, timed isn't run.
20660786Spsif [ "X${timedflags}" != X"NO" ]; then
20760786Sps	echo -n ' timed'; timed $timedflags
20860786Spsfi
20960786Sps
21060786Sps# Portmapper should always be run, to provide RPC services for inetd.
21160786Spsif [ -x /usr/sbin/portmap ]; then
21260786Sps	echo -n ' portmap';		portmap
21360786Spsfi
21460786Sps
21560786Sps# Start ypserv if we're an NIS server.
21660786Sps# Run rpc.ypxfrd and rpc.yppasswdd only on the NIS master server.
21760786Spsif [ "X${nis_serverflags}" != X"NO" ]; then
21860786Sps	echo -n ' ypserv'; ypserv ${nis_serverflags}
21960786Sps
22060786Sps	if [ "X${ypxfrdflags}" != X"NO" ]; then
22160786Sps		echo -n ' rpc.ypxfrd'; rpc.ypxfrd ${ypxfrdflags}
22260786Sps	fi
22360786Sps
22460786Sps	if [ "X${yppasswddflags}" != X"NO" ]; then
22560786Sps		echo -n ' rpc.yppasswdd'; rpc.yppasswdd ${yppasswddflags}
22660786Sps	fi
22760786Spsfi
22860786Sps
22960786Sps# Start ypbind if we're an NIS client
23060786Spsif [ "X${nis_clientflags}" != X"NO" ]; then
23160786Sps	echo -n ' ypbind'; ypbind ${nis_clientflags}
23260786Sps	if [ "X${nis_ypsetflags}" != X"NO" ]; then
23360786Sps		echo -n ' ypset'; ypset ${nis_ypsetflags}
23460786Sps	fi
23560786Spsfi
23660786Sps
23760786Spsecho '.'
23860786Sps
23960786Sps# Check the quotas (must be after ypbind if using NIS)
24060786Spsif [ "X${check_quotas}" = X"YES" ]; then
24160786Sps	echo -n 'checking quotas:'
24260786Sps	quotacheck -a
24360786Sps	echo ' done.'
24460786Sps	quotaon -a
24560786Spsfi
24660786Sps
24760786Spsecho -n starting other network daemons:
24860786Sps
24960786Spsif [ "X${nfs_server}" = X"YES" -a -r /etc/exports ]; then
25060786Sps	echo -n ' mountd'
25160786Sps	if [ "X${weak_mountd_authentication}" = X"YES" ]; then
25260786Sps		mountd -n
25360786Sps	else
25460786Sps		mountd
25560786Sps	fi
25660786Sps	echo -n ' nfsd';		nfsd -u -t 4
25760786Sps# Warning: rpc.lockd is broken.
25860786Sps# Only uncomment this line if the consequences are fully understood.
25960786Sps#	echo -n ' rpc.lockd';		rpc.lockd
26060786Sps	echo -n ' rpc.statd';		rpc.statd
26160786Spsfi
26260786Sps
26360786Spsif [ "X${nfs_client}" = X"YES" ]; then
26460786Sps	echo -n ' nfsiod';		nfsiod -n 4
26560786Spsfi
26660786Sps
26760786Spsif [ "X${amdflags}" != X"NO" ]; then
26860786Sps	echo -n ' amd'
26960786Sps	amd -p ${amdflags} > /var/run/amd.pid
27060786Spsfi
27160786Sps
27260786Sps# $rwhod is imported from /etc/sysconfig;
27360786Sps# if $rwhod is set to YES, rwhod is run.
27460786Spsif [ "X${rwhod}" = X"YES" ]; then
27560786Sps	echo -n ' rwhod';	rwhod
27660786Spsfi
27760786Sps
27860786Sps# Kerberos runs ONLY on the Kerberos server machine
27960786Spsif [ "X${kerberos_server}" = X"YES" ]; then
28060786Sps	echo -n ' kerberos';	kerberos >> /var/log/kerberos.log &
28160786Sps	echo -n ' kadmind'; \
28260786Sps		(sleep 20; kadmind -n >/dev/null 2>&1 &) &
28360786Spsfi
28460786Sps
28560786Sps# IP multicast routing daemon
28660786Spsif [ "X${mrouted}" != X"NO" -a -x /usr/sbin/mrouted ]; then
28760786Sps	echo -n ' mrouted'; mrouted ${mrouted}
28860786Spsfi
28960786Sps
29060786Spsecho '.'
29160786Sps
29260786Sps# build ps databases
29360786Spskvm_mkdb 
29460786Spsdev_mkdb
29560786Sps
29660786Sps# check the password temp/lock file
29760786Spsif [ -f /etc/ptmp ]
29860786Spsthen
29960786Sps	logger -s -p auth.err \
30060786Sps	"password file may be incorrect -- /etc/ptmp exists"
30160786Spsfi
30260786Sps
30360786Spsif [ "X${accounting}" = X"YES" -a -d /var/account ]; then
30460786Sps	echo 'turning on accounting'
30560786Sps	if [ ! -e /var/account/acct ]; then
30660786Sps		touch /var/account/acct
30760786Sps	fi
30860786Sps	accton /var/account/acct
30960786Spsfi
31060786Sps
31160786Sps# Make shared lib searching a little faster.  Leave /usr/lib first if you
31260786Sps# add your own entries or you may come to grief.
31360786Spsif [ -x /sbin/ldconfig ]; then
31460786Sps	_LDC=/usr/lib
31560786Sps	if [ -d /usr/lib/compat ]; then _LDC="${_LDC} /usr/lib/compat" ; fi
31660786Sps	if [ -d /usr/X11R6/lib ]; then _LDC="${_LDC} /usr/X11R6/lib" ; fi
31760786Sps	if [ -d /usr/X386/lib ]; then _LDC="${_LDC} /usr/X386/lib" ; fi
31860786Sps	if [ -d /usr/local/lib ]; then _LDC="${_LDC} /usr/local/lib" ; fi
31960786Sps	echo 'setting ldconfig path:' ${_LDC}
32060786Sps	ldconfig ${_LDC}
32160786Spsfi
32260786Sps
32360786Sps# Now start up miscellaneous daemons that don't belong anywhere else
32460786Sps#
32560786Spsecho -n standard daemons:
32660786Spsecho -n ' inetd';		inetd
32760786Spsecho -n ' cron';		cron
32860786Sps
32960786Spsif [ "X${lpd}" != X"NO" -a -x /usr/sbin/lpd ]; then
33060786Sps	echo -n ' printer';		lpd
33160786Spsfi
33260786Sps
33360786Sps# $sendmail_flags is imported from /etc/sysconfig;
33460786Sps# if $sendmail_flags is something other than NO, sendmail is run.
33560786Spsif [ "X${sendmail_flags}" != X"NO" -a -r /etc/sendmail.cf ]; then
33660786Sps	echo -n ' sendmail';            /usr/sbin/sendmail ${sendmail_flags}
33760786Spsfi
33860786Sps
33960786Spsecho '.'
34060786Sps
34160786Sps# configure implementation specific stuff
34260786Spsarch=`uname -m`
34360786Spsif [ -f /etc/rc.${arch} ]; then
34460786Sps	. /etc/rc.${arch}
34560786Spsfi
34660786Sps
34760786Sps# Recover vi editor files.
34860786Spsvibackup=`echo /var/tmp/vi.recover/vi.*`
34960786Spsif [ "$vibackup" != '/var/tmp/vi.recover/vi.*' ]; then
35060786Sps	echo 'Recovering vi editor sessions'
35160786Sps	for i in $vibackup; do
35260786Sps		# Only test files that are readable.
35360786Sps		if test ! -r $i; then
35460786Sps			continue
35560786Sps		fi
35660786Sps
35760786Sps		# Unmodified nvi editor backup files either have the
35860786Sps		# execute bit set or are zero length.  Delete them.
35960786Sps		if test -x $i -o ! -s $i; then
36060786Sps			rm -f $i
36160786Sps		fi
36260786Sps	done
36360786Sps
36460786Sps	# It is possible to get incomplete recovery files, if the editor
36560786Sps	# crashes at the right time.
36660786Sps	virecovery=`echo /var/tmp/vi.recover/recover.*`
36760786Sps	if [ "$virecovery" != "/var/tmp/vi.recover/recover.*" ]; then
36860786Sps		for i in $virecovery; do
36960786Sps			# Only test files that are readable.
37060786Sps			if test ! -r $i; then
37160786Sps				continue
37260786Sps			fi
37360786Sps
37460786Sps			# Delete any recovery files that are zero length,
37560786Sps			# corrupted, or that have no corresponding backup file.
37660786Sps			# Else send mail to the user.
37760786Sps			recfile=`awk '/^X-vi-recover-path:/{print $2}' < $i`
37860786Sps			if test -n "$recfile" -a -s "$recfile"; then
37960786Sps				sendmail -t < $i
38060786Sps			else
38160786Sps				rm -f $i
38260786Sps			fi
38360786Sps		done
38460786Sps	fi
38560786Spsfi
38660786Sps
38760786Sps# for each valid dir in $local_startup, search for init scripts matching *.sh
38860786Spsif [ "X${local_startup}" != X"NO" ]; then
38960786Sps	echo -n 'Local package startup:'
39060786Sps	for dir in ${local_startup}; do
39160786Sps		[ -d ${dir} ] && for script in ${dir}/*.sh; do
39260786Sps			[ -x ${script} ] && ${script} start
39360786Sps		done
39460786Sps	done
39560786Sps	echo .
39660786Spsfi
39760786Sps
39860786Sps# Do traditional (but rather obsolete) rc.local file if it exists.
39960786Sps[ -f /etc/rc.local ] && sh /etc/rc.local
40060786Sps
40160786Spsdate
40260786Spsexit 0
40360786Sps