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