rc revision 1.89
11.89Scjs#	$NetBSD: rc,v 1.89 1997/08/29 02:24:05 cjs 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.89Scjsif [ -f /etc/rc.func ]; then
711.89Scjs	. /etc/rc.func
721.89Scjselse
731.89Scjs	echo "Can't read /etc/rc.func; 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.67Smycroftif [ "$lkm_init" != NO ] && [ -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.82Sveegomount /usr >/dev/null 2>&1
1081.42Smycroftmount /var >/dev/null 2>&1
1091.79Sthorpej
1101.79Sthorpej# "Critical" file systems are now mounted.  Go ahead and swap
1111.79Sthorpej# to files now, since they will be residing in the critical file
1121.79Sthorpej# systems (or, at least, better).
1131.79Sthorpejswapctl -A -t noblk
1141.26Sderaadt
1151.41Sjtc# clean up left-over files
1161.41Sjtcrm -f /etc/nologin
1171.41Sjtcrm -f /var/spool/lock/LCK.*
1181.41Sjtcrm -f /var/spool/uucp/STST/*
1191.45Scgd(cd /var/run && { rm -rf -- *; install -c -m 664 -g utmp /dev/null utmp; })
1201.41Sjtc
1211.84Sveego# start the system logger first, so that all messages from daemons
1221.84Sveego# are logged, then start savecore to get a dump on low memory systems
1231.84Sveego# and then start the name server.
1241.63Smrg
1251.89Scjsif checkyesno syslogd; then
1261.63Smrg	echo 'starting system logger'
1271.63Smrg	rm -f /dev/log
1281.63Smrg	syslogd $syslogd_flags
1291.63Smrgfi
1301.63Smrg
1311.84Sveego# /var/crash should be a directory or a symbolic link
1321.84Sveego# to the crash directory if core dumps are to be saved.
1331.89Scjsif checkyesno savecore; then
1341.89Scjs	if [ -d /var/crash ]; then
1351.89Scjs		echo checking for core dump...
1361.89Scjs		savecore $savecore_flags /var/crash
1371.89Scjs	else
1381.89Scjs		logger -s "WARNING: no /var/crash directory; savecore not run."
1391.84Sveego	fi
1401.84Sveegofi
1411.84Sveego
1421.89Scjsif checkyesno named; then
1431.89Scjs	echo 'starting name server';	named $named_flags
1441.89Scjsfi
1451.89Scjs
1461.89Scjs# set time, if requested
1471.89Scjsif checkyesno ntpdate; then
1481.89Scjs	if [ "$ntpdate_hosts" = DEFAULT ]; then
1491.89Scjs		ntpdate_hosts=`awk '/^server/ {print $2}' </etc/ntp.conf`
1501.89Scjs	fi
1511.89Scjs	if [ -n "$ntpdate_hosts"  ]; then
1521.89Scjs		echo 'Setting date via ntp.'
1531.89Scjs		ntpdate -b $ntpdate_hosts
1541.67Smycroft	fi
1551.63Smrgfi
1561.63Smrg
1571.84Sveego# now start the rpc servers, for YP server/client.
1581.63Smrgecho -n 'starting rpc daemons:'
1591.63Smrg
1601.63Smrg# note that portmap is generally required for all other rpc services.
1611.89Scjsif checkyesno portmap; then
1621.63Smrg	echo -n ' portmap';             portmap
1631.63Smrgfi
1641.63Smrg
1651.89Scjsif checkyesno ypserv; then
1661.63Smrg        echo -n ' ypserv';              ypserv $ypserv_flags
1671.63Smrgfi
1681.63Smrg
1691.89Scjsif checkyesno ypbind; then
1701.63Smrg        echo -n ' ypbind';              ypbind $ypbind_flags
1711.63Smrgfi
1721.63Smrg
1731.89Scjsif checkyesno yppasswdd; then
1741.63Smrg        echo -n ' rpc.yppasswdd';       rpc.yppasswdd $yppasswdd_flags
1751.63Smrgfi
1761.63Smrg
1771.89Scjsif checkyesno bootparamd; then
1781.89Scjs	if [ -r /etc/bootparams ]; then
1791.89Scjs		echo -n ' rpc.bootparamd'; rpc.bootparamd $bootparamd_flags
1801.89Scjs	else
1811.89Scjs		echo
1821.89Scjs		logger -s "WARNING: /etc/bootparams not found. " \
1831.89Scjs		    "bootparamd not started."
1841.67Smycroft	fi
1851.63Smrgfi
1861.63Smrg
1871.84Sveegoecho '.'
1881.84Sveego
1891.84Sveego# load kernel modules specified in /etc/lkm.conf
1901.89Scjsif checkyesno lkm; then
1911.89Scjs	if [ -r /etc/rc.lkm ]; then
1921.89Scjs		lkmstage=BEFOREMOUNT
1931.89Scjs		. /etc/rc.lkm
1941.89Scjs	else
1951.89Scjs		logger -s "WARNING: /etc/rc.lkm not found; LKMs not loaded."
1961.89Scjs	fi
1971.84Sveegofi
1981.84Sveego
1991.84Sveegomount -a
2001.84Sveego
2011.84Sveego# now start the rpc servers, for NFS server/client.
2021.84Sveegoecho -n 'starting nfs-rpc daemons:'
2031.84Sveego
2041.67Smycroftnfs_locking=NO
2051.67Smycroft
2061.89Scjsif checkyesno nfs_server; then
2071.89Scjs	if [ -r /etc/exports ]; then
2081.89Scjs		rm -f /var/db/mountdtab
2091.89Scjs		echo -n > /var/db/mountdtab
2101.89Scjs		echo -n ' mountd';              mountd $mountd_flags
2111.89Scjs		echo -n ' nfsd';                nfsd $nfsd_flags
2121.89Scjs		nfs_locking=MAYBE
2131.89Scjs	else
2141.89Scjs		echo
2151.89Scjs		logger -s "WARNING: /etc/exports not readable; " \
2161.89Scjs		    "NFS server not started."
2171.69Smycroft	fi
2181.1Scgdfi
2191.63Smrg
2201.89Scjsif checkyesno nfs_client; then
2211.63Smrg        echo -n ' nfsiod';              nfsiod $nfsiod_flags
2221.67Smycroft	nfs_locking=MAYBE
2231.66Sscottrfi
2241.66Sscottr
2251.67Smycroftif [ "$nfs_locking" != NO ]; then
2261.89Scjs	if checkyesno statd; then
2271.71Smycroft		echo -n ' rpc.statd';		rpc.statd $statd_flags
2281.66Sscottr	fi
2291.89Scjs	if checkyesno lockd; then
2301.71Smycroft		echo -n ' rpc.lockd';		rpc.lockd $lockd_flags
2311.66Sscottr	fi
2321.63Smrgfi
2331.63Smrg
2341.89Scjsif checkyesno amd; then
2351.89Scjs	if [ -d "$amd_dir" ]; then
2361.89Scjs		if [ -r "$amd_master" ]; then
2371.89Scjs			echo -n ' amd'
2381.89Scjs			amd $amd_flags -p -a $amd_dir `cat $amd_master` \
2391.89Scjs			    > /var/run/amd.pid
2401.89Scjs		else
2411.89Scjs			echo
2421.89Scjs			logger -s "WARNING: \$amd_master ($amd_master)not " \
2431.89Scjs			    "readable; amd not started."
2441.89Scjs		fi
2451.89Scjs	else
2461.89Scjs		echo
2471.89Scjs		logger -s "WARNING: \$amd_dir ($amd_dir) not a directory; " \
2481.89Scjs		    "amd not started."
2491.67Smycroft	fi
2501.63Smrgfi
2511.63Smrg
2521.1Scgdecho '.'
2531.83Sdrochner
2541.63Smrgif [ -f /sbin/ldconfig ]; then
2551.63Smrg	echo 'creating runtime link editor directory cache.'
2561.88Sthorpej	ldconfig
2571.63Smrgfi 
2581.83Sdrochner
2591.83Sdrochner# load kernel modules specified in /etc/lkm.conf
2601.89Scjsif checkyesno lkm && [ -f /etc/rc.lkm ]; then
2611.83Sdrochner	lkmstage=AFTERMOUNT
2621.83Sdrochner	. /etc/rc.lkm
2631.1Scgdfi
2641.1Scgd
2651.89Scjsecho -n 'checking quotas:'; quotacheck -a; echo ' done.'
2661.47Sderaadtquotaon -a
2671.1Scgd
2681.1Scgd# build ps databases
2691.2Scgdecho 'building databases...'
2701.11Scgdkvm_mkdb /netbsd
2711.1Scgddev_mkdb
2721.1Scgd
2731.1Scgdchmod 666 /dev/tty[pqrs]*
2741.1Scgd
2751.1Scgd# check the password temp/lock file
2761.1Scgdif [ -f /etc/ptmp ]
2771.1Scgdthen
2781.1Scgd	logger -s -p auth.err \
2791.1Scgd	'password file may be incorrect -- /etc/ptmp exists'
2801.1Scgdfi
2811.1Scgd
2821.85Sperryvirecovery=`echo /var/tmp/vi.recover/recover.*`
2831.32Smycroftif [ "$virecovery" != "/var/tmp/vi.recover/recover.*" ]; then
2841.32Smycroft	echo preserving editor files
2851.32Smycroft	for i in $virecovery; do
2861.32Smycroft		sendmail -t < $i
2871.32Smycroft	done
2881.32Smycroftfi
2891.1Scgd
2901.1Scgdecho clearing /tmp
2911.1Scgd
2921.65Smikel# Prune quickly with one rm, then use find to clean up /tmp/[lq]* (this
2931.65Smikel# is not needed with mfs /tmp, but doesn't hurt anything).
2941.1Scgd(cd /tmp && rm -rf [a-km-pr-zA-Z]* &&
2951.46Sderaadt    find . ! -name . ! -name lost+found ! -name quota.user \
2961.46Sderaadt	! -name quota.group -exec rm -rf -- {} \; -type d -prune)
2971.1Scgd
2981.74Sperry# Update kernel info in /etc/motd
2991.74Sperry# Must be done *before* interactive logins are possible to prevent
3001.74Sperry# possible race conditions.
3011.89Scjsif checkyesno update_motd; then
3021.74Sperry	echo 'updating motd.'
3031.74Sperry	if [ ! -f /etc/motd ]; then
3041.74Sperry		install -c -o root -g wheel -m 664 /dev/null /etc/motd
3051.74Sperry	fi
3061.74Sperry	T=/tmp/_motd
3071.74Sperry	rm -f $T
3081.74Sperry	sysctl -n kern.version | sed 1q > $T
3091.74Sperry	echo "" >> $T
3101.74Sperry	sed '1,/^$/d' < /etc/motd >> $T
3111.74Sperry	cmp -s $T /etc/motd || cp $T /etc/motd
3121.74Sperry	rm -f $T
3131.74Sperryfi
3141.74Sperry
3151.34Scgdif [ -f /var/account/acct ]; then
3161.34Scgd	echo 'turning on accounting';	accton /var/account/acct
3171.34Scgdfi
3181.1Scgd
3191.1Scgdecho -n standard daemons:
3201.89Scjsif checkyesno update; then
3211.70Smycroft	echo -n ' update';		update $update_flags
3221.70Smycroftfi
3231.31Sjtcecho -n ' cron';		cron
3241.1Scgdecho '.'
3251.1Scgd
3261.63Smrg# now start all the other daemons
3271.1Scgdecho -n starting network daemons:
3281.1Scgd
3291.89Scjsif checkyesno gated && checkyesno routed; then
3301.89Scjs	echo
3311.89Scjs	logger -s "WARNING: gated and routed both requested to be run: " \
3321.89Scjs	    "running only gated."
3331.89Scjs	routed=NO
3341.89Scjsfi
3351.89Scjs
3361.89Scjsif checkyesno gated; then
3371.89Scjs	if [ -r /etc/gated.conf ]; then
3381.89Scjs		echo -n ' gated';		gated $gated_flags
3391.89Scjs	else
3401.89Scjs		logger -s "WARNING: no /etc/gated.conf; gated not started."
3411.67Smycroft	fi
3421.89Scjsfi
3431.89Scjs
3441.89Scjsif checkyesno routed; then
3451.48Smycroft	echo -n ' routed';		routed $routed_flags
3461.1Scgdfi
3471.1Scgd
3481.89Scjsif checkyesno mrouted; then
3491.55Sthorpej	echo -n ' mrouted';		mrouted $mrouted_flags
3501.55Sthorpejfi
3511.55Sthorpej
3521.89Scjsif checkyesno timed; then
3531.67Smycroft	echo -n ' timed'; 		timed $timed_flags
3541.63Smrgfi
3551.63Smrg
3561.89Scjsif checkyesno xntpd; then
3571.67Smycroft	echo -n ' xntpd';		xntpd $xntpd_flags
3581.61Smrgfi
3591.61Smrg
3601.89Scjsif checkyesno dhcpd; then
3611.89Scjs	if [ -r /etc/dhcpd.conf ]; then
3621.89Scjs		echo -n ' dhcpd';		dhcpd $dhcpd_flags
3631.89Scjs	else
3641.89Scjs		echo
3651.89Scjs		logger -s "WARNING: /etc/dhcpd.conf not readable; " \
3661.89Scjs		    "dhcpd not started."
3671.67Smycroft	fi
3681.29Smycroftfi
3691.29Smycroft
3701.89Scjsif checkyesno rwhod; then
3711.48Smycroft	echo -n ' rwhod';		rwhod
3721.1Scgdfi
3731.1Scgd
3741.89Scjsif checkyesno lpd; then
3751.89Scjs	echo -n ' lpd';			lpd $lpd_flags
3761.60Stlsfi
3771.60Stls
3781.63Smrg# We call sendmail with a full path so that SIGHUP works.
3791.89Scjsif checkyesno sendmail; then
3801.89Scjs	if [ -r /etc/sendmail.cf ]; then
3811.89Scjs		echo -n ' sendmail';	/usr/sbin/sendmail $sendmail_flags
3821.89Scjs	else
3831.89Scjs		echo
3841.89Scjs		logger -s "WARNING: /etc/sendmail.cf not readable; " \
3851.89Scjs		    "sendmail not started."
3861.67Smycroft	fi
3871.60Stlsfi
3881.60Stls
3891.89Scjsif checkyesno rarpd; then
3901.89Scjs	if [ -r /etc/ethers ]; then
3911.89Scjs		echo -n ' rarpd';	rarpd $rarpd_flags
3921.89Scjs	else
3931.89Scjs		echo
3941.89Scjs		logger -s "WARNING: /etc/ethers not readable; " \
3951.89Scjs		    "rarpd not started."
3961.67Smycroft	fi
3971.60Stlsfi
3981.60Stls
3991.89Scjsif checkyesno rbootd; then
4001.89Scjs	if [ -r /etc/rbootd.conf ]; then
4011.89Scjs		echo -n ' rbootd';	rbootd $rbootd_flags
4021.89Scjs	else
4031.89Scjs		echo
4041.89Scjs		logger -s "WARNING: /etc/rbootd.conf not readable; " \
4051.89Scjs		    "rarpd not started."
4061.67Smycroft	fi
4071.72Scjsfi
4081.72Scjs
4091.89Scjsif checkyesno mopd; then
4101.72Scjs	echo -n ' mopd';		mopd $mopd_flags
4111.86Sperryfi
4121.86Sperry
4131.89Scjsif checkyesno apmd; then
4141.86Sperry	echo -n ' apmd';		apmd $apmd_flags
4151.52Sthorpejfi
4161.52Sthorpej
4171.89Scjsif checkyesno inetd; then
4181.89Scjs	if [ -r /etc/inetd.conf ]; then
4191.89Scjs		echo -n ' inetd';	inetd $inetd_flags
4201.89Scjs	else
4211.89Scjs		echo
4221.89Scjs		logger -s "WARNING: /etc/inetd.conf not readable; " \
4231.89Scjs		    "inetd not started."
4241.67Smycroft	fi
4251.30Smycroftfi
4261.30Smycroft
4271.1Scgdecho '.'
4281.73Sperry
4291.73Sperry# Kerberos runs ONLY on the Kerberos server machine
4301.89Scjsif checkyesno kerberos; then
4311.73Sperry	echo -n 'starting kerberos daemons:'
4321.73Sperry	echo -n ' kerberos';	kerberos >> /var/log/kerberos.log &
4331.73Sperry	echo -n ' kadmind';	kadmind -n >> /var/log/kadmind.log &
4341.73Sperry	echo '.'
4351.73Sperryfi
4361.1Scgd
4371.25Smycroft. /etc/rc.local
4381.1Scgd
4391.1Scgddate
4401.1Scgdexit 0
441