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