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