rc revision 1.110
1#	$NetBSD: rc,v 1.110 1999/01/12 04:58:37 jwise Exp $
2#	originally from: @(#)rc	8.2 (Berkeley) 3/17/94
3
4# System startup script run by init on autoboot
5# or after single-user.
6# Output and error are redirected to console by init,
7# and the console is the controlling terminal.
8
9stty status '^T'
10
11# Set shell to ignore SIGINT (2), but not children;
12# shell catches SIGQUIT (3) and returns to single user after fsck.
13trap : 2
14trap : 3	# shouldn't be needed
15
16export HOME=/
17export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin
18
19# Configure ccd devices.
20if [ -f /etc/ccd.conf ]; then
21	ccdconfig -C
22fi
23
24# Configure raid devices.
25for dev in 0 1 2 3; do
26	if [ -f /etc/raid$dev.conf ]; then
27		raidctl -c /etc/raid$dev.conf raid$dev
28		raidctl -r raid$dev
29	fi
30done
31
32# Add all block-type swap devices; these might be necessary
33# during disk checks.
34swapctl -A -t blk
35
36if [ -e /fastboot ]; then
37	echo "Fast boot: skipping disk checks."
38elif [ "$1" = autoboot ]; then
39	echo "Automatic boot in progress: starting file system checks."
40	fsck -p
41	case $? in
42	0)
43		;;
44	2)
45		exit 1
46		;;
47	4)
48		echo "Rebooting..."
49		reboot
50		echo "Reboot failed; help!"
51		exit 1
52		;;
53	8)
54		echo "Automatic file system check failed; help!"
55		exit 1
56		;;
57	12)
58		echo "Boot interrupted."
59		exit 1
60		;;
61	130)
62		# interrupt before catcher installed
63		exit 1
64		;;
65	*)
66		echo "Unknown error; help!"
67		exit 1
68		;;
69	esac
70fi
71
72trap "echo 'Boot interrupted.'; exit 1" 3
73
74umount -a >/dev/null 2>&1
75mount /
76rm -f /fastboot		# XXX (root now writeable)
77
78if [ -f /etc/rc.subr ]; then
79	. /etc/rc.subr
80else
81	echo "Can't read /etc/rc.subr; aborting."
82	exit 1;
83fi
84
85if [ -f /etc/rc.conf ]; then
86	. /etc/rc.conf
87fi
88
89if [ "$rc_configured" != YES ]; then
90	echo "/etc/rc.conf is not configured. Multiuser boot aborted."
91	exit 1
92fi
93
94# set flags on ttys.  (do early, in case they use tty for SLIP in netstart)
95echo 'setting tty flags'
96ttyflags -a
97
98# load kernel modules specified in /etc/lkm.conf if the /usr filesystem
99# is already present with "/" or can be mounted now
100if checkyesno lkm && [ -f /etc/rc.lkm ]; then
101	mount /usr >/dev/null 2>&1
102	if [ -x /usr/bin/ld ]; then
103		lkmstage=BEFORENET
104		. /etc/rc.lkm
105	fi
106fi
107
108# set hostname, turn on network
109echo 'starting network'
110sh /etc/netstart
111if [ $? -ne 0 ]; then
112	exit 1
113fi
114
115for fs in /usr /var $critical_filesystems; do
116	mount | (
117        		ismounted=no
118        		while read what _on on _type type; do
119               		 if [ $on = $fs ]; then
120                        			ismounted=yes
121               		 fi
122        		done
123       		if [ $ismounted = no ]; then
124			mount $fs >/dev/null 2>&1
125		fi
126	)
127done
128
129# Network Address Translation...
130if checkyesno ipnat && [ -f /etc/ipnat.conf ]; then
131	echo 'installing NAT rules ... '
132	if ! checkyesno ipfilter || [ ! -f /etc/ipf.conf ]; then
133		ipf -E -Fa
134	fi
135	ipnat -F -f /etc/ipnat.conf
136fi
137
138# "Critical" file systems are now mounted.  Go ahead and swap
139# to files now, since they will be residing in the critical file
140# systems (or, at least, better).
141swapctl -A -t noblk
142
143# Check for no swap, and warn about it unless that is desired.
144if ! checkyesno no_swap; then
145	swapctl -s | grep 'no swap devices configured' > /dev/null && \
146		echo "WARNING:  no swap space configured!"
147fi
148
149# clean up left-over files
150rm -f /etc/nologin
151rm -f /var/spool/lock/LCK.*
152rm -f /var/spool/uucp/STST/*
153(cd /var/run && { rm -rf -- *; install -c -m 664 -g utmp /dev/null utmp; })
154
155# save a copy of the boot messages
156dmesg | sed -n -e '1,$H' -e '/^NetBSD/h' -e '$g' -e '$p' > /var/run/dmesg.boot
157
158# start the system logger first, so that all messages from daemons
159# are logged, then start savecore to get a dump on low memory systems
160# and then start the name server.
161
162if checkyesno syslogd; then
163	echo 'starting system logger'
164	rm -f /dev/log
165	syslogd $syslogd_flags
166fi
167
168# Enable ipmon (only useful if ipfilter is running)
169# NOTE: requires the IPFILTER_LOG kernel option.
170if checkyesno ipmon; then
171	echo 'starting ipmon'
172	ipmon $ipmon_flags &
173fi
174
175# /var/crash should be a directory or a symbolic link
176# to the crash directory if core dumps are to be saved.
177if checkyesno savecore; then
178	if [ -d /var/crash/. ]; then
179		echo checking for core dump...
180		savecore $savecore_flags /var/crash
181	else
182		logger -s "WARNING: no /var/crash directory; savecore not run."
183	fi
184fi
185
186if checkyesno named; then
187	echo 'starting name server';	named $named_flags
188fi
189
190# set time, if requested
191if checkyesno ntpdate; then
192	if [ -z "$ntpdate_hosts" ]; then
193		ntpdate_hosts=`awk '
194		    /^server[ \t]*127.127/	{next}
195		    /^server/			{print $2}
196		' </etc/ntp.conf`
197	fi
198	if [ -n "$ntpdate_hosts"  ]; then
199		echo 'Setting date via ntp.'
200		ntpdate -b -s $ntpdate_hosts
201	fi
202fi
203
204# now start the rpc servers, for YP server/client.
205echo -n 'starting rpc daemons:'
206
207# note that portmap is generally required for all other rpc services.
208if checkyesno portmap; then
209	echo -n ' portmap';             portmap $portmap_flags
210fi
211
212if checkyesno ypserv; then
213        echo -n ' ypserv';              ypserv $ypserv_flags
214fi
215
216if checkyesno ypbind; then
217        echo -n ' ypbind';              ypbind $ypbind_flags
218fi
219
220if checkyesno yppasswdd; then
221        echo -n ' rpc.yppasswdd';       rpc.yppasswdd $yppasswdd_flags
222fi
223
224if checkyesno bootparamd; then
225	if [ -r /etc/bootparams ]; then
226		echo -n ' rpc.bootparamd'; rpc.bootparamd $bootparamd_flags
227	else
228		echo
229		logger -s "WARNING: /etc/bootparams not found. " \
230		    "bootparamd not started."
231	fi
232fi
233
234echo '.'
235
236# load kernel modules specified in /etc/lkm.conf
237if checkyesno lkm; then
238	if [ -r /etc/rc.lkm ]; then
239		lkmstage=BEFOREMOUNT
240		. /etc/rc.lkm
241	else
242		logger -s "WARNING: /etc/rc.lkm not found; LKMs not loaded."
243	fi
244fi
245
246mount -a
247
248# now start the rpc servers, for NFS server/client.
249echo -n 'starting nfs daemons:'
250
251nfs_locking=NO
252
253if checkyesno nfs_server; then
254	if [ -r /etc/exports ]; then
255		rm -f /var/db/mountdtab
256		echo -n > /var/db/mountdtab
257		echo -n ' mountd';              mountd $mountd_flags
258		echo -n ' nfsd';                nfsd $nfsd_flags
259		nfs_locking=YES
260	else
261		echo
262		logger -s "WARNING: /etc/exports not readable; " \
263		    "NFS server not started."
264	fi
265fi
266
267if checkyesno nfs_client; then
268        echo -n ' nfsiod';              nfsiod $nfsiod_flags
269	nfs_locking=YES
270fi
271
272if checkyesno nfs_locking; then
273	if checkyesno statd; then
274		echo -n ' rpc.statd';		rpc.statd $statd_flags
275	fi
276	if checkyesno lockd; then
277		echo -n ' rpc.lockd';		rpc.lockd $lockd_flags
278	fi
279fi
280
281if checkyesno amd; then
282	if [ -d "$amd_dir" ]; then
283		if [ -r "$amd_master" ]; then
284			echo -n ' amd'
285			amd $amd_flags -p -a $amd_dir \
286			`sed s/#.*$// <$amd_master`  >/var/run/amd.pid
287		else
288			echo
289			logger -s "WARNING: \$amd_master ($amd_master)not " \
290			    "readable; amd not started."
291		fi
292	else
293		echo
294		logger -s "WARNING: \$amd_dir ($amd_dir) not a directory; " \
295		    "amd not started."
296	fi
297fi
298
299echo '.'
300
301if [ -f /sbin/ldconfig ]; then
302	echo 'creating runtime link editor directory cache.'
303	ldconfig
304fi 
305
306# load kernel modules specified in /etc/lkm.conf
307if checkyesno lkm && [ -f /etc/rc.lkm ]; then
308	lkmstage=AFTERMOUNT
309	. /etc/rc.lkm
310fi
311
312echo -n 'checking quotas:'; quotacheck -a; echo ' done.'
313quotaon -a
314
315# build ps databases
316echo 'building databases...'
317kvm_mkdb /netbsd
318dev_mkdb
319
320chmod 666 /dev/tty[pqrs]*
321
322# check the password temp/lock file
323if [ -f /etc/ptmp ]
324then
325	logger -s -p auth.err \
326	'password file may be incorrect -- /etc/ptmp exists'
327fi
328
329virecovery=`echo /var/tmp/vi.recover/recover.*`
330if [ "$virecovery" != "/var/tmp/vi.recover/recover.*" ]; then
331	echo preserving editor files
332	for i in $virecovery; do
333		sendmail -t < $i
334	done
335fi
336
337echo clearing /tmp
338
339# Prune quickly with one rm, then use find to clean up /tmp/[lq]* (this
340# is not needed with mfs /tmp, but doesn't hurt anything).
341(cd /tmp && rm -rf [a-km-pr-zA-Z]* &&
342    find . ! -name . ! -name lost+found ! -name quota.user \
343	! -name quota.group -exec rm -rf -- {} \; -type d -prune)
344
345# Update kernel info in /etc/motd
346# Must be done *before* interactive logins are possible to prevent
347# possible race conditions.
348if checkyesno update_motd; then
349	echo 'updating motd.'
350	if [ ! -f /etc/motd ]; then
351		install -c -o root -g wheel -m 664 /dev/null /etc/motd
352	fi
353	T=/tmp/_motd
354	rm -f $T
355	sysctl -n kern.version | sed 1q > $T
356	echo "" >> $T
357	sed '1,/^$/d' < /etc/motd >> $T
358	cmp -s $T /etc/motd || cp $T /etc/motd
359	rm -f $T
360fi
361
362if [ -f /var/account/acct ]; then
363	echo 'turning on accounting';	accton /var/account/acct
364fi
365
366echo -n standard daemons:
367if checkyesno update; then
368	echo -n ' update';		update $update_flags
369fi
370if checkyesno cron; then
371	echo -n ' cron';		cron
372fi
373echo '.'
374
375# now start all the other daemons
376echo -n starting network daemons:
377
378if checkyesno gated && checkyesno routed; then
379	echo
380	logger -s "WARNING: gated and routed both requested to be run: " \
381	    "running only gated."
382	routed=NO
383fi
384
385if checkyesno gated; then
386	if [ -r /etc/gated.conf ]; then
387		echo -n ' gated';		gated $gated_flags
388	else
389		logger -s "WARNING: no /etc/gated.conf; gated not started."
390	fi
391fi
392
393if checkyesno routed; then
394	echo -n ' routed';		routed $routed_flags
395fi
396
397if checkyesno mrouted; then
398	echo -n ' mrouted';		mrouted $mrouted_flags
399fi
400
401if checkyesno timed; then
402	echo -n ' timed'; 		timed $timed_flags
403fi
404
405if checkyesno xntpd; then
406	echo -n ' xntpd';		xntpd $xntpd_flags
407fi
408
409if checkyesno dhcpd; then
410	if [ -r /etc/dhcpd.conf ]; then
411		echo -n ' dhcpd';		dhcpd $dhcpd_flags
412	else
413		echo
414		logger -s "WARNING: /etc/dhcpd.conf not readable; " \
415		    "dhcpd not started."
416	fi
417fi
418
419if checkyesno rwhod; then
420	echo -n ' rwhod';		rwhod
421fi
422
423if checkyesno lpd; then
424	echo -n ' lpd';			lpd $lpd_flags
425fi
426
427# We call sendmail with a full path so that SIGHUP works.
428if checkyesno sendmail; then
429	if [ -r /etc/sendmail.cf ]; then
430		echo -n ' sendmail';	/usr/sbin/sendmail $sendmail_flags
431	else
432		echo
433		logger -s "WARNING: /etc/sendmail.cf not readable; " \
434		    "sendmail not started."
435	fi
436fi
437
438# Start xfs before boot daemons, so its ready before client xterminals.
439if checkyesno xfs; then
440	echo -n ' xfs';			xfs $xfs_flags &
441	sleep 2
442fi
443
444if checkyesno rarpd; then
445	if [ -r /etc/ethers ]; then
446		echo -n ' rarpd';	rarpd $rarpd_flags
447	else
448		echo
449		logger -s "WARNING: /etc/ethers not readable; " \
450		    "rarpd not started."
451	fi
452fi
453
454if checkyesno rbootd; then
455	if [ -r /etc/rbootd.conf ]; then
456		echo -n ' rbootd';	rbootd $rbootd_flags
457	else
458		echo
459		logger -s "WARNING: /etc/rbootd.conf not readable; " \
460		    "rarpd not started."
461	fi
462fi
463
464if checkyesno mopd; then
465	echo -n ' mopd';		mopd $mopd_flags
466fi
467
468if checkyesno apmd; then
469	echo -n ' apmd';		apmd $apmd_flags
470fi
471
472if checkyesno screenblank; then
473	echo -n ' screenblank';		screenblank $screenblank_flags
474fi
475
476if checkyesno inetd; then
477	if [ -r /etc/inetd.conf ]; then
478		echo -n ' inetd';	inetd $inetd_flags
479	else
480		echo
481		logger -s "WARNING: /etc/inetd.conf not readable; " \
482		    "inetd not started."
483	fi
484fi
485
486if checkyesno usbd; then
487	echo -n ' usbd';		usbd $usbd_flags
488fi
489
490if checkyesno xdm; then
491	echo -n ' xdm';			xdm $xdm_flags
492fi
493
494echo '.'
495
496# Kerberos runs ONLY on the Kerberos server machine
497if checkyesno kerberos; then
498	echo -n 'starting kerberos daemons:'
499	echo -n ' kerberos';	kerberos >> /var/log/kerberos.log &
500	echo -n ' kadmind';	kadmind -n >> /var/log/kadmind.log &
501	echo '.'
502fi
503
504. /etc/rc.local
505
506date
507exit 0
508