rc revision 1.68
11.68Smycroft#	$NetBSD: rc,v 1.68 1997/03/10 09:34:59 mycroft 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.63Smrgif [ -s /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.67Smycroft	if [ "$nfsd_flags" = DEFAULT ]; then
1531.63Smrg		nfsd_flags="-tun 4"
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.63Smrg        echo -n ' nfsd';                nfsd $nfsd_flags
1591.67Smycroft	nfs_locking=MAYBE
1601.1Scgdfi
1611.63Smrg
1621.67Smycroftif [ "$nfs_client" = YES ]; then
1631.67Smycroft	if [ "$nfsiod_flags" = DEFAULT ]; then
1641.63Smrg		nfsiod_flags="-n 4"
1651.63Smrg	fi
1661.63Smrg        echo -n ' nfsiod';              nfsiod $nfsiod_flags
1671.67Smycroft	nfs_locking=MAYBE
1681.66Sscottrfi
1691.66Sscottr
1701.67Smycroftif [ "$nfs_locking" != NO ]; then
1711.67Smycroft	if [ "$statd_flags" != NO ]; then
1721.67Smycroft		if [ "$statd_flags" = DEFAULT ]; then
1731.67Smycroft			statd_flags=""
1741.67Smycroft		fi
1751.66Sscottr		echo ' statd';		rpc.statd $statd_flags
1761.66Sscottr	fi
1771.66Sscottr
1781.67Smycroft	if [ "$lockd_flags" != NO ]; then
1791.67Smycroft		if [ "$lockd_flags" = DEFAULT ]; then
1801.67Smycroft			lockd_flags=""
1811.67Smycroft		fi
1821.66Sscottr		echo ' lockd';		rpc.lockd $lockd_flags
1831.66Sscottr	fi
1841.63Smrgfi
1851.63Smrg
1861.67Smycroftif [ "$amd_flags" != NO ] && [ -d "$amd_dir" -a -r "$amd_master" ]; then
1871.67Smycroft	if [ "$amd_flags" = DEFAULT ]; then
1881.67Smycroft		amd_flags="-l syslog -x error,noinfo,nostats"
1891.67Smycroft	fi
1901.63Smrg        echo -n ' amd'
1911.63Smrg        amd $amd_flags -p -a $amd_dir `cat $amd_master` > /var/run/amd.pid
1921.63Smrgfi
1931.63Smrg
1941.1Scgdecho '.'
1951.63Smrgmount -a -t nfs
1961.63Smrg
1971.63Smrgif [ -f /sbin/ldconfig ]; then
1981.63Smrg	echo 'creating runtime link editor directory cache.'
1991.63Smrg	if [ -s /etc/ld.so.conf ]; then
2001.63Smrg		ldconfig `cat /etc/ld.so.conf`
2011.63Smrg	else
2021.63Smrg		ldconfig
2031.63Smrg	fi
2041.63Smrgfi 
2051.1Scgd
2061.1Scgd# /var/crash should be a directory or a symbolic link
2071.1Scgd# to the crash directory if core dumps are to be saved.
2081.67Smycroftif [ "$savecore_flags" != NO ] && [ -d /var/crash ]; then
2091.67Smycroft	if [ "$savecore_flags" = DEFAULT ]; then
2101.67Smycroft		savecore_flags=""
2111.67Smycroft	fi
2121.1Scgd	echo checking for core dump...
2131.63Smrg	savecore $savecore_flags /var/crash
2141.1Scgdfi
2151.1Scgd
2161.47Sderaadt				echo -n 'checking quotas:'
2171.47Sderaadtquotacheck -a
2181.47Sderaadt				echo ' done.'
2191.47Sderaadtquotaon -a
2201.1Scgd
2211.1Scgd# build ps databases
2221.2Scgdecho 'building databases...'
2231.11Scgdkvm_mkdb /netbsd
2241.1Scgddev_mkdb
2251.1Scgd
2261.1Scgdchmod 666 /dev/tty[pqrs]*
2271.1Scgd
2281.1Scgd# check the password temp/lock file
2291.1Scgdif [ -f /etc/ptmp ]
2301.1Scgdthen
2311.1Scgd	logger -s -p auth.err \
2321.1Scgd	'password file may be incorrect -- /etc/ptmp exists'
2331.1Scgdfi
2341.1Scgd
2351.32Smycroftvirecovery=/var/tmp/vi.recover/recover.*
2361.32Smycroftif [ "$virecovery" != "/var/tmp/vi.recover/recover.*" ]; then
2371.32Smycroft	echo preserving editor files
2381.32Smycroft	for i in $virecovery; do
2391.32Smycroft		sendmail -t < $i
2401.32Smycroft	done
2411.32Smycroftfi
2421.1Scgd
2431.1Scgdecho clearing /tmp
2441.1Scgd
2451.65Smikel# Prune quickly with one rm, then use find to clean up /tmp/[lq]* (this
2461.65Smikel# is not needed with mfs /tmp, but doesn't hurt anything).
2471.1Scgd(cd /tmp && rm -rf [a-km-pr-zA-Z]* &&
2481.46Sderaadt    find . ! -name . ! -name lost+found ! -name quota.user \
2491.46Sderaadt	! -name quota.group -exec rm -rf -- {} \; -type d -prune)
2501.1Scgd
2511.34Scgdif [ -f /var/account/acct ]; then
2521.34Scgd	echo 'turning on accounting';	accton /var/account/acct
2531.34Scgdfi
2541.1Scgd
2551.1Scgdecho -n standard daemons:
2561.1Scgdecho -n ' update';		update
2571.31Sjtcecho -n ' cron';		cron
2581.1Scgdecho '.'
2591.1Scgd
2601.63Smrg# now start all the other daemons
2611.1Scgdecho -n starting network daemons:
2621.1Scgd
2631.67Smycroftif [ "$gated_flags" != NO ] && [ -r /etc/gated.conf ]; then
2641.67Smycroft	if [ "$gated_flags" = DEFAULT ]; then
2651.67Smycroft		gated_flags=""
2661.67Smycroft	fi
2671.48Smycroft	echo -n ' gated';		gated $gated_flags
2681.67Smycroftelif [ "$routed_flags" != NO ]; then
2691.67Smycroft	if [ "$routed_flags" = DEFAULT ]; then
2701.67Smycroft		routed_flags="-q"
2711.67Smycroft	fi
2721.48Smycroft	echo -n ' routed';		routed $routed_flags
2731.1Scgdfi
2741.1Scgd
2751.67Smycroftif [ "$mrouted_flags" != NO ]; then
2761.67Smycroft	if [ "$mrouted_flags" = DEFAULT ]; then
2771.67Smycroft		mrouted_flags=""
2781.67Smycroft	fi
2791.55Sthorpej	echo -n ' mrouted';		mrouted $mrouted_flags
2801.55Sthorpejfi
2811.55Sthorpej
2821.67Smycroftif [ "$timed_flags" != NO ]; then
2831.67Smycroft	if [ "$timed_flags" = DEFAULT ]; then
2841.67Smycroft		timed_flags=""
2851.67Smycroft	fi
2861.67Smycroft	echo -n ' timed'; 		timed $timed_flags
2871.63Smrgfi
2881.63Smrg
2891.67Smycroftif [ "$xntpd_flags" != NO ]; then
2901.67Smycroft	if [ "$xntpd_flags" = DEFAULT ]; then
2911.67Smycroft		xntpd_flags=""
2921.67Smycroft	fi
2931.67Smycroft	echo -n ' xntpd';		xntpd $xntpd_flags
2941.61Smrgfi
2951.61Smrg
2961.67Smycroftif [ "$dhcpd_flags" != NO ] && [ -r /etc/dhcpd.conf ]; then
2971.67Smycroft	if [ "$dhcpd_flags" = DEFAULT ]; then
2981.67Smycroft		dhcpd_flags=""
2991.67Smycroft	fi
3001.61Smrg	echo -n ' dhcpd';		dhcpd $dhcpd_flags
3011.29Smycroftfi
3021.29Smycroft
3031.67Smycroftif [ "$rwhod" = YES ]; then
3041.48Smycroft	echo -n ' rwhod';		rwhod
3051.1Scgdfi
3061.1Scgd
3071.67Smycroftif [ "$lpd_flags" != NO ]; then
3081.67Smycroft	if [ "$lpd_flags" = DEFAULT ]; then
3091.67Smycroft		lpd_flags=""
3101.67Smycroft	fi
3111.63Smrg	echo -n ' printer';		lpd $lpd_flags
3121.60Stlsfi
3131.60Stls
3141.63Smrg# We call sendmail with a full path so that SIGHUP works.
3151.67Smycroftif [ "$sendmail_flags" != NO ] && [ -r /etc/sendmail.cf ]; then
3161.67Smycroft	if [ "$sendmail_flags" = DEFAULT ]; then
3171.67Smycroft		sendmail_flags="-bd -q30m"
3181.67Smycroft	fi
3191.63Smrg	echo -n ' sendmail';		/usr/sbin/sendmail $sendmail_flags
3201.60Stlsfi
3211.60Stls
3221.67Smycroftif [ "$rarpd_flags" != NO ] && [ -r /etc/ethers ]; then
3231.67Smycroft	if [ "$rarpd_flags" = DEFAULT ]; then
3241.67Smycroft		rarpd_flags="-a"
3251.67Smycroft	fi
3261.63Smrg	echo -n ' rarpd';		rarpd $rarpd_flags
3271.60Stlsfi
3281.60Stls
3291.67Smycroftif [ "$rbootd_flags" != NO ] && [ -r /etc/rbootd.conf ]; then
3301.67Smycroft	if [ "$rbootd_flags" = DEFAULT ]; then
3311.67Smycroft		rbootd_flags=""
3321.67Smycroft	fi
3331.63Smrg	echo -n ' rbootd';		rbootd $rbootd_flags
3341.52Sthorpejfi
3351.52Sthorpej
3361.67Smycroftif [ "$inetd_flags" != NO ] && [ -r /etc/inetd.conf ]; then
3371.67Smycroft	if [ "$inetd_flags" = DEFAULT ]; then
3381.67Smycroft		inetd_flags=""
3391.67Smycroft	fi
3401.63Smrg	echo -n ' inetd';		inetd $inetd_flags
3411.30Smycroftfi
3421.30Smycroft
3431.1Scgdecho '.'
3441.1Scgd
3451.25Smycroft. /etc/rc.local
3461.1Scgd
3471.1Scgddate
3481.1Scgdexit 0
349