rc revision 1.119
1#	$NetBSD: rc,v 1.119 1999/03/19 00:35:44 perry 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# get the system dmesg output, hopefully containing the boot messages
156# $dmesg_flags is imported from /etc/rc.conf
157if checkyesno dmesg; then
158	dmesg $dmesg_flags > /var/run/dmesg.boot
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 $securelevel is set, change it here, else if it is 0, change
320# it to 1 here, before we start login services.
321if [ -n "$securelevel" ]; then
322	echo -n 'setting securelevel: '
323	sysctl -w kern.securelevel=$securelevel
324else
325	securelevel=`sysctl -n kern.securelevel`
326	if [ x"$securelevel" = x0 ]; then
327		echo -n 'setting securelevel: '
328		sysctl -w kern.securelevel=1
329	fi
330fi
331
332echo -n 'checking quotas:'; quotacheck -a; echo ' done.'
333quotaon -a
334
335# build ps databases
336echo 'building databases...'
337kvm_mkdb /netbsd
338dev_mkdb
339
340chmod 666 /dev/tty[pqrs]*
341
342# check the password temp/lock file
343if [ -f /etc/ptmp ]
344then
345	logger -s -p auth.err \
346	'password file may be incorrect -- /etc/ptmp exists'
347fi
348
349# XXX replace me with a script that works!
350virecovery=`echo /var/tmp/vi.recover/recover.*`
351if [ "$virecovery" != "/var/tmp/vi.recover/recover.*" ]; then
352	echo preserving editor files
353	for i in $virecovery; do
354		sendmail -t < $i
355	done
356fi
357
358echo clearing /tmp
359
360# Prune quickly with one rm, then use find to clean up /tmp/[lq]* (this
361# is not needed with mfs /tmp, but doesn't hurt anything).
362(cd /tmp && rm -rf [a-km-pr-zA-Z]* &&
363    find . ! -name . ! -name lost+found ! -name quota.user \
364	! -name quota.group -exec rm -rf -- {} \; -type d -prune)
365
366# Update kernel info in /etc/motd
367# Must be done *before* interactive logins are possible to prevent
368# possible race conditions.
369if checkyesno update_motd; then
370	echo 'updating motd.'
371	if [ ! -f /etc/motd ]; then
372		install -c -o root -g wheel -m 664 /dev/null /etc/motd
373	fi
374	T=/tmp/_motd
375	rm -f $T
376	sysctl -n kern.version | sed 1q > $T
377	echo "" >> $T
378	sed '1,/^$/d' < /etc/motd >> $T
379	cmp -s $T /etc/motd || cp $T /etc/motd
380	rm -f $T
381fi
382
383if [ -f /var/account/acct ]; then
384	echo 'turning on accounting';	accton /var/account/acct
385fi
386
387echo -n standard daemons:
388if checkyesno update; then
389	echo -n ' update';		update $update_flags
390fi
391if checkyesno cron; then
392	echo -n ' cron';		cron
393fi
394echo '.'
395
396# now start all the other daemons
397echo -n starting network daemons:
398
399if checkyesno gated && checkyesno routed; then
400	echo
401	logger -s "WARNING: gated and routed both requested to be run: " \
402	    "running only gated."
403	routed=NO
404fi
405
406if checkyesno gated; then
407	if [ -r /etc/gated.conf ]; then
408		echo -n ' gated';		gated $gated_flags
409	else
410		logger -s "WARNING: no /etc/gated.conf; gated not started."
411	fi
412fi
413
414if checkyesno routed; then
415	echo -n ' routed';		routed $routed_flags
416fi
417
418if checkyesno mrouted; then
419	echo -n ' mrouted';		mrouted $mrouted_flags
420fi
421
422if checkyesno timed; then
423	echo -n ' timed'; 		timed $timed_flags
424fi
425
426if checkyesno xntpd; then
427	echo -n ' xntpd';		xntpd $xntpd_flags
428fi
429
430if checkyesno dhcpd; then
431	if [ -r /etc/dhcpd.conf ]; then
432		echo -n ' dhcpd';		dhcpd $dhcpd_flags
433	else
434		echo
435		logger -s "WARNING: /etc/dhcpd.conf not readable; " \
436		    "dhcpd not started."
437	fi
438fi
439
440if checkyesno rwhod; then
441	echo -n ' rwhod';		rwhod
442fi
443
444if checkyesno lpd; then
445	echo -n ' lpd';			lpd $lpd_flags
446fi
447
448# We call sendmail with a full path so that SIGHUP works.
449if checkyesno sendmail; then
450	if [ -r /etc/sendmail.cf ]; then
451		echo -n ' sendmail';	/usr/sbin/sendmail $sendmail_flags
452	else
453		echo
454		logger -s "WARNING: /etc/sendmail.cf not readable; " \
455		    "sendmail not started."
456	fi
457fi
458
459# Start xfs before boot daemons, so its ready before client xterminals.
460if checkyesno xfs; then
461	echo -n ' xfs';			xfs $xfs_flags &
462	sleep 2
463fi
464
465if checkyesno rarpd; then
466	if [ -r /etc/ethers ]; then
467		echo -n ' rarpd';	rarpd $rarpd_flags
468	else
469		echo
470		logger -s "WARNING: /etc/ethers not readable; " \
471		    "rarpd not started."
472	fi
473fi
474
475if checkyesno rbootd; then
476	if [ -r /etc/rbootd.conf ]; then
477		echo -n ' rbootd';	rbootd $rbootd_flags
478	else
479		echo
480		logger -s "WARNING: /etc/rbootd.conf not readable; " \
481		    "rbootd not started."
482	fi
483fi
484
485if checkyesno mopd; then
486	echo -n ' mopd';		mopd $mopd_flags
487fi
488
489if checkyesno apmd; then
490	echo -n ' apmd';		apmd $apmd_flags
491fi
492
493if checkyesno screenblank; then
494	echo -n ' screenblank';		screenblank $screenblank_flags
495fi
496
497if checkyesno inetd; then
498	if [ -r /etc/inetd.conf ]; then
499		echo -n ' inetd';	inetd $inetd_flags
500	else
501		echo
502		logger -s "WARNING: /etc/inetd.conf not readable; " \
503		    "inetd not started."
504	fi
505fi
506
507if checkyesno usbd; then
508	echo -n ' usbd';		usbd $usbd_flags
509fi
510
511if checkyesno xdm; then
512	echo -n ' xdm';			xdm $xdm_flags
513fi
514
515echo '.'
516
517# Kerberos runs ONLY on the Kerberos server machine
518if checkyesno kerberos; then
519	echo -n 'starting kerberos daemons:'
520	echo -n ' kerberos';	kerberos >> /var/log/kerberos.log &
521	echo -n ' kadmind';	kadmind -n >> /var/log/kadmind.log &
522	echo '.'
523fi
524
525if checkyesno wscons && [ -f /etc/rc.wscons ]; then
526	echo 'configuring wscons'
527	/bin/sh /etc/rc.wscons $wscons_flags
528fi
529
530. /etc/rc.local
531
532date
533exit 0
534