rc revision 1.107
11.107Stron#	$NetBSD: rc,v 1.107 1999/01/04 00:49:36 tron Exp $
21.73Sperry#	originally from: @(#)rc	8.2 (Berkeley) 3/17/94
31.1Scgd
41.1Scgd# System startup script run by init on autoboot
51.1Scgd# or after single-user.
61.1Scgd# Output and error are redirected to console by init,
71.1Scgd# and the console is the controlling terminal.
81.1Scgd
91.1Scgdstty status '^T'
101.1Scgd
111.1Scgd# Set shell to ignore SIGINT (2), but not children;
121.1Scgd# shell catches SIGQUIT (3) and returns to single user after fsck.
131.1Scgdtrap : 2
141.1Scgdtrap : 3	# shouldn't be needed
151.1Scgd
161.68Smycroftexport HOME=/
171.96Sjonathanexport PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin
181.50Sthorpej
191.50Sthorpej# Configure ccd devices.
201.63Smrgif [ -f /etc/ccd.conf ]; then
211.50Sthorpej	ccdconfig -C
221.50Sthorpejfi
231.107Stron
241.107Stron# Configure raid devices.
251.107Stronfor dev in 0 1 2 3; do
261.107Stron	if [ -f /etc/raid$dev.conf ]; then
271.107Stron		raidctl -c /etc/raid$dev.conf raid$dev
281.107Stron		raidctl -r raid$dev
291.107Stron	fi
301.107Strondone
311.1Scgd
321.79Sthorpej# Add all block-type swap devices; these might be necessary
331.79Sthorpej# during disk checks.
341.79Sthorpejswapctl -A -t blk
351.79Sthorpej
361.63Smrgif [ -e /fastboot ]; then
371.38Scgd	echo "Fast boot: skipping disk checks."
381.68Smycroftelif [ "$1" = autoboot ]; then
391.38Scgd	echo "Automatic boot in progress: starting file system checks."
401.1Scgd	fsck -p
411.1Scgd	case $? in
421.1Scgd	0)
431.1Scgd		;;
441.1Scgd	2)
451.1Scgd		exit 1
461.1Scgd		;;
471.1Scgd	4)
481.35Scgd		echo "Rebooting..."
491.1Scgd		reboot
501.38Scgd		echo "Reboot failed; help!"
511.1Scgd		exit 1
521.1Scgd		;;
531.1Scgd	8)
541.38Scgd		echo "Automatic file system check failed; help!"
551.1Scgd		exit 1
561.1Scgd		;;
571.1Scgd	12)
581.38Scgd		echo "Boot interrupted."
591.1Scgd		exit 1
601.1Scgd		;;
611.1Scgd	130)
621.1Scgd		# interrupt before catcher installed
631.1Scgd		exit 1
641.1Scgd		;;
651.1Scgd	*)
661.38Scgd		echo "Unknown error; help!"
671.1Scgd		exit 1
681.1Scgd		;;
691.1Scgd	esac
701.1Scgdfi
711.1Scgd
721.38Scgdtrap "echo 'Boot interrupted.'; exit 1" 3
731.1Scgd
741.1Scgdumount -a >/dev/null 2>&1
751.83Sdrochnermount /
761.1Scgdrm -f /fastboot		# XXX (root now writeable)
771.40Scgd
781.90Sveegoif [ -f /etc/rc.subr ]; then
791.90Sveego	. /etc/rc.subr
801.89Scjselse
811.90Sveego	echo "Can't read /etc/rc.subr; aborting."
821.89Scjs	exit 1;
831.89Scjsfi
841.89Scjs
851.71Smycroftif [ -f /etc/rc.conf ]; then
861.63Smrg	. /etc/rc.conf
871.63Smrgfi
881.63Smrg
891.89Scjsif [ "$rc_configured" != YES ]; then
901.89Scjs	echo "/etc/rc.conf is not configured. Multiuser boot aborted."
911.89Scjs	exit 1
921.89Scjsfi
931.89Scjs
941.40Scgd# set flags on ttys.  (do early, in case they use tty for SLIP in netstart)
951.40Scgdecho 'setting tty flags'
961.40Scgdttyflags -a
971.1Scgd
981.83Sdrochner# load kernel modules specified in /etc/lkm.conf if the /usr filesystem
991.83Sdrochner# is already present with "/" or can be mounted now
1001.93Sdrochnerif checkyesno lkm && [ -f /etc/rc.lkm ]; then
1011.83Sdrochner	mount /usr >/dev/null 2>&1
1021.83Sdrochner	if [ -x /usr/bin/ld ]; then
1031.83Sdrochner		lkmstage=BEFORENET
1041.83Sdrochner		. /etc/rc.lkm
1051.83Sdrochner	fi
1061.63Smrgfi
1071.63Smrg
1081.1Scgd# set hostname, turn on network
1091.1Scgdecho 'starting network'
1101.76Sscottrsh /etc/netstart
1111.76Sscottrif [ $? -ne 0 ]; then
1121.76Sscottr	exit 1
1131.76Sscottrfi
1141.1Scgd
1151.95Sdrochnerfor fs in /usr /var $critical_filesystems; do
1161.95Sdrochner	mount | (
1171.95Sdrochner        		ismounted=no
1181.95Sdrochner        		while read what _on on _type type; do
1191.95Sdrochner               		 if [ $on = $fs ]; then
1201.95Sdrochner                        			ismounted=yes
1211.95Sdrochner               		 fi
1221.95Sdrochner        		done
1231.95Sdrochner       		if [ $ismounted = no ]; then
1241.95Sdrochner			mount $fs >/dev/null 2>&1
1251.95Sdrochner		fi
1261.95Sdrochner	)
1271.95Sdrochnerdone
1281.99Sveego
1291.99Sveego# Network Address Translation...
1301.100Slukemif checkyesno ipnat && [ -f /etc/ipnat.conf ]; then
1311.99Sveego	echo 'installing NAT rules ... '
1321.100Slukem	if ! checkyesno ipfilter || [ ! -f /etc/ipf.conf ]; then
1331.99Sveego		ipf -E -Fa
1341.99Sveego	fi
1351.99Sveego	ipnat -F -f /etc/ipnat.conf
1361.99Sveegofi
1371.79Sthorpej
1381.79Sthorpej# "Critical" file systems are now mounted.  Go ahead and swap
1391.79Sthorpej# to files now, since they will be residing in the critical file
1401.79Sthorpej# systems (or, at least, better).
1411.79Sthorpejswapctl -A -t noblk
1421.97Smrg
1431.97Smrg# Check for no swap, and warn about it unless that is desired.
1441.100Slukemif ! checkyesno no_swap; then
1451.97Smrg	swapctl -s | grep 'no swap devices configured' > /dev/null && \
1461.97Smrg		echo "WARNING:  no swap space configured!"
1471.97Smrgfi
1481.26Sderaadt
1491.41Sjtc# clean up left-over files
1501.41Sjtcrm -f /etc/nologin
1511.41Sjtcrm -f /var/spool/lock/LCK.*
1521.41Sjtcrm -f /var/spool/uucp/STST/*
1531.45Scgd(cd /var/run && { rm -rf -- *; install -c -m 664 -g utmp /dev/null utmp; })
1541.41Sjtc
1551.84Sveego# start the system logger first, so that all messages from daemons
1561.84Sveego# are logged, then start savecore to get a dump on low memory systems
1571.84Sveego# and then start the name server.
1581.63Smrg
1591.89Scjsif checkyesno syslogd; then
1601.63Smrg	echo 'starting system logger'
1611.63Smrg	rm -f /dev/log
1621.63Smrg	syslogd $syslogd_flags
1631.94Slukemfi
1641.94Slukem
1651.94Slukem# Enable ipmon (only useful if ipfilter is running)
1661.94Slukem# NOTE: requires the IPFILTER_LOG kernel option.
1671.94Slukemif checkyesno ipmon; then
1681.94Slukem	echo 'starting ipmon'
1691.94Slukem	ipmon $ipmon_flags &
1701.63Smrgfi
1711.63Smrg
1721.84Sveego# /var/crash should be a directory or a symbolic link
1731.84Sveego# to the crash directory if core dumps are to be saved.
1741.89Scjsif checkyesno savecore; then
1751.106Shubertf	if [ -d /var/crash/. ]; then
1761.89Scjs		echo checking for core dump...
1771.89Scjs		savecore $savecore_flags /var/crash
1781.89Scjs	else
1791.89Scjs		logger -s "WARNING: no /var/crash directory; savecore not run."
1801.84Sveego	fi
1811.84Sveegofi
1821.84Sveego
1831.89Scjsif checkyesno named; then
1841.89Scjs	echo 'starting name server';	named $named_flags
1851.89Scjsfi
1861.89Scjs
1871.89Scjs# set time, if requested
1881.89Scjsif checkyesno ntpdate; then
1891.91Smikel	if [ -z "$ntpdate_hosts" ]; then
1901.101Slukem		ntpdate_hosts=`awk '
1911.101Slukem		    /^server[ \t]*127.127/	{next}
1921.101Slukem		    /^server/			{print $2}
1931.101Slukem		' </etc/ntp.conf`
1941.89Scjs	fi
1951.89Scjs	if [ -n "$ntpdate_hosts"  ]; then
1961.89Scjs		echo 'Setting date via ntp.'
1971.102Slukem		ntpdate -b -s $ntpdate_hosts
1981.67Smycroft	fi
1991.63Smrgfi
2001.63Smrg
2011.84Sveego# now start the rpc servers, for YP server/client.
2021.63Smrgecho -n 'starting rpc daemons:'
2031.63Smrg
2041.63Smrg# note that portmap is generally required for all other rpc services.
2051.89Scjsif checkyesno portmap; then
2061.63Smrg	echo -n ' portmap';             portmap
2071.63Smrgfi
2081.63Smrg
2091.89Scjsif checkyesno ypserv; then
2101.63Smrg        echo -n ' ypserv';              ypserv $ypserv_flags
2111.63Smrgfi
2121.63Smrg
2131.89Scjsif checkyesno ypbind; then
2141.63Smrg        echo -n ' ypbind';              ypbind $ypbind_flags
2151.63Smrgfi
2161.63Smrg
2171.89Scjsif checkyesno yppasswdd; then
2181.63Smrg        echo -n ' rpc.yppasswdd';       rpc.yppasswdd $yppasswdd_flags
2191.63Smrgfi
2201.63Smrg
2211.89Scjsif checkyesno bootparamd; then
2221.89Scjs	if [ -r /etc/bootparams ]; then
2231.89Scjs		echo -n ' rpc.bootparamd'; rpc.bootparamd $bootparamd_flags
2241.89Scjs	else
2251.89Scjs		echo
2261.89Scjs		logger -s "WARNING: /etc/bootparams not found. " \
2271.89Scjs		    "bootparamd not started."
2281.67Smycroft	fi
2291.63Smrgfi
2301.63Smrg
2311.84Sveegoecho '.'
2321.84Sveego
2331.84Sveego# load kernel modules specified in /etc/lkm.conf
2341.89Scjsif checkyesno lkm; then
2351.89Scjs	if [ -r /etc/rc.lkm ]; then
2361.89Scjs		lkmstage=BEFOREMOUNT
2371.89Scjs		. /etc/rc.lkm
2381.89Scjs	else
2391.89Scjs		logger -s "WARNING: /etc/rc.lkm not found; LKMs not loaded."
2401.89Scjs	fi
2411.84Sveegofi
2421.84Sveego
2431.84Sveegomount -a
2441.84Sveego
2451.84Sveego# now start the rpc servers, for NFS server/client.
2461.90Sveegoecho -n 'starting nfs daemons:'
2471.84Sveego
2481.67Smycroftnfs_locking=NO
2491.67Smycroft
2501.89Scjsif checkyesno nfs_server; then
2511.89Scjs	if [ -r /etc/exports ]; then
2521.89Scjs		rm -f /var/db/mountdtab
2531.89Scjs		echo -n > /var/db/mountdtab
2541.89Scjs		echo -n ' mountd';              mountd $mountd_flags
2551.89Scjs		echo -n ' nfsd';                nfsd $nfsd_flags
2561.100Slukem		nfs_locking=YES
2571.89Scjs	else
2581.89Scjs		echo
2591.89Scjs		logger -s "WARNING: /etc/exports not readable; " \
2601.89Scjs		    "NFS server not started."
2611.69Smycroft	fi
2621.1Scgdfi
2631.63Smrg
2641.89Scjsif checkyesno nfs_client; then
2651.63Smrg        echo -n ' nfsiod';              nfsiod $nfsiod_flags
2661.100Slukem	nfs_locking=YES
2671.66Sscottrfi
2681.66Sscottr
2691.100Slukemif checkyesno nfs_locking; then
2701.89Scjs	if checkyesno statd; then
2711.71Smycroft		echo -n ' rpc.statd';		rpc.statd $statd_flags
2721.66Sscottr	fi
2731.89Scjs	if checkyesno lockd; then
2741.71Smycroft		echo -n ' rpc.lockd';		rpc.lockd $lockd_flags
2751.66Sscottr	fi
2761.63Smrgfi
2771.63Smrg
2781.89Scjsif checkyesno amd; then
2791.89Scjs	if [ -d "$amd_dir" ]; then
2801.89Scjs		if [ -r "$amd_master" ]; then
2811.89Scjs			echo -n ' amd'
2821.104Stron			amd $amd_flags -p -a $amd_dir \
2831.104Stron			`sed s/#.*$// <$amd_master`  >/var/run/amd.pid
2841.89Scjs		else
2851.89Scjs			echo
2861.89Scjs			logger -s "WARNING: \$amd_master ($amd_master)not " \
2871.89Scjs			    "readable; amd not started."
2881.89Scjs		fi
2891.89Scjs	else
2901.89Scjs		echo
2911.89Scjs		logger -s "WARNING: \$amd_dir ($amd_dir) not a directory; " \
2921.89Scjs		    "amd not started."
2931.67Smycroft	fi
2941.63Smrgfi
2951.63Smrg
2961.1Scgdecho '.'
2971.83Sdrochner
2981.63Smrgif [ -f /sbin/ldconfig ]; then
2991.63Smrg	echo 'creating runtime link editor directory cache.'
3001.88Sthorpej	ldconfig
3011.63Smrgfi 
3021.83Sdrochner
3031.83Sdrochner# load kernel modules specified in /etc/lkm.conf
3041.89Scjsif checkyesno lkm && [ -f /etc/rc.lkm ]; then
3051.83Sdrochner	lkmstage=AFTERMOUNT
3061.83Sdrochner	. /etc/rc.lkm
3071.1Scgdfi
3081.1Scgd
3091.89Scjsecho -n 'checking quotas:'; quotacheck -a; echo ' done.'
3101.47Sderaadtquotaon -a
3111.1Scgd
3121.1Scgd# build ps databases
3131.2Scgdecho 'building databases...'
3141.11Scgdkvm_mkdb /netbsd
3151.1Scgddev_mkdb
3161.1Scgd
3171.1Scgdchmod 666 /dev/tty[pqrs]*
3181.1Scgd
3191.1Scgd# check the password temp/lock file
3201.1Scgdif [ -f /etc/ptmp ]
3211.1Scgdthen
3221.1Scgd	logger -s -p auth.err \
3231.1Scgd	'password file may be incorrect -- /etc/ptmp exists'
3241.1Scgdfi
3251.1Scgd
3261.85Sperryvirecovery=`echo /var/tmp/vi.recover/recover.*`
3271.32Smycroftif [ "$virecovery" != "/var/tmp/vi.recover/recover.*" ]; then
3281.32Smycroft	echo preserving editor files
3291.32Smycroft	for i in $virecovery; do
3301.32Smycroft		sendmail -t < $i
3311.32Smycroft	done
3321.32Smycroftfi
3331.1Scgd
3341.1Scgdecho clearing /tmp
3351.1Scgd
3361.65Smikel# Prune quickly with one rm, then use find to clean up /tmp/[lq]* (this
3371.65Smikel# is not needed with mfs /tmp, but doesn't hurt anything).
3381.1Scgd(cd /tmp && rm -rf [a-km-pr-zA-Z]* &&
3391.46Sderaadt    find . ! -name . ! -name lost+found ! -name quota.user \
3401.46Sderaadt	! -name quota.group -exec rm -rf -- {} \; -type d -prune)
3411.1Scgd
3421.74Sperry# Update kernel info in /etc/motd
3431.74Sperry# Must be done *before* interactive logins are possible to prevent
3441.74Sperry# possible race conditions.
3451.89Scjsif checkyesno update_motd; then
3461.74Sperry	echo 'updating motd.'
3471.74Sperry	if [ ! -f /etc/motd ]; then
3481.74Sperry		install -c -o root -g wheel -m 664 /dev/null /etc/motd
3491.74Sperry	fi
3501.74Sperry	T=/tmp/_motd
3511.74Sperry	rm -f $T
3521.74Sperry	sysctl -n kern.version | sed 1q > $T
3531.74Sperry	echo "" >> $T
3541.74Sperry	sed '1,/^$/d' < /etc/motd >> $T
3551.74Sperry	cmp -s $T /etc/motd || cp $T /etc/motd
3561.74Sperry	rm -f $T
3571.74Sperryfi
3581.74Sperry
3591.34Scgdif [ -f /var/account/acct ]; then
3601.34Scgd	echo 'turning on accounting';	accton /var/account/acct
3611.34Scgdfi
3621.1Scgd
3631.1Scgdecho -n standard daemons:
3641.89Scjsif checkyesno update; then
3651.70Smycroft	echo -n ' update';		update $update_flags
3661.70Smycroftfi
3671.31Sjtcecho -n ' cron';		cron
3681.1Scgdecho '.'
3691.1Scgd
3701.63Smrg# now start all the other daemons
3711.1Scgdecho -n starting network daemons:
3721.1Scgd
3731.89Scjsif checkyesno gated && checkyesno routed; then
3741.89Scjs	echo
3751.89Scjs	logger -s "WARNING: gated and routed both requested to be run: " \
3761.89Scjs	    "running only gated."
3771.89Scjs	routed=NO
3781.89Scjsfi
3791.89Scjs
3801.89Scjsif checkyesno gated; then
3811.89Scjs	if [ -r /etc/gated.conf ]; then
3821.89Scjs		echo -n ' gated';		gated $gated_flags
3831.89Scjs	else
3841.89Scjs		logger -s "WARNING: no /etc/gated.conf; gated not started."
3851.67Smycroft	fi
3861.89Scjsfi
3871.89Scjs
3881.89Scjsif checkyesno routed; then
3891.48Smycroft	echo -n ' routed';		routed $routed_flags
3901.1Scgdfi
3911.1Scgd
3921.89Scjsif checkyesno mrouted; then
3931.55Sthorpej	echo -n ' mrouted';		mrouted $mrouted_flags
3941.55Sthorpejfi
3951.55Sthorpej
3961.89Scjsif checkyesno timed; then
3971.67Smycroft	echo -n ' timed'; 		timed $timed_flags
3981.63Smrgfi
3991.63Smrg
4001.89Scjsif checkyesno xntpd; then
4011.67Smycroft	echo -n ' xntpd';		xntpd $xntpd_flags
4021.61Smrgfi
4031.61Smrg
4041.89Scjsif checkyesno dhcpd; then
4051.89Scjs	if [ -r /etc/dhcpd.conf ]; then
4061.89Scjs		echo -n ' dhcpd';		dhcpd $dhcpd_flags
4071.89Scjs	else
4081.89Scjs		echo
4091.89Scjs		logger -s "WARNING: /etc/dhcpd.conf not readable; " \
4101.89Scjs		    "dhcpd not started."
4111.67Smycroft	fi
4121.29Smycroftfi
4131.29Smycroft
4141.89Scjsif checkyesno rwhod; then
4151.48Smycroft	echo -n ' rwhod';		rwhod
4161.1Scgdfi
4171.1Scgd
4181.89Scjsif checkyesno lpd; then
4191.89Scjs	echo -n ' lpd';			lpd $lpd_flags
4201.60Stlsfi
4211.60Stls
4221.63Smrg# We call sendmail with a full path so that SIGHUP works.
4231.89Scjsif checkyesno sendmail; then
4241.89Scjs	if [ -r /etc/sendmail.cf ]; then
4251.89Scjs		echo -n ' sendmail';	/usr/sbin/sendmail $sendmail_flags
4261.89Scjs	else
4271.89Scjs		echo
4281.89Scjs		logger -s "WARNING: /etc/sendmail.cf not readable; " \
4291.89Scjs		    "sendmail not started."
4301.67Smycroft	fi
4311.60Stlsfi
4321.60Stls
4331.96Sjonathan# Start xfs before boot daemons, so its ready before client xterminals.
4341.96Sjonathanif checkyesno xfs; then
4351.96Sjonathan	echo -n ' xfs';			xfs $xfs_flags &
4361.98Sperry	sleep 2
4371.96Sjonathanfi
4381.96Sjonathan
4391.89Scjsif checkyesno rarpd; then
4401.89Scjs	if [ -r /etc/ethers ]; then
4411.89Scjs		echo -n ' rarpd';	rarpd $rarpd_flags
4421.89Scjs	else
4431.89Scjs		echo
4441.89Scjs		logger -s "WARNING: /etc/ethers not readable; " \
4451.89Scjs		    "rarpd not started."
4461.67Smycroft	fi
4471.60Stlsfi
4481.60Stls
4491.89Scjsif checkyesno rbootd; then
4501.89Scjs	if [ -r /etc/rbootd.conf ]; then
4511.89Scjs		echo -n ' rbootd';	rbootd $rbootd_flags
4521.89Scjs	else
4531.89Scjs		echo
4541.89Scjs		logger -s "WARNING: /etc/rbootd.conf not readable; " \
4551.89Scjs		    "rarpd not started."
4561.67Smycroft	fi
4571.72Scjsfi
4581.72Scjs
4591.89Scjsif checkyesno mopd; then
4601.72Scjs	echo -n ' mopd';		mopd $mopd_flags
4611.86Sperryfi
4621.86Sperry
4631.89Scjsif checkyesno apmd; then
4641.86Sperry	echo -n ' apmd';		apmd $apmd_flags
4651.103Smrgfi
4661.103Smrg
4671.103Smrgif checkyesno screenblank; then
4681.103Smrg	echo -n ' screenblank';		screenblank $screenblank_flags
4691.52Sthorpejfi
4701.52Sthorpej
4711.89Scjsif checkyesno inetd; then
4721.89Scjs	if [ -r /etc/inetd.conf ]; then
4731.89Scjs		echo -n ' inetd';	inetd $inetd_flags
4741.89Scjs	else
4751.89Scjs		echo
4761.89Scjs		logger -s "WARNING: /etc/inetd.conf not readable; " \
4771.89Scjs		    "inetd not started."
4781.67Smycroft	fi
4791.105Saugustssfi
4801.105Saugustss
4811.105Saugustssif checkyesno usbd; then
4821.105Saugustss	echo -n ' usbd';		usbd $usbd_flags
4831.96Sjonathanfi
4841.96Sjonathan
4851.96Sjonathanif checkyesno xdm; then
4861.96Sjonathan	echo -n ' xdm';			xdm $xdm_flags
4871.30Smycroftfi
4881.30Smycroft
4891.1Scgdecho '.'
4901.73Sperry
4911.73Sperry# Kerberos runs ONLY on the Kerberos server machine
4921.89Scjsif checkyesno kerberos; then
4931.73Sperry	echo -n 'starting kerberos daemons:'
4941.73Sperry	echo -n ' kerberos';	kerberos >> /var/log/kerberos.log &
4951.73Sperry	echo -n ' kadmind';	kadmind -n >> /var/log/kadmind.log &
4961.73Sperry	echo '.'
4971.73Sperryfi
4981.1Scgd
4991.25Smycroft. /etc/rc.local
5001.1Scgd
5011.1Scgddate
5021.1Scgdexit 0
503