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