rc revision 1.83
11.83Sdrochner#	$NetBSD: rc,v 1.83 1997/07/14 11:55:44 drochner 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.68Smycroftexport PATH=/sbin:/bin:/usr/sbin:/usr/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.71Smycroftif [ -f /etc/rc.conf ]; then
711.63Smrg	. /etc/rc.conf
721.63Smrgfi
731.63Smrg
741.40Scgd# set flags on ttys.  (do early, in case they use tty for SLIP in netstart)
751.40Scgdecho 'setting tty flags'
761.40Scgdttyflags -a
771.1Scgd
781.83Sdrochner# load kernel modules specified in /etc/lkm.conf if the /usr filesystem
791.83Sdrochner# is already present with "/" or can be mounted now
801.67Smycroftif [ "$lkm_init" != NO ] && [ -f /etc/rc.lkm ]; then
811.83Sdrochner	mount /usr >/dev/null 2>&1
821.83Sdrochner	if [ -x /usr/bin/ld ]; then
831.83Sdrochner		lkmstage=BEFORENET
841.83Sdrochner		. /etc/rc.lkm
851.83Sdrochner	fi
861.63Smrgfi
871.63Smrg
881.1Scgd# set hostname, turn on network
891.1Scgdecho 'starting network'
901.76Sscottrsh /etc/netstart
911.76Sscottrif [ $? -ne 0 ]; then
921.76Sscottr	exit 1
931.76Sscottrfi
941.1Scgd
951.82Sveegomount /usr >/dev/null 2>&1
961.42Smycroftmount /var >/dev/null 2>&1
971.79Sthorpej
981.79Sthorpej# "Critical" file systems are now mounted.  Go ahead and swap
991.79Sthorpej# to files now, since they will be residing in the critical file
1001.79Sthorpej# systems (or, at least, better).
1011.79Sthorpejswapctl -A -t noblk
1021.26Sderaadt
1031.41Sjtc# clean up left-over files
1041.41Sjtcrm -f /etc/nologin
1051.41Sjtcrm -f /var/spool/lock/LCK.*
1061.41Sjtcrm -f /var/spool/uucp/STST/*
1071.45Scgd(cd /var/run && { rm -rf -- *; install -c -m 664 -g utmp /dev/null utmp; })
1081.41Sjtc
1091.63Smrg# start the system logger first, so that all messages
1101.63Smrg# from daemons are logged, and the name server next.
1111.63Smrg
1121.67Smycroftif [ "$syslogd_flags" != NO ]; then
1131.67Smycroft	if [ "$syslogd_flags" = DEFAULT ]; then
1141.67Smycroft		syslogd_flags=""
1151.67Smycroft	fi
1161.63Smrg	echo 'starting system logger'
1171.63Smrg	rm -f /dev/log
1181.63Smrg	syslogd $syslogd_flags
1191.63Smrgfi
1201.63Smrg
1211.67Smycroftif [ "$named_flags" != NO ]; then
1221.67Smycroft	if [ "$named_flags" = DEFAULT ]; then
1231.67Smycroft		named_flags=""
1241.67Smycroft	fi
1251.63Smrg	echo 'starting name server';	named $named_flags
1261.63Smrgfi
1271.63Smrg
1281.63Smrg# now start the rpc servers, for YP server/client, NFS.
1291.63Smrgecho -n 'starting rpc daemons:'
1301.63Smrg
1311.63Smrg# note that portmap is generally required for all other rpc services.
1321.67Smycroftif [ "$portmap" != NO ]; then
1331.63Smrg	echo -n ' portmap';             portmap
1341.63Smrgfi
1351.63Smrg
1361.67Smycroftif [ "$ypserv_flags" != NO ]; then
1371.67Smycroft	if [ "$ypserv_flags" = DEFAULT ]; then
1381.67Smycroft		ypserv_flags="-d"
1391.67Smycroft	fi
1401.63Smrg        echo -n ' ypserv';              ypserv $ypserv_flags
1411.63Smrgfi
1421.63Smrg
1431.67Smycroftif [ "$ypbind_flags" != NO ]; then
1441.67Smycroft	if [ "$ypbind_flags" = DEFAULT ]; then
1451.67Smycroft		ypbind_flags=""
1461.67Smycroft	fi
1471.63Smrg        echo -n ' ypbind';              ypbind $ypbind_flags
1481.63Smrgfi
1491.63Smrg
1501.67Smycroftif [ "$yppasswdd_flags" != NO ]; then
1511.67Smycroft	if [ "$yppasswdd_flags" = DEFAULT ]; then
1521.67Smycroft		yppasswdd_flags=""
1531.67Smycroft	fi
1541.63Smrg        echo -n ' rpc.yppasswdd';       rpc.yppasswdd $yppasswdd_flags
1551.63Smrgfi
1561.63Smrg
1571.67Smycroftif [ "$bootparamd_flags" != NO ] && [ -r /etc/bootparams ]; then
1581.67Smycroft	if [ "$bootparamd_flags" = DEFAULT ]; then
1591.67Smycroft		bootparamd_flags=""
1601.67Smycroft	fi
1611.63Smrg        echo -n ' rpc.bootparamd';      rpc.bootparamd $bootparamd_flags
1621.63Smrgfi
1631.63Smrg
1641.67Smycroftnfs_locking=NO
1651.67Smycroft
1661.67Smycroftif [ "$nfs_server" = YES ] && [ -r /etc/exports ]; then
1671.69Smycroft	if [ "$mountd_flags" = DEFAULT ]; then
1681.69Smycroft		mountd_flags=""
1691.63Smrg	fi
1701.63Smrg        rm -f /var/db/mountdtab
1711.63Smrg        echo -n > /var/db/mountdtab
1721.63Smrg        echo -n ' mountd';              mountd $mountd_flags
1731.69Smycroft	if [ "$nfsd_flags" = DEFAULT ]; then
1741.69Smycroft		nfsd_flags="-tun 4"
1751.69Smycroft	fi
1761.63Smrg        echo -n ' nfsd';                nfsd $nfsd_flags
1771.67Smycroft	nfs_locking=MAYBE
1781.1Scgdfi
1791.63Smrg
1801.67Smycroftif [ "$nfs_client" = YES ]; then
1811.67Smycroft	if [ "$nfsiod_flags" = DEFAULT ]; then
1821.63Smrg		nfsiod_flags="-n 4"
1831.63Smrg	fi
1841.63Smrg        echo -n ' nfsiod';              nfsiod $nfsiod_flags
1851.67Smycroft	nfs_locking=MAYBE
1861.66Sscottrfi
1871.66Sscottr
1881.67Smycroftif [ "$nfs_locking" != NO ]; then
1891.67Smycroft	if [ "$statd_flags" != NO ]; then
1901.67Smycroft		if [ "$statd_flags" = DEFAULT ]; then
1911.67Smycroft			statd_flags=""
1921.67Smycroft		fi
1931.71Smycroft		echo -n ' rpc.statd';		rpc.statd $statd_flags
1941.66Sscottr	fi
1951.66Sscottr
1961.67Smycroft	if [ "$lockd_flags" != NO ]; then
1971.67Smycroft		if [ "$lockd_flags" = DEFAULT ]; then
1981.67Smycroft			lockd_flags=""
1991.67Smycroft		fi
2001.71Smycroft		echo -n ' rpc.lockd';		rpc.lockd $lockd_flags
2011.66Sscottr	fi
2021.63Smrgfi
2031.63Smrg
2041.67Smycroftif [ "$amd_flags" != NO ] && [ -d "$amd_dir" -a -r "$amd_master" ]; then
2051.67Smycroft	if [ "$amd_flags" = DEFAULT ]; then
2061.67Smycroft		amd_flags="-l syslog -x error,noinfo,nostats"
2071.67Smycroft	fi
2081.63Smrg        echo -n ' amd'
2091.63Smrg        amd $amd_flags -p -a $amd_dir `cat $amd_master` > /var/run/amd.pid
2101.63Smrgfi
2111.63Smrg
2121.1Scgdecho '.'
2131.83Sdrochner
2141.83Sdrochner# load kernel modules specified in /etc/lkm.conf
2151.83Sdrochnerif [ "$lkm_init" != NO ] && [ -f /etc/rc.lkm ]; then
2161.83Sdrochner	lkmstage=BEFOREMOUNT
2171.83Sdrochner	. /etc/rc.lkm
2181.83Sdrochnerfi
2191.83Sdrochner
2201.83Sdrochnermount -a
2211.63Smrg
2221.63Smrgif [ -f /sbin/ldconfig ]; then
2231.63Smrg	echo 'creating runtime link editor directory cache.'
2241.71Smycroft	if [ -f /etc/ld.so.conf ]; then
2251.63Smrg		ldconfig `cat /etc/ld.so.conf`
2261.63Smrg	else
2271.63Smrg		ldconfig
2281.63Smrg	fi
2291.63Smrgfi 
2301.1Scgd
2311.1Scgd# /var/crash should be a directory or a symbolic link
2321.1Scgd# to the crash directory if core dumps are to be saved.
2331.67Smycroftif [ "$savecore_flags" != NO ] && [ -d /var/crash ]; then
2341.67Smycroft	if [ "$savecore_flags" = DEFAULT ]; then
2351.67Smycroft		savecore_flags=""
2361.67Smycroft	fi
2371.1Scgd	echo checking for core dump...
2381.63Smrg	savecore $savecore_flags /var/crash
2391.83Sdrochnerfi
2401.83Sdrochner
2411.83Sdrochner# load kernel modules specified in /etc/lkm.conf
2421.83Sdrochnerif [ "$lkm_init" != NO ] && [ -f /etc/rc.lkm ]; then
2431.83Sdrochner	lkmstage=AFTERMOUNT
2441.83Sdrochner	. /etc/rc.lkm
2451.1Scgdfi
2461.1Scgd
2471.47Sderaadt				echo -n 'checking quotas:'
2481.47Sderaadtquotacheck -a
2491.47Sderaadt				echo ' done.'
2501.47Sderaadtquotaon -a
2511.1Scgd
2521.1Scgd# build ps databases
2531.2Scgdecho 'building databases...'
2541.11Scgdkvm_mkdb /netbsd
2551.1Scgddev_mkdb
2561.1Scgd
2571.1Scgdchmod 666 /dev/tty[pqrs]*
2581.1Scgd
2591.1Scgd# check the password temp/lock file
2601.1Scgdif [ -f /etc/ptmp ]
2611.1Scgdthen
2621.1Scgd	logger -s -p auth.err \
2631.1Scgd	'password file may be incorrect -- /etc/ptmp exists'
2641.1Scgdfi
2651.1Scgd
2661.32Smycroftvirecovery=/var/tmp/vi.recover/recover.*
2671.32Smycroftif [ "$virecovery" != "/var/tmp/vi.recover/recover.*" ]; then
2681.32Smycroft	echo preserving editor files
2691.32Smycroft	for i in $virecovery; do
2701.32Smycroft		sendmail -t < $i
2711.32Smycroft	done
2721.32Smycroftfi
2731.1Scgd
2741.1Scgdecho clearing /tmp
2751.1Scgd
2761.65Smikel# Prune quickly with one rm, then use find to clean up /tmp/[lq]* (this
2771.65Smikel# is not needed with mfs /tmp, but doesn't hurt anything).
2781.1Scgd(cd /tmp && rm -rf [a-km-pr-zA-Z]* &&
2791.46Sderaadt    find . ! -name . ! -name lost+found ! -name quota.user \
2801.46Sderaadt	! -name quota.group -exec rm -rf -- {} \; -type d -prune)
2811.1Scgd
2821.74Sperry# Update kernel info in /etc/motd
2831.74Sperry# Must be done *before* interactive logins are possible to prevent
2841.74Sperry# possible race conditions.
2851.74Sperryif [ "$update_motd" != NO ]; then
2861.74Sperry	echo 'updating motd.'
2871.74Sperry	if [ ! -f /etc/motd ]; then
2881.74Sperry		install -c -o root -g wheel -m 664 /dev/null /etc/motd
2891.74Sperry	fi
2901.74Sperry	T=/tmp/_motd
2911.74Sperry	rm -f $T
2921.74Sperry	sysctl -n kern.version | sed 1q > $T
2931.74Sperry	echo "" >> $T
2941.74Sperry	sed '1,/^$/d' < /etc/motd >> $T
2951.74Sperry	cmp -s $T /etc/motd || cp $T /etc/motd
2961.74Sperry	rm -f $T
2971.74Sperryfi
2981.74Sperry
2991.34Scgdif [ -f /var/account/acct ]; then
3001.34Scgd	echo 'turning on accounting';	accton /var/account/acct
3011.34Scgdfi
3021.1Scgd
3031.1Scgdecho -n standard daemons:
3041.70Smycroftif [ "$update_flags" != NO ]; then
3051.70Smycroft	if [ "$update_flags" = DEFAULT ]; then
3061.70Smycroft		update_flags="30"
3071.70Smycroft	fi
3081.70Smycroft	echo -n ' update';		update $update_flags
3091.70Smycroftfi
3101.31Sjtcecho -n ' cron';		cron
3111.1Scgdecho '.'
3121.1Scgd
3131.63Smrg# now start all the other daemons
3141.1Scgdecho -n starting network daemons:
3151.1Scgd
3161.67Smycroftif [ "$gated_flags" != NO ] && [ -r /etc/gated.conf ]; then
3171.67Smycroft	if [ "$gated_flags" = DEFAULT ]; then
3181.67Smycroft		gated_flags=""
3191.67Smycroft	fi
3201.48Smycroft	echo -n ' gated';		gated $gated_flags
3211.67Smycroftelif [ "$routed_flags" != NO ]; then
3221.67Smycroft	if [ "$routed_flags" = DEFAULT ]; then
3231.67Smycroft		routed_flags="-q"
3241.67Smycroft	fi
3251.48Smycroft	echo -n ' routed';		routed $routed_flags
3261.1Scgdfi
3271.1Scgd
3281.67Smycroftif [ "$mrouted_flags" != NO ]; then
3291.67Smycroft	if [ "$mrouted_flags" = DEFAULT ]; then
3301.67Smycroft		mrouted_flags=""
3311.67Smycroft	fi
3321.55Sthorpej	echo -n ' mrouted';		mrouted $mrouted_flags
3331.55Sthorpejfi
3341.55Sthorpej
3351.67Smycroftif [ "$timed_flags" != NO ]; then
3361.67Smycroft	if [ "$timed_flags" = DEFAULT ]; then
3371.67Smycroft		timed_flags=""
3381.67Smycroft	fi
3391.67Smycroft	echo -n ' timed'; 		timed $timed_flags
3401.75Sperryfi
3411.75Sperry
3421.75Sperryif [ "$ntpdate_hosts" != NO ]; then
3431.75Sperry	if [ "$ntpdate_hosts" = DEFAULT ]; then
3441.75Sperry		ntpdate_hosts=`awk '/^server/ {print $2}' </etc/ntp.conf`
3451.75Sperry	fi
3461.75Sperry
3471.75Sperry	if [ -n "$ntpdate_hosts"  ]; then
3481.75Sperry		echo -n 'ntpdate:'
3491.75Sperry		ntpdate -b $ntpdate_hosts
3501.75Sperry	fi
3511.63Smrgfi
3521.63Smrg
3531.67Smycroftif [ "$xntpd_flags" != NO ]; then
3541.67Smycroft	if [ "$xntpd_flags" = DEFAULT ]; then
3551.77Scjs		xntpd_flags="-p /var/run/xntpd.pid"
3561.67Smycroft	fi
3571.67Smycroft	echo -n ' xntpd';		xntpd $xntpd_flags
3581.61Smrgfi
3591.61Smrg
3601.67Smycroftif [ "$dhcpd_flags" != NO ] && [ -r /etc/dhcpd.conf ]; then
3611.67Smycroft	if [ "$dhcpd_flags" = DEFAULT ]; then
3621.67Smycroft		dhcpd_flags=""
3631.67Smycroft	fi
3641.61Smrg	echo -n ' dhcpd';		dhcpd $dhcpd_flags
3651.29Smycroftfi
3661.29Smycroft
3671.67Smycroftif [ "$rwhod" = YES ]; then
3681.48Smycroft	echo -n ' rwhod';		rwhod
3691.1Scgdfi
3701.1Scgd
3711.67Smycroftif [ "$lpd_flags" != NO ]; then
3721.67Smycroft	if [ "$lpd_flags" = DEFAULT ]; then
3731.67Smycroft		lpd_flags=""
3741.67Smycroft	fi
3751.63Smrg	echo -n ' printer';		lpd $lpd_flags
3761.60Stlsfi
3771.60Stls
3781.63Smrg# We call sendmail with a full path so that SIGHUP works.
3791.67Smycroftif [ "$sendmail_flags" != NO ] && [ -r /etc/sendmail.cf ]; then
3801.67Smycroft	if [ "$sendmail_flags" = DEFAULT ]; then
3811.67Smycroft		sendmail_flags="-bd -q30m"
3821.67Smycroft	fi
3831.63Smrg	echo -n ' sendmail';		/usr/sbin/sendmail $sendmail_flags
3841.60Stlsfi
3851.60Stls
3861.67Smycroftif [ "$rarpd_flags" != NO ] && [ -r /etc/ethers ]; then
3871.67Smycroft	if [ "$rarpd_flags" = DEFAULT ]; then
3881.67Smycroft		rarpd_flags="-a"
3891.67Smycroft	fi
3901.63Smrg	echo -n ' rarpd';		rarpd $rarpd_flags
3911.60Stlsfi
3921.60Stls
3931.67Smycroftif [ "$rbootd_flags" != NO ] && [ -r /etc/rbootd.conf ]; then
3941.67Smycroft	if [ "$rbootd_flags" = DEFAULT ]; then
3951.67Smycroft		rbootd_flags=""
3961.67Smycroft	fi
3971.63Smrg	echo -n ' rbootd';		rbootd $rbootd_flags
3981.72Scjsfi
3991.72Scjs
4001.72Scjsif [ "$mopd_flags" != NO ]; then
4011.72Scjs	if [ "$mopd_flags" = DEFAULT ]; then
4021.72Scjs		mopd_flags="-a"
4031.72Scjs	fi
4041.72Scjs	echo -n ' mopd';		mopd $mopd_flags
4051.52Sthorpejfi
4061.52Sthorpej
4071.67Smycroftif [ "$inetd_flags" != NO ] && [ -r /etc/inetd.conf ]; then
4081.67Smycroft	if [ "$inetd_flags" = DEFAULT ]; then
4091.67Smycroft		inetd_flags=""
4101.67Smycroft	fi
4111.63Smrg	echo -n ' inetd';		inetd $inetd_flags
4121.30Smycroftfi
4131.30Smycroft
4141.1Scgdecho '.'
4151.73Sperry
4161.73Sperry# Kerberos runs ONLY on the Kerberos server machine
4171.73Sperryif [ "$kerberos_server" = YES ]; then
4181.73Sperry	echo -n 'starting kerberos daemons:'
4191.73Sperry	echo -n ' kerberos';	kerberos >> /var/log/kerberos.log &
4201.73Sperry	echo -n ' kadmind';	kadmind -n >> /var/log/kadmind.log &
4211.73Sperry	echo '.'
4221.73Sperryfi
4231.1Scgd
4241.25Smycroft. /etc/rc.local
4251.1Scgd
4261.1Scgddate
4271.1Scgdexit 0
428