rc revision 1.98
11.98Sperry#	$NetBSD: rc,v 1.98 1998/01/09 21:57:17 perry 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.79Sthorpej
1211.79Sthorpej# "Critical" file systems are now mounted.  Go ahead and swap
1221.79Sthorpej# to files now, since they will be residing in the critical file
1231.79Sthorpej# systems (or, at least, better).
1241.79Sthorpejswapctl -A -t noblk
1251.97Smrg
1261.97Smrg# Check for no swap, and warn about it unless that is desired.
1271.97Smrgif [ "$no_swap" != YES ]; then
1281.97Smrg	swapctl -s | grep 'no swap devices configured' > /dev/null && \
1291.97Smrg		echo "WARNING:  no swap space configured!"
1301.97Smrgfi
1311.26Sderaadt
1321.41Sjtc# clean up left-over files
1331.41Sjtcrm -f /etc/nologin
1341.41Sjtcrm -f /var/spool/lock/LCK.*
1351.41Sjtcrm -f /var/spool/uucp/STST/*
1361.45Scgd(cd /var/run && { rm -rf -- *; install -c -m 664 -g utmp /dev/null utmp; })
1371.41Sjtc
1381.84Sveego# start the system logger first, so that all messages from daemons
1391.84Sveego# are logged, then start savecore to get a dump on low memory systems
1401.84Sveego# and then start the name server.
1411.63Smrg
1421.89Scjsif checkyesno syslogd; then
1431.63Smrg	echo 'starting system logger'
1441.63Smrg	rm -f /dev/log
1451.63Smrg	syslogd $syslogd_flags
1461.94Slukemfi
1471.94Slukem
1481.94Slukem# Enable ipmon (only useful if ipfilter is running)
1491.94Slukem# NOTE: requires the IPFILTER_LOG kernel option.
1501.94Slukemif checkyesno ipmon; then
1511.94Slukem	echo 'starting ipmon'
1521.94Slukem	ipmon $ipmon_flags &
1531.63Smrgfi
1541.63Smrg
1551.84Sveego# /var/crash should be a directory or a symbolic link
1561.84Sveego# to the crash directory if core dumps are to be saved.
1571.89Scjsif checkyesno savecore; then
1581.89Scjs	if [ -d /var/crash ]; then
1591.89Scjs		echo checking for core dump...
1601.89Scjs		savecore $savecore_flags /var/crash
1611.89Scjs	else
1621.89Scjs		logger -s "WARNING: no /var/crash directory; savecore not run."
1631.84Sveego	fi
1641.84Sveegofi
1651.84Sveego
1661.89Scjsif checkyesno named; then
1671.89Scjs	echo 'starting name server';	named $named_flags
1681.89Scjsfi
1691.89Scjs
1701.89Scjs# set time, if requested
1711.89Scjsif checkyesno ntpdate; then
1721.91Smikel	if [ -z "$ntpdate_hosts" ]; then
1731.89Scjs		ntpdate_hosts=`awk '/^server/ {print $2}' </etc/ntp.conf`
1741.89Scjs	fi
1751.89Scjs	if [ -n "$ntpdate_hosts"  ]; then
1761.89Scjs		echo 'Setting date via ntp.'
1771.89Scjs		ntpdate -b $ntpdate_hosts
1781.67Smycroft	fi
1791.63Smrgfi
1801.63Smrg
1811.84Sveego# now start the rpc servers, for YP server/client.
1821.63Smrgecho -n 'starting rpc daemons:'
1831.63Smrg
1841.63Smrg# note that portmap is generally required for all other rpc services.
1851.89Scjsif checkyesno portmap; then
1861.63Smrg	echo -n ' portmap';             portmap
1871.63Smrgfi
1881.63Smrg
1891.89Scjsif checkyesno ypserv; then
1901.63Smrg        echo -n ' ypserv';              ypserv $ypserv_flags
1911.63Smrgfi
1921.63Smrg
1931.89Scjsif checkyesno ypbind; then
1941.63Smrg        echo -n ' ypbind';              ypbind $ypbind_flags
1951.63Smrgfi
1961.63Smrg
1971.89Scjsif checkyesno yppasswdd; then
1981.63Smrg        echo -n ' rpc.yppasswdd';       rpc.yppasswdd $yppasswdd_flags
1991.63Smrgfi
2001.63Smrg
2011.89Scjsif checkyesno bootparamd; then
2021.89Scjs	if [ -r /etc/bootparams ]; then
2031.89Scjs		echo -n ' rpc.bootparamd'; rpc.bootparamd $bootparamd_flags
2041.89Scjs	else
2051.89Scjs		echo
2061.89Scjs		logger -s "WARNING: /etc/bootparams not found. " \
2071.89Scjs		    "bootparamd not started."
2081.67Smycroft	fi
2091.63Smrgfi
2101.63Smrg
2111.84Sveegoecho '.'
2121.84Sveego
2131.84Sveego# load kernel modules specified in /etc/lkm.conf
2141.89Scjsif checkyesno lkm; then
2151.89Scjs	if [ -r /etc/rc.lkm ]; then
2161.89Scjs		lkmstage=BEFOREMOUNT
2171.89Scjs		. /etc/rc.lkm
2181.89Scjs	else
2191.89Scjs		logger -s "WARNING: /etc/rc.lkm not found; LKMs not loaded."
2201.89Scjs	fi
2211.84Sveegofi
2221.84Sveego
2231.84Sveegomount -a
2241.84Sveego
2251.84Sveego# now start the rpc servers, for NFS server/client.
2261.90Sveegoecho -n 'starting nfs daemons:'
2271.84Sveego
2281.67Smycroftnfs_locking=NO
2291.67Smycroft
2301.89Scjsif checkyesno nfs_server; then
2311.89Scjs	if [ -r /etc/exports ]; then
2321.89Scjs		rm -f /var/db/mountdtab
2331.89Scjs		echo -n > /var/db/mountdtab
2341.89Scjs		echo -n ' mountd';              mountd $mountd_flags
2351.89Scjs		echo -n ' nfsd';                nfsd $nfsd_flags
2361.89Scjs		nfs_locking=MAYBE
2371.89Scjs	else
2381.89Scjs		echo
2391.89Scjs		logger -s "WARNING: /etc/exports not readable; " \
2401.89Scjs		    "NFS server not started."
2411.69Smycroft	fi
2421.1Scgdfi
2431.63Smrg
2441.89Scjsif checkyesno nfs_client; then
2451.63Smrg        echo -n ' nfsiod';              nfsiod $nfsiod_flags
2461.67Smycroft	nfs_locking=MAYBE
2471.66Sscottrfi
2481.66Sscottr
2491.67Smycroftif [ "$nfs_locking" != NO ]; then
2501.89Scjs	if checkyesno statd; then
2511.71Smycroft		echo -n ' rpc.statd';		rpc.statd $statd_flags
2521.66Sscottr	fi
2531.89Scjs	if checkyesno lockd; then
2541.71Smycroft		echo -n ' rpc.lockd';		rpc.lockd $lockd_flags
2551.66Sscottr	fi
2561.63Smrgfi
2571.63Smrg
2581.89Scjsif checkyesno amd; then
2591.89Scjs	if [ -d "$amd_dir" ]; then
2601.89Scjs		if [ -r "$amd_master" ]; then
2611.89Scjs			echo -n ' amd'
2621.89Scjs			amd $amd_flags -p -a $amd_dir `cat $amd_master` \
2631.89Scjs			    > /var/run/amd.pid
2641.89Scjs		else
2651.89Scjs			echo
2661.89Scjs			logger -s "WARNING: \$amd_master ($amd_master)not " \
2671.89Scjs			    "readable; amd not started."
2681.89Scjs		fi
2691.89Scjs	else
2701.89Scjs		echo
2711.89Scjs		logger -s "WARNING: \$amd_dir ($amd_dir) not a directory; " \
2721.89Scjs		    "amd not started."
2731.67Smycroft	fi
2741.63Smrgfi
2751.63Smrg
2761.1Scgdecho '.'
2771.83Sdrochner
2781.63Smrgif [ -f /sbin/ldconfig ]; then
2791.63Smrg	echo 'creating runtime link editor directory cache.'
2801.88Sthorpej	ldconfig
2811.63Smrgfi 
2821.83Sdrochner
2831.83Sdrochner# load kernel modules specified in /etc/lkm.conf
2841.89Scjsif checkyesno lkm && [ -f /etc/rc.lkm ]; then
2851.83Sdrochner	lkmstage=AFTERMOUNT
2861.83Sdrochner	. /etc/rc.lkm
2871.1Scgdfi
2881.1Scgd
2891.89Scjsecho -n 'checking quotas:'; quotacheck -a; echo ' done.'
2901.47Sderaadtquotaon -a
2911.1Scgd
2921.1Scgd# build ps databases
2931.2Scgdecho 'building databases...'
2941.11Scgdkvm_mkdb /netbsd
2951.1Scgddev_mkdb
2961.1Scgd
2971.1Scgdchmod 666 /dev/tty[pqrs]*
2981.1Scgd
2991.1Scgd# check the password temp/lock file
3001.1Scgdif [ -f /etc/ptmp ]
3011.1Scgdthen
3021.1Scgd	logger -s -p auth.err \
3031.1Scgd	'password file may be incorrect -- /etc/ptmp exists'
3041.1Scgdfi
3051.1Scgd
3061.85Sperryvirecovery=`echo /var/tmp/vi.recover/recover.*`
3071.32Smycroftif [ "$virecovery" != "/var/tmp/vi.recover/recover.*" ]; then
3081.32Smycroft	echo preserving editor files
3091.32Smycroft	for i in $virecovery; do
3101.32Smycroft		sendmail -t < $i
3111.32Smycroft	done
3121.32Smycroftfi
3131.1Scgd
3141.1Scgdecho clearing /tmp
3151.1Scgd
3161.65Smikel# Prune quickly with one rm, then use find to clean up /tmp/[lq]* (this
3171.65Smikel# is not needed with mfs /tmp, but doesn't hurt anything).
3181.1Scgd(cd /tmp && rm -rf [a-km-pr-zA-Z]* &&
3191.46Sderaadt    find . ! -name . ! -name lost+found ! -name quota.user \
3201.46Sderaadt	! -name quota.group -exec rm -rf -- {} \; -type d -prune)
3211.1Scgd
3221.74Sperry# Update kernel info in /etc/motd
3231.74Sperry# Must be done *before* interactive logins are possible to prevent
3241.74Sperry# possible race conditions.
3251.89Scjsif checkyesno update_motd; then
3261.74Sperry	echo 'updating motd.'
3271.74Sperry	if [ ! -f /etc/motd ]; then
3281.74Sperry		install -c -o root -g wheel -m 664 /dev/null /etc/motd
3291.74Sperry	fi
3301.74Sperry	T=/tmp/_motd
3311.74Sperry	rm -f $T
3321.74Sperry	sysctl -n kern.version | sed 1q > $T
3331.74Sperry	echo "" >> $T
3341.74Sperry	sed '1,/^$/d' < /etc/motd >> $T
3351.74Sperry	cmp -s $T /etc/motd || cp $T /etc/motd
3361.74Sperry	rm -f $T
3371.74Sperryfi
3381.74Sperry
3391.34Scgdif [ -f /var/account/acct ]; then
3401.34Scgd	echo 'turning on accounting';	accton /var/account/acct
3411.34Scgdfi
3421.1Scgd
3431.1Scgdecho -n standard daemons:
3441.89Scjsif checkyesno update; then
3451.70Smycroft	echo -n ' update';		update $update_flags
3461.70Smycroftfi
3471.31Sjtcecho -n ' cron';		cron
3481.1Scgdecho '.'
3491.1Scgd
3501.63Smrg# now start all the other daemons
3511.1Scgdecho -n starting network daemons:
3521.1Scgd
3531.89Scjsif checkyesno gated && checkyesno routed; then
3541.89Scjs	echo
3551.89Scjs	logger -s "WARNING: gated and routed both requested to be run: " \
3561.89Scjs	    "running only gated."
3571.89Scjs	routed=NO
3581.89Scjsfi
3591.89Scjs
3601.89Scjsif checkyesno gated; then
3611.89Scjs	if [ -r /etc/gated.conf ]; then
3621.89Scjs		echo -n ' gated';		gated $gated_flags
3631.89Scjs	else
3641.89Scjs		logger -s "WARNING: no /etc/gated.conf; gated not started."
3651.67Smycroft	fi
3661.89Scjsfi
3671.89Scjs
3681.89Scjsif checkyesno routed; then
3691.48Smycroft	echo -n ' routed';		routed $routed_flags
3701.1Scgdfi
3711.1Scgd
3721.89Scjsif checkyesno mrouted; then
3731.55Sthorpej	echo -n ' mrouted';		mrouted $mrouted_flags
3741.55Sthorpejfi
3751.55Sthorpej
3761.89Scjsif checkyesno timed; then
3771.67Smycroft	echo -n ' timed'; 		timed $timed_flags
3781.63Smrgfi
3791.63Smrg
3801.89Scjsif checkyesno xntpd; then
3811.67Smycroft	echo -n ' xntpd';		xntpd $xntpd_flags
3821.61Smrgfi
3831.61Smrg
3841.89Scjsif checkyesno dhcpd; then
3851.89Scjs	if [ -r /etc/dhcpd.conf ]; then
3861.89Scjs		echo -n ' dhcpd';		dhcpd $dhcpd_flags
3871.89Scjs	else
3881.89Scjs		echo
3891.89Scjs		logger -s "WARNING: /etc/dhcpd.conf not readable; " \
3901.89Scjs		    "dhcpd not started."
3911.67Smycroft	fi
3921.29Smycroftfi
3931.29Smycroft
3941.89Scjsif checkyesno rwhod; then
3951.48Smycroft	echo -n ' rwhod';		rwhod
3961.1Scgdfi
3971.1Scgd
3981.89Scjsif checkyesno lpd; then
3991.89Scjs	echo -n ' lpd';			lpd $lpd_flags
4001.60Stlsfi
4011.60Stls
4021.63Smrg# We call sendmail with a full path so that SIGHUP works.
4031.89Scjsif checkyesno sendmail; then
4041.89Scjs	if [ -r /etc/sendmail.cf ]; then
4051.89Scjs		echo -n ' sendmail';	/usr/sbin/sendmail $sendmail_flags
4061.89Scjs	else
4071.89Scjs		echo
4081.89Scjs		logger -s "WARNING: /etc/sendmail.cf not readable; " \
4091.89Scjs		    "sendmail not started."
4101.67Smycroft	fi
4111.60Stlsfi
4121.60Stls
4131.96Sjonathan# Start xfs before boot daemons, so its ready before client xterminals.
4141.96Sjonathanif checkyesno xfs; then
4151.96Sjonathan	echo -n ' xfs';			xfs $xfs_flags &
4161.98Sperry	sleep 2
4171.96Sjonathanfi
4181.96Sjonathan
4191.89Scjsif checkyesno rarpd; then
4201.89Scjs	if [ -r /etc/ethers ]; then
4211.89Scjs		echo -n ' rarpd';	rarpd $rarpd_flags
4221.89Scjs	else
4231.89Scjs		echo
4241.89Scjs		logger -s "WARNING: /etc/ethers not readable; " \
4251.89Scjs		    "rarpd not started."
4261.67Smycroft	fi
4271.60Stlsfi
4281.60Stls
4291.89Scjsif checkyesno rbootd; then
4301.89Scjs	if [ -r /etc/rbootd.conf ]; then
4311.89Scjs		echo -n ' rbootd';	rbootd $rbootd_flags
4321.89Scjs	else
4331.89Scjs		echo
4341.89Scjs		logger -s "WARNING: /etc/rbootd.conf not readable; " \
4351.89Scjs		    "rarpd not started."
4361.67Smycroft	fi
4371.72Scjsfi
4381.72Scjs
4391.89Scjsif checkyesno mopd; then
4401.72Scjs	echo -n ' mopd';		mopd $mopd_flags
4411.86Sperryfi
4421.86Sperry
4431.89Scjsif checkyesno apmd; then
4441.86Sperry	echo -n ' apmd';		apmd $apmd_flags
4451.52Sthorpejfi
4461.52Sthorpej
4471.89Scjsif checkyesno inetd; then
4481.89Scjs	if [ -r /etc/inetd.conf ]; then
4491.89Scjs		echo -n ' inetd';	inetd $inetd_flags
4501.89Scjs	else
4511.89Scjs		echo
4521.89Scjs		logger -s "WARNING: /etc/inetd.conf not readable; " \
4531.89Scjs		    "inetd not started."
4541.67Smycroft	fi
4551.96Sjonathanfi
4561.96Sjonathan
4571.96Sjonathanif checkyesno xdm; then
4581.96Sjonathan	echo -n ' xdm';			xdm $xdm_flags
4591.30Smycroftfi
4601.30Smycroft
4611.1Scgdecho '.'
4621.73Sperry
4631.73Sperry# Kerberos runs ONLY on the Kerberos server machine
4641.89Scjsif checkyesno kerberos; then
4651.73Sperry	echo -n 'starting kerberos daemons:'
4661.73Sperry	echo -n ' kerberos';	kerberos >> /var/log/kerberos.log &
4671.73Sperry	echo -n ' kadmind';	kadmind -n >> /var/log/kadmind.log &
4681.73Sperry	echo '.'
4691.73Sperryfi
4701.1Scgd
4711.25Smycroft. /etc/rc.local
4721.1Scgd
4731.1Scgddate
4741.1Scgdexit 0
475