rc revision 1.98
1#	$NetBSD: rc,v 1.98 1998/01/09 21:57:17 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# Add all block-type swap devices; these might be necessary
25# during disk checks.
26swapctl -A -t blk
27
28if [ -e /fastboot ]; then
29	echo "Fast boot: skipping disk checks."
30elif [ "$1" = autoboot ]; then
31	echo "Automatic boot in progress: starting file system checks."
32	fsck -p
33	case $? in
34	0)
35		;;
36	2)
37		exit 1
38		;;
39	4)
40		echo "Rebooting..."
41		reboot
42		echo "Reboot failed; help!"
43		exit 1
44		;;
45	8)
46		echo "Automatic file system check failed; help!"
47		exit 1
48		;;
49	12)
50		echo "Boot interrupted."
51		exit 1
52		;;
53	130)
54		# interrupt before catcher installed
55		exit 1
56		;;
57	*)
58		echo "Unknown error; help!"
59		exit 1
60		;;
61	esac
62fi
63
64trap "echo 'Boot interrupted.'; exit 1" 3
65
66umount -a >/dev/null 2>&1
67mount /
68rm -f /fastboot		# XXX (root now writeable)
69
70if [ -f /etc/rc.subr ]; then
71	. /etc/rc.subr
72else
73	echo "Can't read /etc/rc.subr; aborting."
74	exit 1;
75fi
76
77if [ -f /etc/rc.conf ]; then
78	. /etc/rc.conf
79fi
80
81if [ "$rc_configured" != YES ]; then
82	echo "/etc/rc.conf is not configured. Multiuser boot aborted."
83	exit 1
84fi
85
86# set flags on ttys.  (do early, in case they use tty for SLIP in netstart)
87echo 'setting tty flags'
88ttyflags -a
89
90# load kernel modules specified in /etc/lkm.conf if the /usr filesystem
91# is already present with "/" or can be mounted now
92if checkyesno lkm && [ -f /etc/rc.lkm ]; then
93	mount /usr >/dev/null 2>&1
94	if [ -x /usr/bin/ld ]; then
95		lkmstage=BEFORENET
96		. /etc/rc.lkm
97	fi
98fi
99
100# set hostname, turn on network
101echo 'starting network'
102sh /etc/netstart
103if [ $? -ne 0 ]; then
104	exit 1
105fi
106
107for fs in /usr /var $critical_filesystems; do
108	mount | (
109        		ismounted=no
110        		while read what _on on _type type; do
111               		 if [ $on = $fs ]; then
112                        			ismounted=yes
113               		 fi
114        		done
115       		if [ $ismounted = no ]; then
116			mount $fs >/dev/null 2>&1
117		fi
118	)
119done
120
121# "Critical" file systems are now mounted.  Go ahead and swap
122# to files now, since they will be residing in the critical file
123# systems (or, at least, better).
124swapctl -A -t noblk
125
126# Check for no swap, and warn about it unless that is desired.
127if [ "$no_swap" != YES ]; then
128	swapctl -s | grep 'no swap devices configured' > /dev/null && \
129		echo "WARNING:  no swap space configured!"
130fi
131
132# clean up left-over files
133rm -f /etc/nologin
134rm -f /var/spool/lock/LCK.*
135rm -f /var/spool/uucp/STST/*
136(cd /var/run && { rm -rf -- *; install -c -m 664 -g utmp /dev/null utmp; })
137
138# start the system logger first, so that all messages from daemons
139# are logged, then start savecore to get a dump on low memory systems
140# and then start the name server.
141
142if checkyesno syslogd; then
143	echo 'starting system logger'
144	rm -f /dev/log
145	syslogd $syslogd_flags
146fi
147
148# Enable ipmon (only useful if ipfilter is running)
149# NOTE: requires the IPFILTER_LOG kernel option.
150if checkyesno ipmon; then
151	echo 'starting ipmon'
152	ipmon $ipmon_flags &
153fi
154
155# /var/crash should be a directory or a symbolic link
156# to the crash directory if core dumps are to be saved.
157if checkyesno savecore; then
158	if [ -d /var/crash ]; then
159		echo checking for core dump...
160		savecore $savecore_flags /var/crash
161	else
162		logger -s "WARNING: no /var/crash directory; savecore not run."
163	fi
164fi
165
166if checkyesno named; then
167	echo 'starting name server';	named $named_flags
168fi
169
170# set time, if requested
171if checkyesno ntpdate; then
172	if [ -z "$ntpdate_hosts" ]; then
173		ntpdate_hosts=`awk '/^server/ {print $2}' </etc/ntp.conf`
174	fi
175	if [ -n "$ntpdate_hosts"  ]; then
176		echo 'Setting date via ntp.'
177		ntpdate -b $ntpdate_hosts
178	fi
179fi
180
181# now start the rpc servers, for YP server/client.
182echo -n 'starting rpc daemons:'
183
184# note that portmap is generally required for all other rpc services.
185if checkyesno portmap; then
186	echo -n ' portmap';             portmap
187fi
188
189if checkyesno ypserv; then
190        echo -n ' ypserv';              ypserv $ypserv_flags
191fi
192
193if checkyesno ypbind; then
194        echo -n ' ypbind';              ypbind $ypbind_flags
195fi
196
197if checkyesno yppasswdd; then
198        echo -n ' rpc.yppasswdd';       rpc.yppasswdd $yppasswdd_flags
199fi
200
201if checkyesno bootparamd; then
202	if [ -r /etc/bootparams ]; then
203		echo -n ' rpc.bootparamd'; rpc.bootparamd $bootparamd_flags
204	else
205		echo
206		logger -s "WARNING: /etc/bootparams not found. " \
207		    "bootparamd not started."
208	fi
209fi
210
211echo '.'
212
213# load kernel modules specified in /etc/lkm.conf
214if checkyesno lkm; then
215	if [ -r /etc/rc.lkm ]; then
216		lkmstage=BEFOREMOUNT
217		. /etc/rc.lkm
218	else
219		logger -s "WARNING: /etc/rc.lkm not found; LKMs not loaded."
220	fi
221fi
222
223mount -a
224
225# now start the rpc servers, for NFS server/client.
226echo -n 'starting nfs daemons:'
227
228nfs_locking=NO
229
230if checkyesno nfs_server; then
231	if [ -r /etc/exports ]; then
232		rm -f /var/db/mountdtab
233		echo -n > /var/db/mountdtab
234		echo -n ' mountd';              mountd $mountd_flags
235		echo -n ' nfsd';                nfsd $nfsd_flags
236		nfs_locking=MAYBE
237	else
238		echo
239		logger -s "WARNING: /etc/exports not readable; " \
240		    "NFS server not started."
241	fi
242fi
243
244if checkyesno nfs_client; then
245        echo -n ' nfsiod';              nfsiod $nfsiod_flags
246	nfs_locking=MAYBE
247fi
248
249if [ "$nfs_locking" != NO ]; then
250	if checkyesno statd; then
251		echo -n ' rpc.statd';		rpc.statd $statd_flags
252	fi
253	if checkyesno lockd; then
254		echo -n ' rpc.lockd';		rpc.lockd $lockd_flags
255	fi
256fi
257
258if checkyesno amd; then
259	if [ -d "$amd_dir" ]; then
260		if [ -r "$amd_master" ]; then
261			echo -n ' amd'
262			amd $amd_flags -p -a $amd_dir `cat $amd_master` \
263			    > /var/run/amd.pid
264		else
265			echo
266			logger -s "WARNING: \$amd_master ($amd_master)not " \
267			    "readable; amd not started."
268		fi
269	else
270		echo
271		logger -s "WARNING: \$amd_dir ($amd_dir) not a directory; " \
272		    "amd not started."
273	fi
274fi
275
276echo '.'
277
278if [ -f /sbin/ldconfig ]; then
279	echo 'creating runtime link editor directory cache.'
280	ldconfig
281fi 
282
283# load kernel modules specified in /etc/lkm.conf
284if checkyesno lkm && [ -f /etc/rc.lkm ]; then
285	lkmstage=AFTERMOUNT
286	. /etc/rc.lkm
287fi
288
289echo -n 'checking quotas:'; quotacheck -a; echo ' done.'
290quotaon -a
291
292# build ps databases
293echo 'building databases...'
294kvm_mkdb /netbsd
295dev_mkdb
296
297chmod 666 /dev/tty[pqrs]*
298
299# check the password temp/lock file
300if [ -f /etc/ptmp ]
301then
302	logger -s -p auth.err \
303	'password file may be incorrect -- /etc/ptmp exists'
304fi
305
306virecovery=`echo /var/tmp/vi.recover/recover.*`
307if [ "$virecovery" != "/var/tmp/vi.recover/recover.*" ]; then
308	echo preserving editor files
309	for i in $virecovery; do
310		sendmail -t < $i
311	done
312fi
313
314echo clearing /tmp
315
316# Prune quickly with one rm, then use find to clean up /tmp/[lq]* (this
317# is not needed with mfs /tmp, but doesn't hurt anything).
318(cd /tmp && rm -rf [a-km-pr-zA-Z]* &&
319    find . ! -name . ! -name lost+found ! -name quota.user \
320	! -name quota.group -exec rm -rf -- {} \; -type d -prune)
321
322# Update kernel info in /etc/motd
323# Must be done *before* interactive logins are possible to prevent
324# possible race conditions.
325if checkyesno update_motd; then
326	echo 'updating motd.'
327	if [ ! -f /etc/motd ]; then
328		install -c -o root -g wheel -m 664 /dev/null /etc/motd
329	fi
330	T=/tmp/_motd
331	rm -f $T
332	sysctl -n kern.version | sed 1q > $T
333	echo "" >> $T
334	sed '1,/^$/d' < /etc/motd >> $T
335	cmp -s $T /etc/motd || cp $T /etc/motd
336	rm -f $T
337fi
338
339if [ -f /var/account/acct ]; then
340	echo 'turning on accounting';	accton /var/account/acct
341fi
342
343echo -n standard daemons:
344if checkyesno update; then
345	echo -n ' update';		update $update_flags
346fi
347echo -n ' cron';		cron
348echo '.'
349
350# now start all the other daemons
351echo -n starting network daemons:
352
353if checkyesno gated && checkyesno routed; then
354	echo
355	logger -s "WARNING: gated and routed both requested to be run: " \
356	    "running only gated."
357	routed=NO
358fi
359
360if checkyesno gated; then
361	if [ -r /etc/gated.conf ]; then
362		echo -n ' gated';		gated $gated_flags
363	else
364		logger -s "WARNING: no /etc/gated.conf; gated not started."
365	fi
366fi
367
368if checkyesno routed; then
369	echo -n ' routed';		routed $routed_flags
370fi
371
372if checkyesno mrouted; then
373	echo -n ' mrouted';		mrouted $mrouted_flags
374fi
375
376if checkyesno timed; then
377	echo -n ' timed'; 		timed $timed_flags
378fi
379
380if checkyesno xntpd; then
381	echo -n ' xntpd';		xntpd $xntpd_flags
382fi
383
384if checkyesno dhcpd; then
385	if [ -r /etc/dhcpd.conf ]; then
386		echo -n ' dhcpd';		dhcpd $dhcpd_flags
387	else
388		echo
389		logger -s "WARNING: /etc/dhcpd.conf not readable; " \
390		    "dhcpd not started."
391	fi
392fi
393
394if checkyesno rwhod; then
395	echo -n ' rwhod';		rwhod
396fi
397
398if checkyesno lpd; then
399	echo -n ' lpd';			lpd $lpd_flags
400fi
401
402# We call sendmail with a full path so that SIGHUP works.
403if checkyesno sendmail; then
404	if [ -r /etc/sendmail.cf ]; then
405		echo -n ' sendmail';	/usr/sbin/sendmail $sendmail_flags
406	else
407		echo
408		logger -s "WARNING: /etc/sendmail.cf not readable; " \
409		    "sendmail not started."
410	fi
411fi
412
413# Start xfs before boot daemons, so its ready before client xterminals.
414if checkyesno xfs; then
415	echo -n ' xfs';			xfs $xfs_flags &
416	sleep 2
417fi
418
419if checkyesno rarpd; then
420	if [ -r /etc/ethers ]; then
421		echo -n ' rarpd';	rarpd $rarpd_flags
422	else
423		echo
424		logger -s "WARNING: /etc/ethers not readable; " \
425		    "rarpd not started."
426	fi
427fi
428
429if checkyesno rbootd; then
430	if [ -r /etc/rbootd.conf ]; then
431		echo -n ' rbootd';	rbootd $rbootd_flags
432	else
433		echo
434		logger -s "WARNING: /etc/rbootd.conf not readable; " \
435		    "rarpd not started."
436	fi
437fi
438
439if checkyesno mopd; then
440	echo -n ' mopd';		mopd $mopd_flags
441fi
442
443if checkyesno apmd; then
444	echo -n ' apmd';		apmd $apmd_flags
445fi
446
447if checkyesno inetd; then
448	if [ -r /etc/inetd.conf ]; then
449		echo -n ' inetd';	inetd $inetd_flags
450	else
451		echo
452		logger -s "WARNING: /etc/inetd.conf not readable; " \
453		    "inetd not started."
454	fi
455fi
456
457if checkyesno xdm; then
458	echo -n ' xdm';			xdm $xdm_flags
459fi
460
461echo '.'
462
463# Kerberos runs ONLY on the Kerberos server machine
464if checkyesno kerberos; then
465	echo -n 'starting kerberos daemons:'
466	echo -n ' kerberos';	kerberos >> /var/log/kerberos.log &
467	echo -n ' kadmind';	kadmind -n >> /var/log/kadmind.log &
468	echo '.'
469fi
470
471. /etc/rc.local
472
473date
474exit 0
475