rc revision 1.72
11.72Scjs#	$NetBSD: rc,v 1.72 1997/03/17 00:05:12 cjs Exp $
21.45Scgd#	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.63Smrgif [ -e /fastboot ]; then
251.38Scgd	echo "Fast boot: skipping disk checks."
261.68Smycroftelif [ "$1" = autoboot ]; then
271.38Scgd	echo "Automatic boot in progress: starting file system checks."
281.1Scgd	fsck -p
291.1Scgd	case $? in
301.1Scgd	0)
311.1Scgd		;;
321.1Scgd	2)
331.1Scgd		exit 1
341.1Scgd		;;
351.1Scgd	4)
361.35Scgd		echo "Rebooting..."
371.1Scgd		reboot
381.38Scgd		echo "Reboot failed; help!"
391.1Scgd		exit 1
401.1Scgd		;;
411.1Scgd	8)
421.38Scgd		echo "Automatic file system check failed; help!"
431.1Scgd		exit 1
441.1Scgd		;;
451.1Scgd	12)
461.38Scgd		echo "Boot interrupted."
471.1Scgd		exit 1
481.1Scgd		;;
491.1Scgd	130)
501.1Scgd		# interrupt before catcher installed
511.1Scgd		exit 1
521.1Scgd		;;
531.1Scgd	*)
541.38Scgd		echo "Unknown error; help!"
551.1Scgd		exit 1
561.1Scgd		;;
571.1Scgd	esac
581.1Scgdfi
591.1Scgd
601.38Scgdtrap "echo 'Boot interrupted.'; exit 1" 3
611.1Scgd
621.1Scgdswapon -a
631.1Scgd
641.1Scgdumount -a >/dev/null 2>&1
651.1Scgdmount -a -t nonfs
661.1Scgdrm -f /fastboot		# XXX (root now writeable)
671.40Scgd
681.71Smycroftif [ -f /etc/rc.conf ]; then
691.63Smrg	. /etc/rc.conf
701.63Smrgfi
711.63Smrg
721.40Scgd# set flags on ttys.  (do early, in case they use tty for SLIP in netstart)
731.40Scgdecho 'setting tty flags'
741.40Scgdttyflags -a
751.1Scgd
761.63Smrg# load any kernel modules specified in /etc/lkm.conf
771.67Smycroftif [ "$lkm_init" != NO ] && [ -f /etc/rc.lkm ]; then
781.63Smrg	. /etc/rc.lkm
791.63Smrgfi
801.63Smrg
811.1Scgd# set hostname, turn on network
821.1Scgdecho 'starting network'
831.1Scgd. /etc/netstart
841.1Scgd
851.26Sderaadtmount /usr >/dev/null 2>&1
861.42Smycroftmount /var >/dev/null 2>&1
871.26Sderaadt
881.41Sjtc# clean up left-over files
891.41Sjtcrm -f /etc/nologin
901.41Sjtcrm -f /var/spool/lock/LCK.*
911.41Sjtcrm -f /var/spool/uucp/STST/*
921.45Scgd(cd /var/run && { rm -rf -- *; install -c -m 664 -g utmp /dev/null utmp; })
931.41Sjtc
941.63Smrg# start the system logger first, so that all messages
951.63Smrg# from daemons are logged, and the name server next.
961.63Smrg
971.67Smycroftif [ "$syslogd_flags" != NO ]; then
981.67Smycroft	if [ "$syslogd_flags" = DEFAULT ]; then
991.67Smycroft		syslogd_flags=""
1001.67Smycroft	fi
1011.63Smrg	echo 'starting system logger'
1021.63Smrg	rm -f /dev/log
1031.63Smrg	syslogd $syslogd_flags
1041.63Smrgfi
1051.63Smrg
1061.67Smycroftif [ "$named_flags" != NO ]; then
1071.67Smycroft	if [ "$named_flags" = DEFAULT ]; then
1081.67Smycroft		named_flags=""
1091.67Smycroft	fi
1101.63Smrg	echo 'starting name server';	named $named_flags
1111.63Smrgfi
1121.63Smrg
1131.63Smrg# now start the rpc servers, for YP server/client, NFS.
1141.63Smrgecho -n 'starting rpc daemons:'
1151.63Smrg
1161.63Smrg# note that portmap is generally required for all other rpc services.
1171.67Smycroftif [ "$portmap" != NO ]; then
1181.63Smrg	echo -n ' portmap';             portmap
1191.63Smrgfi
1201.63Smrg
1211.67Smycroftif [ "$ypserv_flags" != NO ]; then
1221.67Smycroft	if [ "$ypserv_flags" = DEFAULT ]; then
1231.67Smycroft		ypserv_flags="-d"
1241.67Smycroft	fi
1251.63Smrg        echo -n ' ypserv';              ypserv $ypserv_flags
1261.63Smrgfi
1271.63Smrg
1281.67Smycroftif [ "$ypbind_flags" != NO ]; then
1291.67Smycroft	if [ "$ypbind_flags" = DEFAULT ]; then
1301.67Smycroft		ypbind_flags=""
1311.67Smycroft	fi
1321.63Smrg        echo -n ' ypbind';              ypbind $ypbind_flags
1331.63Smrgfi
1341.63Smrg
1351.67Smycroftif [ "$yppasswdd_flags" != NO ]; then
1361.67Smycroft	if [ "$yppasswdd_flags" = DEFAULT ]; then
1371.67Smycroft		yppasswdd_flags=""
1381.67Smycroft	fi
1391.63Smrg        echo -n ' rpc.yppasswdd';       rpc.yppasswdd $yppasswdd_flags
1401.63Smrgfi
1411.63Smrg
1421.67Smycroftif [ "$bootparamd_flags" != NO ] && [ -r /etc/bootparams ]; then
1431.67Smycroft	if [ "$bootparamd_flags" = DEFAULT ]; then
1441.67Smycroft		bootparamd_flags=""
1451.67Smycroft	fi
1461.63Smrg        echo -n ' rpc.bootparamd';      rpc.bootparamd $bootparamd_flags
1471.63Smrgfi
1481.63Smrg
1491.67Smycroftnfs_locking=NO
1501.67Smycroft
1511.67Smycroftif [ "$nfs_server" = YES ] && [ -r /etc/exports ]; then
1521.69Smycroft	if [ "$mountd_flags" = DEFAULT ]; then
1531.69Smycroft		mountd_flags=""
1541.63Smrg	fi
1551.63Smrg        rm -f /var/db/mountdtab
1561.63Smrg        echo -n > /var/db/mountdtab
1571.63Smrg        echo -n ' mountd';              mountd $mountd_flags
1581.69Smycroft	if [ "$nfsd_flags" = DEFAULT ]; then
1591.69Smycroft		nfsd_flags="-tun 4"
1601.69Smycroft	fi
1611.63Smrg        echo -n ' nfsd';                nfsd $nfsd_flags
1621.67Smycroft	nfs_locking=MAYBE
1631.1Scgdfi
1641.63Smrg
1651.67Smycroftif [ "$nfs_client" = YES ]; then
1661.67Smycroft	if [ "$nfsiod_flags" = DEFAULT ]; then
1671.63Smrg		nfsiod_flags="-n 4"
1681.63Smrg	fi
1691.63Smrg        echo -n ' nfsiod';              nfsiod $nfsiod_flags
1701.67Smycroft	nfs_locking=MAYBE
1711.66Sscottrfi
1721.66Sscottr
1731.67Smycroftif [ "$nfs_locking" != NO ]; then
1741.67Smycroft	if [ "$statd_flags" != NO ]; then
1751.67Smycroft		if [ "$statd_flags" = DEFAULT ]; then
1761.67Smycroft			statd_flags=""
1771.67Smycroft		fi
1781.71Smycroft		echo -n ' rpc.statd';		rpc.statd $statd_flags
1791.66Sscottr	fi
1801.66Sscottr
1811.67Smycroft	if [ "$lockd_flags" != NO ]; then
1821.67Smycroft		if [ "$lockd_flags" = DEFAULT ]; then
1831.67Smycroft			lockd_flags=""
1841.67Smycroft		fi
1851.71Smycroft		echo -n ' rpc.lockd';		rpc.lockd $lockd_flags
1861.66Sscottr	fi
1871.63Smrgfi
1881.63Smrg
1891.67Smycroftif [ "$amd_flags" != NO ] && [ -d "$amd_dir" -a -r "$amd_master" ]; then
1901.67Smycroft	if [ "$amd_flags" = DEFAULT ]; then
1911.67Smycroft		amd_flags="-l syslog -x error,noinfo,nostats"
1921.67Smycroft	fi
1931.63Smrg        echo -n ' amd'
1941.63Smrg        amd $amd_flags -p -a $amd_dir `cat $amd_master` > /var/run/amd.pid
1951.63Smrgfi
1961.63Smrg
1971.1Scgdecho '.'
1981.63Smrgmount -a -t nfs
1991.63Smrg
2001.63Smrgif [ -f /sbin/ldconfig ]; then
2011.63Smrg	echo 'creating runtime link editor directory cache.'
2021.71Smycroft	if [ -f /etc/ld.so.conf ]; then
2031.63Smrg		ldconfig `cat /etc/ld.so.conf`
2041.63Smrg	else
2051.63Smrg		ldconfig
2061.63Smrg	fi
2071.63Smrgfi 
2081.1Scgd
2091.1Scgd# /var/crash should be a directory or a symbolic link
2101.1Scgd# to the crash directory if core dumps are to be saved.
2111.67Smycroftif [ "$savecore_flags" != NO ] && [ -d /var/crash ]; then
2121.67Smycroft	if [ "$savecore_flags" = DEFAULT ]; then
2131.67Smycroft		savecore_flags=""
2141.67Smycroft	fi
2151.1Scgd	echo checking for core dump...
2161.63Smrg	savecore $savecore_flags /var/crash
2171.1Scgdfi
2181.1Scgd
2191.47Sderaadt				echo -n 'checking quotas:'
2201.47Sderaadtquotacheck -a
2211.47Sderaadt				echo ' done.'
2221.47Sderaadtquotaon -a
2231.1Scgd
2241.1Scgd# build ps databases
2251.2Scgdecho 'building databases...'
2261.11Scgdkvm_mkdb /netbsd
2271.1Scgddev_mkdb
2281.1Scgd
2291.1Scgdchmod 666 /dev/tty[pqrs]*
2301.1Scgd
2311.1Scgd# check the password temp/lock file
2321.1Scgdif [ -f /etc/ptmp ]
2331.1Scgdthen
2341.1Scgd	logger -s -p auth.err \
2351.1Scgd	'password file may be incorrect -- /etc/ptmp exists'
2361.1Scgdfi
2371.1Scgd
2381.32Smycroftvirecovery=/var/tmp/vi.recover/recover.*
2391.32Smycroftif [ "$virecovery" != "/var/tmp/vi.recover/recover.*" ]; then
2401.32Smycroft	echo preserving editor files
2411.32Smycroft	for i in $virecovery; do
2421.32Smycroft		sendmail -t < $i
2431.32Smycroft	done
2441.32Smycroftfi
2451.1Scgd
2461.1Scgdecho clearing /tmp
2471.1Scgd
2481.65Smikel# Prune quickly with one rm, then use find to clean up /tmp/[lq]* (this
2491.65Smikel# is not needed with mfs /tmp, but doesn't hurt anything).
2501.1Scgd(cd /tmp && rm -rf [a-km-pr-zA-Z]* &&
2511.46Sderaadt    find . ! -name . ! -name lost+found ! -name quota.user \
2521.46Sderaadt	! -name quota.group -exec rm -rf -- {} \; -type d -prune)
2531.1Scgd
2541.34Scgdif [ -f /var/account/acct ]; then
2551.34Scgd	echo 'turning on accounting';	accton /var/account/acct
2561.34Scgdfi
2571.1Scgd
2581.1Scgdecho -n standard daemons:
2591.70Smycroftif [ "$update_flags" != NO ]; then
2601.70Smycroft	if [ "$update_flags" = DEFAULT ]; then
2611.70Smycroft		update_flags="30"
2621.70Smycroft	fi
2631.70Smycroft	echo -n ' update';		update $update_flags
2641.70Smycroftfi
2651.31Sjtcecho -n ' cron';		cron
2661.1Scgdecho '.'
2671.1Scgd
2681.63Smrg# now start all the other daemons
2691.1Scgdecho -n starting network daemons:
2701.1Scgd
2711.67Smycroftif [ "$gated_flags" != NO ] && [ -r /etc/gated.conf ]; then
2721.67Smycroft	if [ "$gated_flags" = DEFAULT ]; then
2731.67Smycroft		gated_flags=""
2741.67Smycroft	fi
2751.48Smycroft	echo -n ' gated';		gated $gated_flags
2761.67Smycroftelif [ "$routed_flags" != NO ]; then
2771.67Smycroft	if [ "$routed_flags" = DEFAULT ]; then
2781.67Smycroft		routed_flags="-q"
2791.67Smycroft	fi
2801.48Smycroft	echo -n ' routed';		routed $routed_flags
2811.1Scgdfi
2821.1Scgd
2831.67Smycroftif [ "$mrouted_flags" != NO ]; then
2841.67Smycroft	if [ "$mrouted_flags" = DEFAULT ]; then
2851.67Smycroft		mrouted_flags=""
2861.67Smycroft	fi
2871.55Sthorpej	echo -n ' mrouted';		mrouted $mrouted_flags
2881.55Sthorpejfi
2891.55Sthorpej
2901.67Smycroftif [ "$timed_flags" != NO ]; then
2911.67Smycroft	if [ "$timed_flags" = DEFAULT ]; then
2921.67Smycroft		timed_flags=""
2931.67Smycroft	fi
2941.67Smycroft	echo -n ' timed'; 		timed $timed_flags
2951.63Smrgfi
2961.63Smrg
2971.67Smycroftif [ "$xntpd_flags" != NO ]; then
2981.67Smycroft	if [ "$xntpd_flags" = DEFAULT ]; then
2991.67Smycroft		xntpd_flags=""
3001.67Smycroft	fi
3011.67Smycroft	echo -n ' xntpd';		xntpd $xntpd_flags
3021.61Smrgfi
3031.61Smrg
3041.67Smycroftif [ "$dhcpd_flags" != NO ] && [ -r /etc/dhcpd.conf ]; then
3051.67Smycroft	if [ "$dhcpd_flags" = DEFAULT ]; then
3061.67Smycroft		dhcpd_flags=""
3071.67Smycroft	fi
3081.61Smrg	echo -n ' dhcpd';		dhcpd $dhcpd_flags
3091.29Smycroftfi
3101.29Smycroft
3111.67Smycroftif [ "$rwhod" = YES ]; then
3121.48Smycroft	echo -n ' rwhod';		rwhod
3131.1Scgdfi
3141.1Scgd
3151.67Smycroftif [ "$lpd_flags" != NO ]; then
3161.67Smycroft	if [ "$lpd_flags" = DEFAULT ]; then
3171.67Smycroft		lpd_flags=""
3181.67Smycroft	fi
3191.63Smrg	echo -n ' printer';		lpd $lpd_flags
3201.60Stlsfi
3211.60Stls
3221.63Smrg# We call sendmail with a full path so that SIGHUP works.
3231.67Smycroftif [ "$sendmail_flags" != NO ] && [ -r /etc/sendmail.cf ]; then
3241.67Smycroft	if [ "$sendmail_flags" = DEFAULT ]; then
3251.67Smycroft		sendmail_flags="-bd -q30m"
3261.67Smycroft	fi
3271.63Smrg	echo -n ' sendmail';		/usr/sbin/sendmail $sendmail_flags
3281.60Stlsfi
3291.60Stls
3301.67Smycroftif [ "$rarpd_flags" != NO ] && [ -r /etc/ethers ]; then
3311.67Smycroft	if [ "$rarpd_flags" = DEFAULT ]; then
3321.67Smycroft		rarpd_flags="-a"
3331.67Smycroft	fi
3341.63Smrg	echo -n ' rarpd';		rarpd $rarpd_flags
3351.60Stlsfi
3361.60Stls
3371.67Smycroftif [ "$rbootd_flags" != NO ] && [ -r /etc/rbootd.conf ]; then
3381.67Smycroft	if [ "$rbootd_flags" = DEFAULT ]; then
3391.67Smycroft		rbootd_flags=""
3401.67Smycroft	fi
3411.63Smrg	echo -n ' rbootd';		rbootd $rbootd_flags
3421.72Scjsfi
3431.72Scjs
3441.72Scjsif [ "$mopd_flags" != NO ]; then
3451.72Scjs	if [ "$mopd_flags" = DEFAULT ]; then
3461.72Scjs		mopd_flags="-a"
3471.72Scjs	fi
3481.72Scjs	echo -n ' mopd';		mopd $mopd_flags
3491.52Sthorpejfi
3501.52Sthorpej
3511.67Smycroftif [ "$inetd_flags" != NO ] && [ -r /etc/inetd.conf ]; then
3521.67Smycroft	if [ "$inetd_flags" = DEFAULT ]; then
3531.67Smycroft		inetd_flags=""
3541.67Smycroft	fi
3551.63Smrg	echo -n ' inetd';		inetd $inetd_flags
3561.30Smycroftfi
3571.30Smycroft
3581.1Scgdecho '.'
3591.1Scgd
3601.25Smycroft. /etc/rc.local
3611.1Scgd
3621.1Scgddate
3631.1Scgdexit 0
364