rc revision 1.99
11.99Sveego#	$NetBSD: rc,v 1.99 1998/01/24 19:12:55 veego 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.1Scgd
241.79Sthorpej# Add all block-type swap devices; these might be necessary
251.79Sthorpej# during disk checks.
261.79Sthorpejswapctl -A -t blk
271.79Sthorpej
281.63Smrgif [ -e /fastboot ]; then
291.38Scgd	echo "Fast boot: skipping disk checks."
301.68Smycroftelif [ "$1" = autoboot ]; then
311.38Scgd	echo "Automatic boot in progress: starting file system checks."
321.1Scgd	fsck -p
331.1Scgd	case $? in
341.1Scgd	0)
351.1Scgd		;;
361.1Scgd	2)
371.1Scgd		exit 1
381.1Scgd		;;
391.1Scgd	4)
401.35Scgd		echo "Rebooting..."
411.1Scgd		reboot
421.38Scgd		echo "Reboot failed; help!"
431.1Scgd		exit 1
441.1Scgd		;;
451.1Scgd	8)
461.38Scgd		echo "Automatic file system check failed; help!"
471.1Scgd		exit 1
481.1Scgd		;;
491.1Scgd	12)
501.38Scgd		echo "Boot interrupted."
511.1Scgd		exit 1
521.1Scgd		;;
531.1Scgd	130)
541.1Scgd		# interrupt before catcher installed
551.1Scgd		exit 1
561.1Scgd		;;
571.1Scgd	*)
581.38Scgd		echo "Unknown error; help!"
591.1Scgd		exit 1
601.1Scgd		;;
611.1Scgd	esac
621.1Scgdfi
631.1Scgd
641.38Scgdtrap "echo 'Boot interrupted.'; exit 1" 3
651.1Scgd
661.1Scgdumount -a >/dev/null 2>&1
671.83Sdrochnermount /
681.1Scgdrm -f /fastboot		# XXX (root now writeable)
691.40Scgd
701.90Sveegoif [ -f /etc/rc.subr ]; then
711.90Sveego	. /etc/rc.subr
721.89Scjselse
731.90Sveego	echo "Can't read /etc/rc.subr; aborting."
741.89Scjs	exit 1;
751.89Scjsfi
761.89Scjs
771.71Smycroftif [ -f /etc/rc.conf ]; then
781.63Smrg	. /etc/rc.conf
791.63Smrgfi
801.63Smrg
811.89Scjsif [ "$rc_configured" != YES ]; then
821.89Scjs	echo "/etc/rc.conf is not configured. Multiuser boot aborted."
831.89Scjs	exit 1
841.89Scjsfi
851.89Scjs
861.40Scgd# set flags on ttys.  (do early, in case they use tty for SLIP in netstart)
871.40Scgdecho 'setting tty flags'
881.40Scgdttyflags -a
891.1Scgd
901.83Sdrochner# load kernel modules specified in /etc/lkm.conf if the /usr filesystem
911.83Sdrochner# is already present with "/" or can be mounted now
921.93Sdrochnerif checkyesno lkm && [ -f /etc/rc.lkm ]; then
931.83Sdrochner	mount /usr >/dev/null 2>&1
941.83Sdrochner	if [ -x /usr/bin/ld ]; then
951.83Sdrochner		lkmstage=BEFORENET
961.83Sdrochner		. /etc/rc.lkm
971.83Sdrochner	fi
981.63Smrgfi
991.63Smrg
1001.1Scgd# set hostname, turn on network
1011.1Scgdecho 'starting network'
1021.76Sscottrsh /etc/netstart
1031.76Sscottrif [ $? -ne 0 ]; then
1041.76Sscottr	exit 1
1051.76Sscottrfi
1061.1Scgd
1071.95Sdrochnerfor fs in /usr /var $critical_filesystems; do
1081.95Sdrochner	mount | (
1091.95Sdrochner        		ismounted=no
1101.95Sdrochner        		while read what _on on _type type; do
1111.95Sdrochner               		 if [ $on = $fs ]; then
1121.95Sdrochner                        			ismounted=yes
1131.95Sdrochner               		 fi
1141.95Sdrochner        		done
1151.95Sdrochner       		if [ $ismounted = no ]; then
1161.95Sdrochner			mount $fs >/dev/null 2>&1
1171.95Sdrochner		fi
1181.95Sdrochner	)
1191.95Sdrochnerdone
1201.99Sveego
1211.99Sveego# Network Address Translation...
1221.99Sveegoif [ "$ipnat" != NO ] && [ -f /etc/ipnat.conf ]; then
1231.99Sveego	echo 'installing NAT rules ... '
1241.99Sveego	if [ "$ipfilter" = NO ] || [ ! -f /etc/ipf.conf ]; then
1251.99Sveego		ipf -E -Fa
1261.99Sveego	fi
1271.99Sveego	ipnat -F -f /etc/ipnat.conf
1281.99Sveegofi
1291.79Sthorpej
1301.79Sthorpej# "Critical" file systems are now mounted.  Go ahead and swap
1311.79Sthorpej# to files now, since they will be residing in the critical file
1321.79Sthorpej# systems (or, at least, better).
1331.79Sthorpejswapctl -A -t noblk
1341.97Smrg
1351.97Smrg# Check for no swap, and warn about it unless that is desired.
1361.97Smrgif [ "$no_swap" != YES ]; then
1371.97Smrg	swapctl -s | grep 'no swap devices configured' > /dev/null && \
1381.97Smrg		echo "WARNING:  no swap space configured!"
1391.97Smrgfi
1401.26Sderaadt
1411.41Sjtc# clean up left-over files
1421.41Sjtcrm -f /etc/nologin
1431.41Sjtcrm -f /var/spool/lock/LCK.*
1441.41Sjtcrm -f /var/spool/uucp/STST/*
1451.45Scgd(cd /var/run && { rm -rf -- *; install -c -m 664 -g utmp /dev/null utmp; })
1461.41Sjtc
1471.84Sveego# start the system logger first, so that all messages from daemons
1481.84Sveego# are logged, then start savecore to get a dump on low memory systems
1491.84Sveego# and then start the name server.
1501.63Smrg
1511.89Scjsif checkyesno syslogd; then
1521.63Smrg	echo 'starting system logger'
1531.63Smrg	rm -f /dev/log
1541.63Smrg	syslogd $syslogd_flags
1551.94Slukemfi
1561.94Slukem
1571.94Slukem# Enable ipmon (only useful if ipfilter is running)
1581.94Slukem# NOTE: requires the IPFILTER_LOG kernel option.
1591.94Slukemif checkyesno ipmon; then
1601.94Slukem	echo 'starting ipmon'
1611.94Slukem	ipmon $ipmon_flags &
1621.63Smrgfi
1631.63Smrg
1641.84Sveego# /var/crash should be a directory or a symbolic link
1651.84Sveego# to the crash directory if core dumps are to be saved.
1661.89Scjsif checkyesno savecore; then
1671.89Scjs	if [ -d /var/crash ]; then
1681.89Scjs		echo checking for core dump...
1691.89Scjs		savecore $savecore_flags /var/crash
1701.89Scjs	else
1711.89Scjs		logger -s "WARNING: no /var/crash directory; savecore not run."
1721.84Sveego	fi
1731.84Sveegofi
1741.84Sveego
1751.89Scjsif checkyesno named; then
1761.89Scjs	echo 'starting name server';	named $named_flags
1771.89Scjsfi
1781.89Scjs
1791.89Scjs# set time, if requested
1801.89Scjsif checkyesno ntpdate; then
1811.91Smikel	if [ -z "$ntpdate_hosts" ]; then
1821.89Scjs		ntpdate_hosts=`awk '/^server/ {print $2}' </etc/ntp.conf`
1831.89Scjs	fi
1841.89Scjs	if [ -n "$ntpdate_hosts"  ]; then
1851.89Scjs		echo 'Setting date via ntp.'
1861.89Scjs		ntpdate -b $ntpdate_hosts
1871.67Smycroft	fi
1881.63Smrgfi
1891.63Smrg
1901.84Sveego# now start the rpc servers, for YP server/client.
1911.63Smrgecho -n 'starting rpc daemons:'
1921.63Smrg
1931.63Smrg# note that portmap is generally required for all other rpc services.
1941.89Scjsif checkyesno portmap; then
1951.63Smrg	echo -n ' portmap';             portmap
1961.63Smrgfi
1971.63Smrg
1981.89Scjsif checkyesno ypserv; then
1991.63Smrg        echo -n ' ypserv';              ypserv $ypserv_flags
2001.63Smrgfi
2011.63Smrg
2021.89Scjsif checkyesno ypbind; then
2031.63Smrg        echo -n ' ypbind';              ypbind $ypbind_flags
2041.63Smrgfi
2051.63Smrg
2061.89Scjsif checkyesno yppasswdd; then
2071.63Smrg        echo -n ' rpc.yppasswdd';       rpc.yppasswdd $yppasswdd_flags
2081.63Smrgfi
2091.63Smrg
2101.89Scjsif checkyesno bootparamd; then
2111.89Scjs	if [ -r /etc/bootparams ]; then
2121.89Scjs		echo -n ' rpc.bootparamd'; rpc.bootparamd $bootparamd_flags
2131.89Scjs	else
2141.89Scjs		echo
2151.89Scjs		logger -s "WARNING: /etc/bootparams not found. " \
2161.89Scjs		    "bootparamd not started."
2171.67Smycroft	fi
2181.63Smrgfi
2191.63Smrg
2201.84Sveegoecho '.'
2211.84Sveego
2221.84Sveego# load kernel modules specified in /etc/lkm.conf
2231.89Scjsif checkyesno lkm; then
2241.89Scjs	if [ -r /etc/rc.lkm ]; then
2251.89Scjs		lkmstage=BEFOREMOUNT
2261.89Scjs		. /etc/rc.lkm
2271.89Scjs	else
2281.89Scjs		logger -s "WARNING: /etc/rc.lkm not found; LKMs not loaded."
2291.89Scjs	fi
2301.84Sveegofi
2311.84Sveego
2321.84Sveegomount -a
2331.84Sveego
2341.84Sveego# now start the rpc servers, for NFS server/client.
2351.90Sveegoecho -n 'starting nfs daemons:'
2361.84Sveego
2371.67Smycroftnfs_locking=NO
2381.67Smycroft
2391.89Scjsif checkyesno nfs_server; then
2401.89Scjs	if [ -r /etc/exports ]; then
2411.89Scjs		rm -f /var/db/mountdtab
2421.89Scjs		echo -n > /var/db/mountdtab
2431.89Scjs		echo -n ' mountd';              mountd $mountd_flags
2441.89Scjs		echo -n ' nfsd';                nfsd $nfsd_flags
2451.89Scjs		nfs_locking=MAYBE
2461.89Scjs	else
2471.89Scjs		echo
2481.89Scjs		logger -s "WARNING: /etc/exports not readable; " \
2491.89Scjs		    "NFS server not started."
2501.69Smycroft	fi
2511.1Scgdfi
2521.63Smrg
2531.89Scjsif checkyesno nfs_client; then
2541.63Smrg        echo -n ' nfsiod';              nfsiod $nfsiod_flags
2551.67Smycroft	nfs_locking=MAYBE
2561.66Sscottrfi
2571.66Sscottr
2581.67Smycroftif [ "$nfs_locking" != NO ]; then
2591.89Scjs	if checkyesno statd; then
2601.71Smycroft		echo -n ' rpc.statd';		rpc.statd $statd_flags
2611.66Sscottr	fi
2621.89Scjs	if checkyesno lockd; then
2631.71Smycroft		echo -n ' rpc.lockd';		rpc.lockd $lockd_flags
2641.66Sscottr	fi
2651.63Smrgfi
2661.63Smrg
2671.89Scjsif checkyesno amd; then
2681.89Scjs	if [ -d "$amd_dir" ]; then
2691.89Scjs		if [ -r "$amd_master" ]; then
2701.89Scjs			echo -n ' amd'
2711.89Scjs			amd $amd_flags -p -a $amd_dir `cat $amd_master` \
2721.89Scjs			    > /var/run/amd.pid
2731.89Scjs		else
2741.89Scjs			echo
2751.89Scjs			logger -s "WARNING: \$amd_master ($amd_master)not " \
2761.89Scjs			    "readable; amd not started."
2771.89Scjs		fi
2781.89Scjs	else
2791.89Scjs		echo
2801.89Scjs		logger -s "WARNING: \$amd_dir ($amd_dir) not a directory; " \
2811.89Scjs		    "amd not started."
2821.67Smycroft	fi
2831.63Smrgfi
2841.63Smrg
2851.1Scgdecho '.'
2861.83Sdrochner
2871.63Smrgif [ -f /sbin/ldconfig ]; then
2881.63Smrg	echo 'creating runtime link editor directory cache.'
2891.88Sthorpej	ldconfig
2901.63Smrgfi 
2911.83Sdrochner
2921.83Sdrochner# load kernel modules specified in /etc/lkm.conf
2931.89Scjsif checkyesno lkm && [ -f /etc/rc.lkm ]; then
2941.83Sdrochner	lkmstage=AFTERMOUNT
2951.83Sdrochner	. /etc/rc.lkm
2961.1Scgdfi
2971.1Scgd
2981.89Scjsecho -n 'checking quotas:'; quotacheck -a; echo ' done.'
2991.47Sderaadtquotaon -a
3001.1Scgd
3011.1Scgd# build ps databases
3021.2Scgdecho 'building databases...'
3031.11Scgdkvm_mkdb /netbsd
3041.1Scgddev_mkdb
3051.1Scgd
3061.1Scgdchmod 666 /dev/tty[pqrs]*
3071.1Scgd
3081.1Scgd# check the password temp/lock file
3091.1Scgdif [ -f /etc/ptmp ]
3101.1Scgdthen
3111.1Scgd	logger -s -p auth.err \
3121.1Scgd	'password file may be incorrect -- /etc/ptmp exists'
3131.1Scgdfi
3141.1Scgd
3151.85Sperryvirecovery=`echo /var/tmp/vi.recover/recover.*`
3161.32Smycroftif [ "$virecovery" != "/var/tmp/vi.recover/recover.*" ]; then
3171.32Smycroft	echo preserving editor files
3181.32Smycroft	for i in $virecovery; do
3191.32Smycroft		sendmail -t < $i
3201.32Smycroft	done
3211.32Smycroftfi
3221.1Scgd
3231.1Scgdecho clearing /tmp
3241.1Scgd
3251.65Smikel# Prune quickly with one rm, then use find to clean up /tmp/[lq]* (this
3261.65Smikel# is not needed with mfs /tmp, but doesn't hurt anything).
3271.1Scgd(cd /tmp && rm -rf [a-km-pr-zA-Z]* &&
3281.46Sderaadt    find . ! -name . ! -name lost+found ! -name quota.user \
3291.46Sderaadt	! -name quota.group -exec rm -rf -- {} \; -type d -prune)
3301.1Scgd
3311.74Sperry# Update kernel info in /etc/motd
3321.74Sperry# Must be done *before* interactive logins are possible to prevent
3331.74Sperry# possible race conditions.
3341.89Scjsif checkyesno update_motd; then
3351.74Sperry	echo 'updating motd.'
3361.74Sperry	if [ ! -f /etc/motd ]; then
3371.74Sperry		install -c -o root -g wheel -m 664 /dev/null /etc/motd
3381.74Sperry	fi
3391.74Sperry	T=/tmp/_motd
3401.74Sperry	rm -f $T
3411.74Sperry	sysctl -n kern.version | sed 1q > $T
3421.74Sperry	echo "" >> $T
3431.74Sperry	sed '1,/^$/d' < /etc/motd >> $T
3441.74Sperry	cmp -s $T /etc/motd || cp $T /etc/motd
3451.74Sperry	rm -f $T
3461.74Sperryfi
3471.74Sperry
3481.34Scgdif [ -f /var/account/acct ]; then
3491.34Scgd	echo 'turning on accounting';	accton /var/account/acct
3501.34Scgdfi
3511.1Scgd
3521.1Scgdecho -n standard daemons:
3531.89Scjsif checkyesno update; then
3541.70Smycroft	echo -n ' update';		update $update_flags
3551.70Smycroftfi
3561.31Sjtcecho -n ' cron';		cron
3571.1Scgdecho '.'
3581.1Scgd
3591.63Smrg# now start all the other daemons
3601.1Scgdecho -n starting network daemons:
3611.1Scgd
3621.89Scjsif checkyesno gated && checkyesno routed; then
3631.89Scjs	echo
3641.89Scjs	logger -s "WARNING: gated and routed both requested to be run: " \
3651.89Scjs	    "running only gated."
3661.89Scjs	routed=NO
3671.89Scjsfi
3681.89Scjs
3691.89Scjsif checkyesno gated; then
3701.89Scjs	if [ -r /etc/gated.conf ]; then
3711.89Scjs		echo -n ' gated';		gated $gated_flags
3721.89Scjs	else
3731.89Scjs		logger -s "WARNING: no /etc/gated.conf; gated not started."
3741.67Smycroft	fi
3751.89Scjsfi
3761.89Scjs
3771.89Scjsif checkyesno routed; then
3781.48Smycroft	echo -n ' routed';		routed $routed_flags
3791.1Scgdfi
3801.1Scgd
3811.89Scjsif checkyesno mrouted; then
3821.55Sthorpej	echo -n ' mrouted';		mrouted $mrouted_flags
3831.55Sthorpejfi
3841.55Sthorpej
3851.89Scjsif checkyesno timed; then
3861.67Smycroft	echo -n ' timed'; 		timed $timed_flags
3871.63Smrgfi
3881.63Smrg
3891.89Scjsif checkyesno xntpd; then
3901.67Smycroft	echo -n ' xntpd';		xntpd $xntpd_flags
3911.61Smrgfi
3921.61Smrg
3931.89Scjsif checkyesno dhcpd; then
3941.89Scjs	if [ -r /etc/dhcpd.conf ]; then
3951.89Scjs		echo -n ' dhcpd';		dhcpd $dhcpd_flags
3961.89Scjs	else
3971.89Scjs		echo
3981.89Scjs		logger -s "WARNING: /etc/dhcpd.conf not readable; " \
3991.89Scjs		    "dhcpd not started."
4001.67Smycroft	fi
4011.29Smycroftfi
4021.29Smycroft
4031.89Scjsif checkyesno rwhod; then
4041.48Smycroft	echo -n ' rwhod';		rwhod
4051.1Scgdfi
4061.1Scgd
4071.89Scjsif checkyesno lpd; then
4081.89Scjs	echo -n ' lpd';			lpd $lpd_flags
4091.60Stlsfi
4101.60Stls
4111.63Smrg# We call sendmail with a full path so that SIGHUP works.
4121.89Scjsif checkyesno sendmail; then
4131.89Scjs	if [ -r /etc/sendmail.cf ]; then
4141.89Scjs		echo -n ' sendmail';	/usr/sbin/sendmail $sendmail_flags
4151.89Scjs	else
4161.89Scjs		echo
4171.89Scjs		logger -s "WARNING: /etc/sendmail.cf not readable; " \
4181.89Scjs		    "sendmail not started."
4191.67Smycroft	fi
4201.60Stlsfi
4211.60Stls
4221.96Sjonathan# Start xfs before boot daemons, so its ready before client xterminals.
4231.96Sjonathanif checkyesno xfs; then
4241.96Sjonathan	echo -n ' xfs';			xfs $xfs_flags &
4251.98Sperry	sleep 2
4261.96Sjonathanfi
4271.96Sjonathan
4281.89Scjsif checkyesno rarpd; then
4291.89Scjs	if [ -r /etc/ethers ]; then
4301.89Scjs		echo -n ' rarpd';	rarpd $rarpd_flags
4311.89Scjs	else
4321.89Scjs		echo
4331.89Scjs		logger -s "WARNING: /etc/ethers not readable; " \
4341.89Scjs		    "rarpd not started."
4351.67Smycroft	fi
4361.60Stlsfi
4371.60Stls
4381.89Scjsif checkyesno rbootd; then
4391.89Scjs	if [ -r /etc/rbootd.conf ]; then
4401.89Scjs		echo -n ' rbootd';	rbootd $rbootd_flags
4411.89Scjs	else
4421.89Scjs		echo
4431.89Scjs		logger -s "WARNING: /etc/rbootd.conf not readable; " \
4441.89Scjs		    "rarpd not started."
4451.67Smycroft	fi
4461.72Scjsfi
4471.72Scjs
4481.89Scjsif checkyesno mopd; then
4491.72Scjs	echo -n ' mopd';		mopd $mopd_flags
4501.86Sperryfi
4511.86Sperry
4521.89Scjsif checkyesno apmd; then
4531.86Sperry	echo -n ' apmd';		apmd $apmd_flags
4541.52Sthorpejfi
4551.52Sthorpej
4561.89Scjsif checkyesno inetd; then
4571.89Scjs	if [ -r /etc/inetd.conf ]; then
4581.89Scjs		echo -n ' inetd';	inetd $inetd_flags
4591.89Scjs	else
4601.89Scjs		echo
4611.89Scjs		logger -s "WARNING: /etc/inetd.conf not readable; " \
4621.89Scjs		    "inetd not started."
4631.67Smycroft	fi
4641.96Sjonathanfi
4651.96Sjonathan
4661.96Sjonathanif checkyesno xdm; then
4671.96Sjonathan	echo -n ' xdm';			xdm $xdm_flags
4681.30Smycroftfi
4691.30Smycroft
4701.1Scgdecho '.'
4711.73Sperry
4721.73Sperry# Kerberos runs ONLY on the Kerberos server machine
4731.89Scjsif checkyesno kerberos; then
4741.73Sperry	echo -n 'starting kerberos daemons:'
4751.73Sperry	echo -n ' kerberos';	kerberos >> /var/log/kerberos.log &
4761.73Sperry	echo -n ' kadmind';	kadmind -n >> /var/log/kadmind.log &
4771.73Sperry	echo '.'
4781.73Sperryfi
4791.1Scgd
4801.25Smycroft. /etc/rc.local
4811.1Scgd
4821.1Scgddate
4831.1Scgdexit 0
484