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