rc revision 1.88
11.88Sthorpej#	$NetBSD: rc,v 1.88 1997/08/26 19:35:33 thorpej 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.84Sveego# start the system logger first, so that all messages from daemons
1101.84Sveego# are logged, then start savecore to get a dump on low memory systems
1111.84Sveego# and then start the name server.
1121.63Smrg
1131.67Smycroftif [ "$syslogd_flags" != NO ]; then
1141.67Smycroft	if [ "$syslogd_flags" = DEFAULT ]; then
1151.67Smycroft		syslogd_flags=""
1161.67Smycroft	fi
1171.63Smrg	echo 'starting system logger'
1181.63Smrg	rm -f /dev/log
1191.63Smrg	syslogd $syslogd_flags
1201.63Smrgfi
1211.63Smrg
1221.84Sveego# /var/crash should be a directory or a symbolic link
1231.84Sveego# to the crash directory if core dumps are to be saved.
1241.84Sveegoif [ "$savecore_flags" != NO ] && [ -d /var/crash ]; then
1251.84Sveego	if [ "$savecore_flags" = DEFAULT ]; then
1261.84Sveego		savecore_flags=""
1271.84Sveego	fi
1281.84Sveego	echo checking for core dump...
1291.84Sveego	savecore $savecore_flags /var/crash
1301.84Sveegofi
1311.84Sveego
1321.67Smycroftif [ "$named_flags" != NO ]; then
1331.67Smycroft	if [ "$named_flags" = DEFAULT ]; then
1341.67Smycroft		named_flags=""
1351.67Smycroft	fi
1361.63Smrg	echo 'starting name server';	named $named_flags
1371.63Smrgfi
1381.63Smrg
1391.84Sveego# now start the rpc servers, for YP server/client.
1401.63Smrgecho -n 'starting rpc daemons:'
1411.63Smrg
1421.63Smrg# note that portmap is generally required for all other rpc services.
1431.67Smycroftif [ "$portmap" != NO ]; then
1441.63Smrg	echo -n ' portmap';             portmap
1451.63Smrgfi
1461.63Smrg
1471.67Smycroftif [ "$ypserv_flags" != NO ]; then
1481.67Smycroft	if [ "$ypserv_flags" = DEFAULT ]; then
1491.67Smycroft		ypserv_flags="-d"
1501.67Smycroft	fi
1511.63Smrg        echo -n ' ypserv';              ypserv $ypserv_flags
1521.63Smrgfi
1531.63Smrg
1541.67Smycroftif [ "$ypbind_flags" != NO ]; then
1551.67Smycroft	if [ "$ypbind_flags" = DEFAULT ]; then
1561.67Smycroft		ypbind_flags=""
1571.67Smycroft	fi
1581.63Smrg        echo -n ' ypbind';              ypbind $ypbind_flags
1591.63Smrgfi
1601.63Smrg
1611.67Smycroftif [ "$yppasswdd_flags" != NO ]; then
1621.67Smycroft	if [ "$yppasswdd_flags" = DEFAULT ]; then
1631.67Smycroft		yppasswdd_flags=""
1641.67Smycroft	fi
1651.63Smrg        echo -n ' rpc.yppasswdd';       rpc.yppasswdd $yppasswdd_flags
1661.63Smrgfi
1671.63Smrg
1681.67Smycroftif [ "$bootparamd_flags" != NO ] && [ -r /etc/bootparams ]; then
1691.67Smycroft	if [ "$bootparamd_flags" = DEFAULT ]; then
1701.67Smycroft		bootparamd_flags=""
1711.67Smycroft	fi
1721.63Smrg        echo -n ' rpc.bootparamd';      rpc.bootparamd $bootparamd_flags
1731.63Smrgfi
1741.63Smrg
1751.84Sveegoecho '.'
1761.84Sveego
1771.84Sveego# load kernel modules specified in /etc/lkm.conf
1781.84Sveegoif [ "$lkm_init" != NO ] && [ -f /etc/rc.lkm ]; then
1791.84Sveego	lkmstage=BEFOREMOUNT
1801.84Sveego	. /etc/rc.lkm
1811.84Sveegofi
1821.84Sveego
1831.84Sveegomount -a
1841.84Sveego
1851.84Sveego# now start the rpc servers, for NFS server/client.
1861.84Sveegoecho -n 'starting nfs-rpc daemons:'
1871.84Sveego
1881.67Smycroftnfs_locking=NO
1891.67Smycroft
1901.67Smycroftif [ "$nfs_server" = YES ] && [ -r /etc/exports ]; then
1911.69Smycroft	if [ "$mountd_flags" = DEFAULT ]; then
1921.69Smycroft		mountd_flags=""
1931.63Smrg	fi
1941.63Smrg        rm -f /var/db/mountdtab
1951.63Smrg        echo -n > /var/db/mountdtab
1961.63Smrg        echo -n ' mountd';              mountd $mountd_flags
1971.69Smycroft	if [ "$nfsd_flags" = DEFAULT ]; then
1981.69Smycroft		nfsd_flags="-tun 4"
1991.69Smycroft	fi
2001.63Smrg        echo -n ' nfsd';                nfsd $nfsd_flags
2011.67Smycroft	nfs_locking=MAYBE
2021.1Scgdfi
2031.63Smrg
2041.67Smycroftif [ "$nfs_client" = YES ]; then
2051.67Smycroft	if [ "$nfsiod_flags" = DEFAULT ]; then
2061.63Smrg		nfsiod_flags="-n 4"
2071.63Smrg	fi
2081.63Smrg        echo -n ' nfsiod';              nfsiod $nfsiod_flags
2091.67Smycroft	nfs_locking=MAYBE
2101.66Sscottrfi
2111.66Sscottr
2121.67Smycroftif [ "$nfs_locking" != NO ]; then
2131.67Smycroft	if [ "$statd_flags" != NO ]; then
2141.67Smycroft		if [ "$statd_flags" = DEFAULT ]; then
2151.67Smycroft			statd_flags=""
2161.67Smycroft		fi
2171.71Smycroft		echo -n ' rpc.statd';		rpc.statd $statd_flags
2181.66Sscottr	fi
2191.66Sscottr
2201.67Smycroft	if [ "$lockd_flags" != NO ]; then
2211.67Smycroft		if [ "$lockd_flags" = DEFAULT ]; then
2221.67Smycroft			lockd_flags=""
2231.67Smycroft		fi
2241.71Smycroft		echo -n ' rpc.lockd';		rpc.lockd $lockd_flags
2251.66Sscottr	fi
2261.63Smrgfi
2271.63Smrg
2281.67Smycroftif [ "$amd_flags" != NO ] && [ -d "$amd_dir" -a -r "$amd_master" ]; then
2291.67Smycroft	if [ "$amd_flags" = DEFAULT ]; then
2301.67Smycroft		amd_flags="-l syslog -x error,noinfo,nostats"
2311.67Smycroft	fi
2321.63Smrg        echo -n ' amd'
2331.63Smrg        amd $amd_flags -p -a $amd_dir `cat $amd_master` > /var/run/amd.pid
2341.63Smrgfi
2351.63Smrg
2361.1Scgdecho '.'
2371.83Sdrochner
2381.63Smrgif [ -f /sbin/ldconfig ]; then
2391.63Smrg	echo 'creating runtime link editor directory cache.'
2401.88Sthorpej	ldconfig
2411.63Smrgfi 
2421.83Sdrochner
2431.83Sdrochner# load kernel modules specified in /etc/lkm.conf
2441.83Sdrochnerif [ "$lkm_init" != NO ] && [ -f /etc/rc.lkm ]; then
2451.83Sdrochner	lkmstage=AFTERMOUNT
2461.83Sdrochner	. /etc/rc.lkm
2471.1Scgdfi
2481.1Scgd
2491.47Sderaadt				echo -n 'checking quotas:'
2501.47Sderaadtquotacheck -a
2511.47Sderaadt				echo ' done.'
2521.47Sderaadtquotaon -a
2531.1Scgd
2541.1Scgd# build ps databases
2551.2Scgdecho 'building databases...'
2561.11Scgdkvm_mkdb /netbsd
2571.1Scgddev_mkdb
2581.1Scgd
2591.1Scgdchmod 666 /dev/tty[pqrs]*
2601.1Scgd
2611.1Scgd# check the password temp/lock file
2621.1Scgdif [ -f /etc/ptmp ]
2631.1Scgdthen
2641.1Scgd	logger -s -p auth.err \
2651.1Scgd	'password file may be incorrect -- /etc/ptmp exists'
2661.1Scgdfi
2671.1Scgd
2681.85Sperryvirecovery=`echo /var/tmp/vi.recover/recover.*`
2691.32Smycroftif [ "$virecovery" != "/var/tmp/vi.recover/recover.*" ]; then
2701.32Smycroft	echo preserving editor files
2711.32Smycroft	for i in $virecovery; do
2721.32Smycroft		sendmail -t < $i
2731.32Smycroft	done
2741.32Smycroftfi
2751.1Scgd
2761.1Scgdecho clearing /tmp
2771.1Scgd
2781.65Smikel# Prune quickly with one rm, then use find to clean up /tmp/[lq]* (this
2791.65Smikel# is not needed with mfs /tmp, but doesn't hurt anything).
2801.1Scgd(cd /tmp && rm -rf [a-km-pr-zA-Z]* &&
2811.46Sderaadt    find . ! -name . ! -name lost+found ! -name quota.user \
2821.46Sderaadt	! -name quota.group -exec rm -rf -- {} \; -type d -prune)
2831.1Scgd
2841.74Sperry# Update kernel info in /etc/motd
2851.74Sperry# Must be done *before* interactive logins are possible to prevent
2861.74Sperry# possible race conditions.
2871.74Sperryif [ "$update_motd" != NO ]; then
2881.74Sperry	echo 'updating motd.'
2891.74Sperry	if [ ! -f /etc/motd ]; then
2901.74Sperry		install -c -o root -g wheel -m 664 /dev/null /etc/motd
2911.74Sperry	fi
2921.74Sperry	T=/tmp/_motd
2931.74Sperry	rm -f $T
2941.74Sperry	sysctl -n kern.version | sed 1q > $T
2951.74Sperry	echo "" >> $T
2961.74Sperry	sed '1,/^$/d' < /etc/motd >> $T
2971.74Sperry	cmp -s $T /etc/motd || cp $T /etc/motd
2981.74Sperry	rm -f $T
2991.74Sperryfi
3001.74Sperry
3011.34Scgdif [ -f /var/account/acct ]; then
3021.34Scgd	echo 'turning on accounting';	accton /var/account/acct
3031.34Scgdfi
3041.1Scgd
3051.1Scgdecho -n standard daemons:
3061.70Smycroftif [ "$update_flags" != NO ]; then
3071.70Smycroft	if [ "$update_flags" = DEFAULT ]; then
3081.70Smycroft		update_flags="30"
3091.70Smycroft	fi
3101.70Smycroft	echo -n ' update';		update $update_flags
3111.70Smycroftfi
3121.31Sjtcecho -n ' cron';		cron
3131.1Scgdecho '.'
3141.1Scgd
3151.87Scjs# set time, if requested
3161.87Scjsif [ "$ntpdate_hosts" != NO ]; then
3171.87Scjs	if [ "$ntpdate_hosts" = DEFAULT ]; then
3181.87Scjs		ntpdate_hosts=`awk '/^server/ {print $2}' </etc/ntp.conf`
3191.87Scjs	fi
3201.87Scjs	if [ -n "$ntpdate_hosts"  ]; then
3211.87Scjs		echo 'Setting date via ntp.'
3221.87Scjs		ntpdate -b $ntpdate_hosts
3231.87Scjs	fi
3241.87Scjsfi
3251.87Scjs
3261.63Smrg# now start all the other daemons
3271.1Scgdecho -n starting network daemons:
3281.1Scgd
3291.67Smycroftif [ "$gated_flags" != NO ] && [ -r /etc/gated.conf ]; then
3301.67Smycroft	if [ "$gated_flags" = DEFAULT ]; then
3311.67Smycroft		gated_flags=""
3321.67Smycroft	fi
3331.48Smycroft	echo -n ' gated';		gated $gated_flags
3341.67Smycroftelif [ "$routed_flags" != NO ]; then
3351.67Smycroft	if [ "$routed_flags" = DEFAULT ]; then
3361.67Smycroft		routed_flags="-q"
3371.67Smycroft	fi
3381.48Smycroft	echo -n ' routed';		routed $routed_flags
3391.1Scgdfi
3401.1Scgd
3411.67Smycroftif [ "$mrouted_flags" != NO ]; then
3421.67Smycroft	if [ "$mrouted_flags" = DEFAULT ]; then
3431.67Smycroft		mrouted_flags=""
3441.67Smycroft	fi
3451.55Sthorpej	echo -n ' mrouted';		mrouted $mrouted_flags
3461.55Sthorpejfi
3471.55Sthorpej
3481.67Smycroftif [ "$timed_flags" != NO ]; then
3491.67Smycroft	if [ "$timed_flags" = DEFAULT ]; then
3501.67Smycroft		timed_flags=""
3511.67Smycroft	fi
3521.67Smycroft	echo -n ' timed'; 		timed $timed_flags
3531.63Smrgfi
3541.63Smrg
3551.67Smycroftif [ "$xntpd_flags" != NO ]; then
3561.67Smycroft	if [ "$xntpd_flags" = DEFAULT ]; then
3571.77Scjs		xntpd_flags="-p /var/run/xntpd.pid"
3581.67Smycroft	fi
3591.67Smycroft	echo -n ' xntpd';		xntpd $xntpd_flags
3601.61Smrgfi
3611.61Smrg
3621.67Smycroftif [ "$dhcpd_flags" != NO ] && [ -r /etc/dhcpd.conf ]; then
3631.67Smycroft	if [ "$dhcpd_flags" = DEFAULT ]; then
3641.67Smycroft		dhcpd_flags=""
3651.67Smycroft	fi
3661.61Smrg	echo -n ' dhcpd';		dhcpd $dhcpd_flags
3671.29Smycroftfi
3681.29Smycroft
3691.67Smycroftif [ "$rwhod" = YES ]; then
3701.48Smycroft	echo -n ' rwhod';		rwhod
3711.1Scgdfi
3721.1Scgd
3731.67Smycroftif [ "$lpd_flags" != NO ]; then
3741.67Smycroft	if [ "$lpd_flags" = DEFAULT ]; then
3751.67Smycroft		lpd_flags=""
3761.67Smycroft	fi
3771.63Smrg	echo -n ' printer';		lpd $lpd_flags
3781.60Stlsfi
3791.60Stls
3801.63Smrg# We call sendmail with a full path so that SIGHUP works.
3811.67Smycroftif [ "$sendmail_flags" != NO ] && [ -r /etc/sendmail.cf ]; then
3821.67Smycroft	if [ "$sendmail_flags" = DEFAULT ]; then
3831.67Smycroft		sendmail_flags="-bd -q30m"
3841.67Smycroft	fi
3851.63Smrg	echo -n ' sendmail';		/usr/sbin/sendmail $sendmail_flags
3861.60Stlsfi
3871.60Stls
3881.67Smycroftif [ "$rarpd_flags" != NO ] && [ -r /etc/ethers ]; then
3891.67Smycroft	if [ "$rarpd_flags" = DEFAULT ]; then
3901.67Smycroft		rarpd_flags="-a"
3911.67Smycroft	fi
3921.63Smrg	echo -n ' rarpd';		rarpd $rarpd_flags
3931.60Stlsfi
3941.60Stls
3951.67Smycroftif [ "$rbootd_flags" != NO ] && [ -r /etc/rbootd.conf ]; then
3961.67Smycroft	if [ "$rbootd_flags" = DEFAULT ]; then
3971.67Smycroft		rbootd_flags=""
3981.67Smycroft	fi
3991.63Smrg	echo -n ' rbootd';		rbootd $rbootd_flags
4001.72Scjsfi
4011.72Scjs
4021.72Scjsif [ "$mopd_flags" != NO ]; then
4031.72Scjs	if [ "$mopd_flags" = DEFAULT ]; then
4041.72Scjs		mopd_flags="-a"
4051.72Scjs	fi
4061.72Scjs	echo -n ' mopd';		mopd $mopd_flags
4071.86Sperryfi
4081.86Sperry
4091.86Sperryif [ "$apmd_flags" != NO ]; then
4101.86Sperry	if [ "$apmd_flags" = DEFAULT ]; then
4111.86Sperry		apmd_flags=""
4121.86Sperry	fi
4131.86Sperry	echo -n ' apmd';		apmd $apmd_flags
4141.52Sthorpejfi
4151.52Sthorpej
4161.67Smycroftif [ "$inetd_flags" != NO ] && [ -r /etc/inetd.conf ]; then
4171.67Smycroft	if [ "$inetd_flags" = DEFAULT ]; then
4181.67Smycroft		inetd_flags=""
4191.67Smycroft	fi
4201.63Smrg	echo -n ' inetd';		inetd $inetd_flags
4211.30Smycroftfi
4221.30Smycroft
4231.1Scgdecho '.'
4241.73Sperry
4251.73Sperry# Kerberos runs ONLY on the Kerberos server machine
4261.73Sperryif [ "$kerberos_server" = YES ]; then
4271.73Sperry	echo -n 'starting kerberos daemons:'
4281.73Sperry	echo -n ' kerberos';	kerberos >> /var/log/kerberos.log &
4291.73Sperry	echo -n ' kadmind';	kadmind -n >> /var/log/kadmind.log &
4301.73Sperry	echo '.'
4311.73Sperryfi
4321.1Scgd
4331.25Smycroft. /etc/rc.local
4341.1Scgd
4351.1Scgddate
4361.1Scgdexit 0
437