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