rc revision 1.143 1 # $NetBSD: rc,v 1.143 2000/01/19 03:52:12 enami 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
9 stty 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.
13 trap : 2
14 trap : 3 # shouldn't be needed
15
16 export HOME=/
17 export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin
18
19 # Configure ccd devices.
20 if [ -f /etc/ccd.conf ]; then
21 ccdconfig -C
22 fi
23
24 # Configure raid devices.
25 for dev in 0 1 2 3; do
26 if [ -f /etc/raid$dev.conf ]; then
27 raidctl -c /etc/raid$dev.conf raid$dev
28 fi
29 done
30
31 # Add all block-type swap devices; these might be necessary
32 # during disk checks.
33 swapctl -A -t blk
34
35 if [ -e /fastboot ]; then
36 echo "Fast boot: skipping disk checks."
37 elif [ "$1" = autoboot ]; then
38 echo "Automatic boot in progress: starting file system checks."
39 fsck -p
40 case $? in
41 0)
42 ;;
43 2)
44 exit 1
45 ;;
46 4)
47 echo "Rebooting..."
48 reboot
49 echo "Reboot failed; help!"
50 exit 1
51 ;;
52 8)
53 echo "Automatic file system check failed; help!"
54 exit 1
55 ;;
56 12)
57 echo "Boot interrupted."
58 exit 1
59 ;;
60 130)
61 # interrupt before catcher installed
62 exit 1
63 ;;
64 *)
65 echo "Unknown error; help!"
66 exit 1
67 ;;
68 esac
69 fi
70
71 trap "echo 'Boot interrupted.'; exit 1" 3
72
73 umount -a >/dev/null 2>&1
74 mount /
75 rm -f /fastboot # XXX (root now writeable)
76
77 if [ -f /etc/rc.subr ]; then
78 . /etc/rc.subr
79 else
80 echo "Can't read /etc/rc.subr; aborting."
81 exit 1;
82 fi
83
84 if [ -f /etc/rc.conf ]; then
85 . /etc/rc.conf
86 fi
87
88 if ! checkyesno rc_configured; then
89 echo "/etc/rc.conf is not configured. Multiuser boot aborted."
90 exit 1
91 fi
92
93 # set flags on ttys. (do early, in case they use tty for SLIP in netstart)
94 echo 'setting tty flags'
95 ttyflags -a
96
97 # load kernel modules specified in /etc/lkm.conf if the /usr filesystem
98 # is already present with "/" or can be mounted now
99 if checkyesno lkm && [ -f /etc/rc.lkm ]; then
100 mount /usr >/dev/null 2>&1
101 if [ -x /usr/bin/ld ]; then
102 lkmstage=BEFORENET
103 . /etc/rc.lkm
104 fi
105 fi
106
107 mount_critical_filesystems local
108
109 if [ -e /etc/etc.current ] ; then
110 if [ -h /etc/etc.default ] ; then
111 def=`ls -ld /etc/etc.default 2>&1`
112 default=`expr "$def" : '.*-> etc\.\(.*\)' 2>&1`
113 else
114 default=current
115 fi
116 spc=""
117 conflist=`cd /etc; ls -1d etc.* 2>&1 | egrep -v 'current|default'`
118 for i in $conflist; do
119 name=`expr $i : 'etc\.\(.*\)' 2>&1`
120 if [ $name = $default ] ; then
121 echo -n "${spc}[${name}]"
122 else
123 echo -n "${spc}${name}"
124 fi
125 spc=" "
126 done
127 echo
128 master=$$
129 conf=/etc/passwd
130 while [ ! -d /etc/etc.$conf ] ; do
131 trap 'conf=$default; echo; echo Using default of $conf' 14
132 echo -n "Which configuration [$default] ? "
133 (sleep 30 && kill -ALRM $master) >/dev/null 2>&1 &
134 read conf
135 trap "" 14
136 if [ -z $conf ] ; then
137 conf=$default
138 fi
139 if [ ! -d /etc/etc.$conf -a ! -h /etc/etc.$conf ] ; then
140 conf=/etc/passwd
141 fi
142 done
143 rm -f /etc/etc.current
144 ln -s /etc/etc.$conf /etc/etc.current
145 if [ -f /etc/rc.conf ] ; then
146 . /etc/rc.conf
147 fi
148 fi
149
150 # set hostname, turn on network
151 echo 'starting network'
152 sh /etc/netstart
153 if [ $? -ne 0 ]; then
154 exit 1
155 fi
156
157 mount_critical_filesystems network
158
159 # Network Address Translation...
160 if checkyesno ipnat && [ -f /etc/ipnat.conf ]; then
161 echo 'installing NAT rules ... '
162 if ! checkyesno ipfilter || [ ! -f /etc/ipf.conf ]; then
163 ipf -E -Fa
164 fi
165 ipnat -F -f /etc/ipnat.conf
166 fi
167
168 # "Critical" file systems are now mounted. Go ahead and swap
169 # to files now, since they will be residing in the critical file
170 # systems (or, at least, better).
171 swapctl -A -t noblk
172
173 # Check for no swap, and warn about it unless that is desired.
174 if ! checkyesno no_swap; then
175 swapctl -s | grep 'no swap devices configured' > /dev/null && \
176 echo "WARNING: no swap space configured!"
177 fi
178
179 # clean up left-over files
180 rm -f /etc/nologin
181 rm -f /var/spool/lock/LCK.*
182 rm -f /var/spool/uucp/STST/*
183 (cd /var/run && { rm -rf -- *; install -c -m 664 -g utmp /dev/null utmp; })
184
185 # build ps databases
186 echo 'building databases...'
187 # if this kernel supports machdep.booted_kernel, use that to build the KVM
188 # db so dmesg will run work when we boot /netbsd.new, etc.
189 sysctl machdep 2>/dev/null | grep -q booted_kernel
190 if [ $? -eq 0 ] ; then
191 kvm_mkdb `sysctl -n machdep.booted_kernel`
192 if [ $? -ne 0 ] ; then
193 kvm_mkdb /netbsd
194 fi
195 else
196 kvm_mkdb /netbsd
197 fi
198 dev_mkdb
199
200 # get the system dmesg output, hopefully containing the boot messages
201 # $dmesg_flags is imported from /etc/rc.conf
202 if checkyesno dmesg; then
203 dmesg $dmesg_flags > /var/run/dmesg.boot
204 fi
205
206 if checkyesno wscons && [ -f /etc/rc.wscons ]; then
207 echo 'configuring wscons'
208 /bin/sh /etc/rc.wscons $wscons_flags
209 fi
210
211 # start the system logger first, so that all messages from daemons
212 # are logged, then start savecore to get a dump on low memory systems
213 # and then start the name server.
214
215 if checkyesno syslogd; then
216 echo 'starting system logger'
217 # Transitional symlink for old binaries
218 if [ ! -h /dev/log ] ; then
219 ln -sf /var/run/log /dev/log
220 fi
221 rm -f /var/run/log
222 syslogd $syslogd_flags
223 fi
224
225 # Enable ipmon (only useful if ipfilter is running)
226 # NOTE: requires the IPFILTER_LOG kernel option.
227 if checkyesno ipmon; then
228 echo 'starting ipmon'
229 ipmon $ipmon_flags &
230 fi
231
232 # /var/crash should be a directory or a symbolic link
233 # to the crash directory if core dumps are to be saved.
234 if checkyesno savecore; then
235 if [ -d /var/crash/. ]; then
236 echo checking for core dump...
237 savecore $savecore_flags /var/crash
238 else
239 logger -s "WARNING: no /var/crash directory; savecore not run."
240 fi
241 fi
242
243 if checkyesno named; then
244 echo 'starting name server'; named $named_flags
245 fi
246
247 # set time, if requested
248 if checkyesno ntpdate; then
249 if [ -z "$ntpdate_hosts" ]; then
250 ntpdate_hosts=`awk '
251 /^server[ \t]*127.127/ {next}
252 /^(server|peer)/ {print $2}
253 ' </etc/ntp.conf`
254 fi
255 if [ -n "$ntpdate_hosts" ]; then
256 echo 'Setting date via ntp.'
257 ntpdate -b -s $ntpdate_hosts
258 fi
259 fi
260
261 # now start the rpc servers, for YP server/client.
262 echo -n 'starting rpc daemons:'
263
264 # note that portmap is generally required for all other rpc services.
265 if checkyesno portmap; then
266 echo -n ' portmap'; portmap $portmap_flags
267 fi
268
269 if checkyesno ypserv; then
270 if ! checkyesno portmap; then
271 echo
272 logger -s "WARNING: set portmap=YES in /etc/rc.conf" \
273 "if ypserv=YES."
274 fi
275
276 echo -n ' ypserv'; ypserv $ypserv_flags
277 fi
278
279 if checkyesno ypbind; then
280 echo -n ' ypbind'; ypbind $ypbind_flags
281 fi
282
283 if checkyesno yppasswdd; then
284 if ! checkyesno ypserv; then
285 echo
286 logger -s "WARNING: set ypserv=YES in /etc/rc.conf" \
287 "if yppasswdd=YES."
288 fi
289
290 echo -n ' rpc.yppasswdd'; rpc.yppasswdd $yppasswdd_flags
291 fi
292
293 if checkyesno bootparamd; then
294 if [ -r /etc/bootparams ]; then
295 echo -n ' rpc.bootparamd'; rpc.bootparamd $bootparamd_flags
296 else
297 echo
298 logger -s "WARNING: /etc/bootparams not found;" \
299 "bootparamd not started."
300 fi
301 fi
302
303 echo '.'
304
305 # load kernel modules specified in /etc/lkm.conf
306 if checkyesno lkm; then
307 if [ -r /etc/rc.lkm ]; then
308 lkmstage=BEFOREMOUNT
309 . /etc/rc.lkm
310 else
311 logger -s "WARNING: /etc/rc.lkm not found; LKMs not loaded."
312 fi
313 fi
314
315 mount -a
316
317 # now start the rpc servers, for NFS server/client.
318 if checkyesno nfs_client || checkyesno nfs_server; then
319 echo -n 'starting nfs daemons:'
320
321 if checkyesno nfs_server && ! checkyesno portmap; then
322 echo
323 logger -s "WARNING: set portmap=YES in /etc/rc.conf" \
324 "if nfs_server=YES."
325 fi
326
327 nfs_locking=NO
328
329 if checkyesno nfs_server; then
330 if [ -r /etc/exports ]; then
331 rm -f /var/db/mountdtab
332 echo -n > /var/db/mountdtab
333 echo -n ' mountd'; mountd $mountd_flags
334 echo -n ' nfsd'; nfsd $nfsd_flags
335 nfs_locking=YES
336 else
337 echo
338 logger -s "WARNING: /etc/exports not readable;" \
339 "NFS server not started."
340 fi
341 fi
342
343 if checkyesno nfs_client; then
344 echo -n ' nfsiod'; nfsiod $nfsiod_flags
345 nfs_locking=YES
346 fi
347
348 if checkyesno nfs_locking; then
349 if checkyesno statd; then
350 echo -n ' rpc.statd'; rpc.statd $statd_flags
351 fi
352 if checkyesno lockd; then
353 echo -n ' rpc.lockd'; rpc.lockd $lockd_flags
354 fi
355 fi
356
357 if checkyesno amd; then
358 if [ -d "$amd_dir" ]; then
359 if [ -r "$amd_master" ]; then
360 echo -n ' amd'
361 amd $amd_flags -p -a $amd_dir \
362 `sed s/#.*$// <$amd_master` >/var/run/amd.pid
363 else
364 echo
365 logger -s "WARNING: \$amd_master" \
366 " ($amd_master) not readable;" \
367 "amd not started."
368 fi
369 else
370 echo
371 logger -s "WARNING: \$amd_dir ($amd_dir) not a" \
372 "directory; amd not started."
373 fi
374 fi
375 echo '.'
376 fi
377
378
379 if [ -f /sbin/ldconfig ]; then
380 echo 'creating runtime link editor directory cache.'
381 ldconfig
382 fi
383
384 # load kernel modules specified in /etc/lkm.conf
385 if checkyesno lkm && [ -f /etc/rc.lkm ]; then
386 lkmstage=AFTERMOUNT
387 . /etc/rc.lkm
388 fi
389
390 # if $defcorename is set, change it here.
391 if [ -n "$defcorename" ]; then
392 echo -n 'setting default core name template: '
393 sysctl -w kern.defcorename=$defcorename
394 fi
395
396 # if $securelevel is set, change it here, else if it is 0, change
397 # it to 1 here, before we start login services.
398 if [ -n "$securelevel" ]; then
399 echo -n 'setting securelevel: '
400 sysctl -w kern.securelevel=$securelevel
401 else
402 securelevel=`sysctl -n kern.securelevel`
403 if [ x"$securelevel" = x0 ]; then
404 echo -n 'setting securelevel: '
405 sysctl -w kern.securelevel=1
406 fi
407 fi
408
409 echo -n 'checking quotas:'; quotacheck -a; echo ' done.'
410 quotaon -a
411
412 chmod 666 /dev/tty[pqrs]*
413
414 # check the password temp/lock file
415 if [ -f /etc/ptmp ]
416 then
417 logger -s -p auth.err \
418 'password file may be incorrect -- /etc/ptmp exists'
419 fi
420
421 # XXX replace me with a script that works!
422 virecovery=`echo /var/tmp/vi.recover/recover.*`
423 if [ "$virecovery" != "/var/tmp/vi.recover/recover.*" ]; then
424 echo preserving editor files
425 for i in $virecovery; do
426 if [ -f $i ]; then
427 sendmail -t < $i
428 fi
429 done
430 fi
431
432 echo clearing /tmp
433
434 # Prune quickly with one rm, then use find to clean up /tmp/[lq]* (this
435 # is not needed with mfs /tmp, but doesn't hurt anything).
436 (cd /tmp && rm -rf [a-km-pr-zA-Z]* &&
437 find . ! -name . ! -name lost+found ! -name quota.user \
438 ! -name quota.group -exec rm -rf -- {} \; -type d -prune)
439
440 # Update kernel info in /etc/motd
441 # Must be done *before* interactive logins are possible to prevent
442 # possible race conditions.
443 if checkyesno update_motd; then
444 echo 'updating motd.'
445 if [ ! -f /etc/motd ]; then
446 install -c -o root -g wheel -m 664 /dev/null /etc/motd
447 fi
448 T=/etc/_motd
449 rm -f $T
450 sysctl -n kern.version | sed 1q > $T
451 echo "" >> $T
452 sed '1,/^$/d' < /etc/motd >> $T
453 cmp -s $T /etc/motd || cp $T /etc/motd
454 rm -f $T
455 fi
456
457 if checkyesno accounting; then
458 if [ -f /var/account/acct ]; then
459 echo 'turning on accounting'
460 accton /var/account/acct
461 else
462 logger -s "WARNING: /var/account/acct doesn't exist;" \
463 "accounting not enabled."
464 fi
465 fi
466
467 echo -n standard daemons:
468 if checkyesno cron; then
469 echo -n ' cron'; cron
470 fi
471 echo '.'
472
473 # now start all the other daemons
474 echo -n starting network daemons:
475
476 if checkyesno gated && checkyesno routed; then
477 echo
478 logger -s "WARNING: gated and routed both requested to be run:" \
479 "running only gated."
480 routed=NO
481 fi
482
483 if checkyesno gated; then
484 if [ -r /etc/gated.conf ]; then
485 echo -n ' gated'; gated $gated_flags
486 else
487 echo
488 logger -s "WARNING: no /etc/gated.conf; gated not started."
489 fi
490 fi
491
492 if checkyesno routed; then
493 echo -n ' routed'; routed $routed_flags
494 fi
495
496 if checkyesno mrouted; then
497 echo -n ' mrouted'; mrouted $mrouted_flags
498 fi
499
500 if checkyesno route6d; then
501 echo -n ' route6d'; route6d $route6d_flags
502 fi
503
504 if checkyesno rtsold; then
505 if checkyesno ip6forwarding; then
506 echo
507 logger -s "WARNING: rtsold cannot be used on IPv6 router."
508 else
509 echo -n ' rtsold'; rtsold $rtsold_flags
510 fi
511 fi
512
513 if checkyesno rtadvd; then
514 if checkyesno ip6forwarding; then
515 echo -n ' rtadvd'; rtadvd $rtadvd_flags
516 else
517 echo
518 logger -s "WARNING: rtadvd cannot be used on IPv6 host."
519 fi
520 fi
521
522 if checkyesno timed; then
523 echo -n ' timed'; timed $timed_flags
524 fi
525
526 if checkyesno xntpd; then
527 echo -n ' xntpd'; xntpd $xntpd_flags
528 fi
529
530 if checkyesno dhcpd; then
531 if [ -r /etc/dhcpd.conf ]; then
532 echo -n ' dhcpd'; dhcpd $dhcpd_flags
533 else
534 echo
535 logger -s "WARNING: /etc/dhcpd.conf not readable;" \
536 "dhcpd not started."
537 fi
538 elif checkyesno dhcrelay; then
539 echo -n ' dhcrelay'; dhcrelay $dhcrelay_flags
540 fi
541
542 if checkyesno rwhod; then
543 echo -n ' rwhod'; rwhod
544 fi
545
546 if checkyesno lpd; then
547 echo -n ' lpd'; lpd $lpd_flags
548 fi
549
550 # We call sendmail with a full path so that SIGHUP works.
551 if checkyesno sendmail; then
552 if [ -r /etc/sendmail.cf ]; then
553 echo -n ' sendmail'; /usr/sbin/sendmail $sendmail_flags
554 else
555 echo
556 logger -s "WARNING: /etc/sendmail.cf not readable;" \
557 "sendmail not started."
558 fi
559 fi
560
561 # Start xfs before boot daemons, so its ready before client xterminals.
562 if checkyesno xfs; then
563 echo -n ' xfs'; xfs $xfs_flags
564 sleep 2
565 fi
566
567 if checkyesno rarpd; then
568 if [ -r /etc/ethers ]; then
569 echo -n ' rarpd'; rarpd $rarpd_flags
570 else
571 echo
572 logger -s "WARNING: /etc/ethers not readable;" \
573 "rarpd not started."
574 fi
575 fi
576
577 if checkyesno rbootd; then
578 if [ -r /etc/rbootd.conf ]; then
579 echo -n ' rbootd'; rbootd $rbootd_flags
580 else
581 echo
582 logger -s "WARNING: /etc/rbootd.conf not readable;" \
583 "rbootd not started."
584 fi
585 fi
586
587 if checkyesno mopd; then
588 echo -n ' mopd'; mopd $mopd_flags
589 fi
590
591 if checkyesno apmd; then
592 echo -n ' apmd'; apmd $apmd_flags
593 fi
594
595 if checkyesno screenblank; then
596 echo -n ' screenblank'; screenblank $screenblank_flags
597 fi
598
599 if checkyesno inetd; then
600 if [ -r /etc/inetd.conf ]; then
601 echo -n ' inetd'; inetd $inetd_flags
602 else
603 echo
604 logger -s "WARNING: /etc/inetd.conf not readable;" \
605 "inetd not started."
606 fi
607 fi
608
609 echo '.'
610
611 # Kerberos runs ONLY on the Kerberos server machine
612 if checkyesno kerberos; then
613 echo -n 'starting kerberos daemons:'
614 echo -n ' kerberos'; kerberos >> /var/log/kerberos.log &
615 echo -n ' kadmind'; kadmind -n >> /var/log/kadmind.log &
616 echo '.'
617 fi
618
619 # xdm after wscons - need a virtual screen for X
620 if checkyesno xdm; then
621 echo 'starting xdm'
622 xdm $xdm_flags
623 fi
624
625 . /etc/rc.local
626
627 date
628 exit 0
629