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