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