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