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