rc revision 1.131 1 # $NetBSD: rc,v 1.131 1999/09/16 11:00:44 darrenr 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 [ "$rc_configured" != YES ]; 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 # set hostname, turn on network
110 echo 'starting network'
111 sh /etc/netstart
112 if [ $? -ne 0 ]; then
113 exit 1
114 fi
115
116 mount_critical_filesystems network
117
118 # Network Address Translation...
119 if checkyesno ipnat && [ -f /etc/ipnat.conf ]; then
120 echo 'installing NAT rules ... '
121 if ! checkyesno ipfilter || [ ! -f /etc/ipf.conf ]; then
122 ipf -E -Fa
123 fi
124 ipnat -F -f /etc/ipnat.conf
125 fi
126
127 # "Critical" file systems are now mounted. Go ahead and swap
128 # to files now, since they will be residing in the critical file
129 # systems (or, at least, better).
130 swapctl -A -t noblk
131
132 # Check for no swap, and warn about it unless that is desired.
133 if ! checkyesno no_swap; then
134 swapctl -s | grep 'no swap devices configured' > /dev/null && \
135 echo "WARNING: no swap space configured!"
136 fi
137
138 # clean up left-over files
139 rm -f /etc/nologin
140 rm -f /var/spool/lock/LCK.*
141 rm -f /var/spool/uucp/STST/*
142 (cd /var/run && { rm -rf -- *; install -c -m 664 -g utmp /dev/null utmp; })
143
144 # if this kernel supports machdep.booted_kernel, use that to build the KVM
145 # db so dmesg will run work when we boot /netbsd.new, etc.
146 sysctl machdep | grep -q booted_kernel
147 if [ $? -eq 0 ] ; then
148 kvm_mkdb `sysctl -n machdep.booted_kernel`
149 fi
150 # get the system dmesg output, hopefully containing the boot messages
151 # $dmesg_flags is imported from /etc/rc.conf
152 if checkyesno dmesg; then
153 dmesg $dmesg_flags > /var/run/dmesg.boot
154 fi
155
156 if checkyesno wscons && [ -f /etc/rc.wscons ]; then
157 echo 'configuring wscons'
158 /bin/sh /etc/rc.wscons $wscons_flags
159 fi
160
161 # start the system logger first, so that all messages from daemons
162 # are logged, then start savecore to get a dump on low memory systems
163 # and then start the name server.
164
165 if checkyesno syslogd; then
166 echo 'starting system logger'
167 # Transitional symlink for old binaries
168 if [ ! -h /dev/log ] ; then
169 ln -sf /var/run/log /dev/log
170 fi
171 rm -f /var/run/log
172 syslogd $syslogd_flags
173 fi
174
175 # Enable ipmon (only useful if ipfilter is running)
176 # NOTE: requires the IPFILTER_LOG kernel option.
177 if checkyesno ipmon; then
178 echo 'starting ipmon'
179 ipmon $ipmon_flags &
180 fi
181
182 # /var/crash should be a directory or a symbolic link
183 # to the crash directory if core dumps are to be saved.
184 if checkyesno savecore; then
185 if [ -d /var/crash/. ]; then
186 echo checking for core dump...
187 savecore $savecore_flags /var/crash
188 else
189 logger -s "WARNING: no /var/crash directory; savecore not run."
190 fi
191 fi
192
193 if checkyesno named; then
194 echo 'starting name server'; named $named_flags
195 fi
196
197 # set time, if requested
198 if checkyesno ntpdate; then
199 if [ -z "$ntpdate_hosts" ]; then
200 ntpdate_hosts=`awk '
201 /^server[ \t]*127.127/ {next}
202 /^(server|peer)/ {print $2}
203 ' </etc/ntp.conf`
204 fi
205 if [ -n "$ntpdate_hosts" ]; then
206 echo 'Setting date via ntp.'
207 ntpdate -b -s $ntpdate_hosts
208 fi
209 fi
210
211 # now start the rpc servers, for YP server/client.
212 echo -n 'starting rpc daemons:'
213
214 # note that portmap is generally required for all other rpc services.
215 if checkyesno portmap; then
216 echo -n ' portmap'; portmap $portmap_flags
217 fi
218
219 if checkyesno ypserv; then
220 echo -n ' ypserv'; ypserv $ypserv_flags
221 fi
222
223 if checkyesno ypbind; then
224 echo -n ' ypbind'; ypbind $ypbind_flags
225 fi
226
227 if checkyesno yppasswdd; then
228 echo -n ' rpc.yppasswdd'; rpc.yppasswdd $yppasswdd_flags
229 fi
230
231 if checkyesno bootparamd; then
232 if [ -r /etc/bootparams ]; then
233 echo -n ' rpc.bootparamd'; rpc.bootparamd $bootparamd_flags
234 else
235 echo
236 logger -s "WARNING: /etc/bootparams not found. " \
237 "bootparamd not started."
238 fi
239 fi
240
241 echo '.'
242
243 # load kernel modules specified in /etc/lkm.conf
244 if checkyesno lkm; then
245 if [ -r /etc/rc.lkm ]; then
246 lkmstage=BEFOREMOUNT
247 . /etc/rc.lkm
248 else
249 logger -s "WARNING: /etc/rc.lkm not found; LKMs not loaded."
250 fi
251 fi
252
253 mount -a
254
255 # now start the rpc servers, for NFS server/client.
256 echo -n 'starting nfs daemons:'
257
258 nfs_locking=NO
259
260 if checkyesno nfs_server; then
261 if [ -r /etc/exports ]; then
262 rm -f /var/db/mountdtab
263 echo -n > /var/db/mountdtab
264 echo -n ' mountd'; mountd $mountd_flags
265 echo -n ' nfsd'; nfsd $nfsd_flags
266 nfs_locking=YES
267 else
268 echo
269 logger -s "WARNING: /etc/exports not readable; " \
270 "NFS server not started."
271 fi
272 fi
273
274 if checkyesno nfs_client; then
275 echo -n ' nfsiod'; nfsiod $nfsiod_flags
276 nfs_locking=YES
277 fi
278
279 if checkyesno nfs_locking; then
280 if checkyesno statd; then
281 echo -n ' rpc.statd'; rpc.statd $statd_flags
282 fi
283 if checkyesno lockd; then
284 echo -n ' rpc.lockd'; rpc.lockd $lockd_flags
285 fi
286 fi
287
288 if checkyesno amd; then
289 if [ -d "$amd_dir" ]; then
290 if [ -r "$amd_master" ]; then
291 echo -n ' amd'
292 amd $amd_flags -p -a $amd_dir \
293 `sed s/#.*$// <$amd_master` >/var/run/amd.pid
294 else
295 echo
296 logger -s "WARNING: \$amd_master ($amd_master)not " \
297 "readable; amd not started."
298 fi
299 else
300 echo
301 logger -s "WARNING: \$amd_dir ($amd_dir) not a directory; " \
302 "amd not started."
303 fi
304 fi
305
306 echo '.'
307
308 if [ -f /sbin/ldconfig ]; then
309 echo 'creating runtime link editor directory cache.'
310 ldconfig
311 fi
312
313 # load kernel modules specified in /etc/lkm.conf
314 if checkyesno lkm && [ -f /etc/rc.lkm ]; then
315 lkmstage=AFTERMOUNT
316 . /etc/rc.lkm
317 fi
318
319 # if $securelevel is set, change it here, else if it is 0, change
320 # it to 1 here, before we start login services.
321 if [ -n "$securelevel" ]; then
322 echo -n 'setting securelevel: '
323 sysctl -w kern.securelevel=$securelevel
324 else
325 securelevel=`sysctl -n kern.securelevel`
326 if [ x"$securelevel" = x0 ]; then
327 echo -n 'setting securelevel: '
328 sysctl -w kern.securelevel=1
329 fi
330 fi
331
332 echo -n 'checking quotas:'; quotacheck -a; echo ' done.'
333 quotaon -a
334
335 # build ps databases
336 echo 'building databases...'
337 kvm_mkdb /netbsd
338 dev_mkdb
339
340 chmod 666 /dev/tty[pqrs]*
341
342 # check the password temp/lock file
343 if [ -f /etc/ptmp ]
344 then
345 logger -s -p auth.err \
346 'password file may be incorrect -- /etc/ptmp exists'
347 fi
348
349 # XXX replace me with a script that works!
350 virecovery=`echo /var/tmp/vi.recover/recover.*`
351 if [ "$virecovery" != "/var/tmp/vi.recover/recover.*" ]; then
352 echo preserving editor files
353 for i in $virecovery; do
354 if [ -f $i ]; then
355 sendmail -t < $i
356 fi
357 done
358 fi
359
360 echo clearing /tmp
361
362 # Prune quickly with one rm, then use find to clean up /tmp/[lq]* (this
363 # is not needed with mfs /tmp, but doesn't hurt anything).
364 (cd /tmp && rm -rf [a-km-pr-zA-Z]* &&
365 find . ! -name . ! -name lost+found ! -name quota.user \
366 ! -name quota.group -exec rm -rf -- {} \; -type d -prune)
367
368 # Update kernel info in /etc/motd
369 # Must be done *before* interactive logins are possible to prevent
370 # possible race conditions.
371 if checkyesno update_motd; then
372 echo 'updating motd.'
373 if [ ! -f /etc/motd ]; then
374 install -c -o root -g wheel -m 664 /dev/null /etc/motd
375 fi
376 T=/etc/_motd
377 rm -f $T
378 sysctl -n kern.version | sed 1q > $T
379 echo "" >> $T
380 sed '1,/^$/d' < /etc/motd >> $T
381 cmp -s $T /etc/motd || cp $T /etc/motd
382 rm -f $T
383 fi
384
385 if [ -f /var/account/acct ]; then
386 echo 'turning on accounting'; accton /var/account/acct
387 fi
388
389 echo -n standard daemons:
390 if checkyesno update; then
391 echo -n ' update'; update $update_flags
392 fi
393 if checkyesno cron; then
394 echo -n ' cron'; cron
395 fi
396 echo '.'
397
398 # now start all the other daemons
399 echo -n starting network daemons:
400
401 if checkyesno gated && checkyesno routed; then
402 echo
403 logger -s "WARNING: gated and routed both requested to be run: " \
404 "running only gated."
405 routed=NO
406 fi
407
408 if checkyesno gated; then
409 if [ -r /etc/gated.conf ]; then
410 echo -n ' gated'; gated $gated_flags
411 else
412 logger -s "WARNING: no /etc/gated.conf; gated not started."
413 fi
414 fi
415
416 if checkyesno routed; then
417 echo -n ' routed'; routed $routed_flags
418 fi
419
420 if checkyesno mrouted; then
421 echo -n ' mrouted'; mrouted $mrouted_flags
422 fi
423
424 if checkyesno route6d; then
425 echo -n ' route6d'; route6d $route6d_flags
426 fi
427
428 if checkyesno rtsold; then
429 if checkyesno ip6forwarding; then
430 logger -s "WARNING: rtsold cannot be used on IPv6 router."
431 else
432 echo -n ' rtsold'; rtsold $rtsold_flags
433 fi
434 fi
435
436 if checkyesno rtadvd; then
437 if checkyesno ip6forwarding; then
438 echo -n ' rtadvd'; rtadvd $rtadvd_flags
439 else
440 logger -s "WARNING: rtadvd cannot be used on IPv6 host."
441 fi
442 fi
443
444 if checkyesno timed; then
445 echo -n ' timed'; timed $timed_flags
446 fi
447
448 if checkyesno xntpd; then
449 echo -n ' xntpd'; xntpd $xntpd_flags
450 fi
451
452 if checkyesno dhcpd; then
453 if [ -r /etc/dhcpd.conf ]; then
454 echo -n ' dhcpd'; dhcpd $dhcpd_flags
455 else
456 echo
457 logger -s "WARNING: /etc/dhcpd.conf not readable; " \
458 "dhcpd not started."
459 fi
460 elif checkyesno dhcrelay; then
461 echo -n ' dhcrelay'; dhcrelay $dhcrelay_flags
462 fi
463
464 if checkyesno rwhod; then
465 echo -n ' rwhod'; rwhod
466 fi
467
468 if checkyesno lpd; then
469 echo -n ' lpd'; lpd $lpd_flags
470 fi
471
472 # We call sendmail with a full path so that SIGHUP works.
473 if checkyesno sendmail; then
474 if [ -r /etc/sendmail.cf ]; then
475 echo -n ' sendmail'; /usr/sbin/sendmail $sendmail_flags
476 else
477 echo
478 logger -s "WARNING: /etc/sendmail.cf not readable; " \
479 "sendmail not started."
480 fi
481 fi
482
483 # Start xfs before boot daemons, so its ready before client xterminals.
484 if checkyesno xfs; then
485 echo -n ' xfs'; xfs $xfs_flags &
486 sleep 2
487 fi
488
489 if checkyesno rarpd; then
490 if [ -r /etc/ethers ]; then
491 echo -n ' rarpd'; rarpd $rarpd_flags
492 else
493 echo
494 logger -s "WARNING: /etc/ethers not readable; " \
495 "rarpd not started."
496 fi
497 fi
498
499 if checkyesno rbootd; then
500 if [ -r /etc/rbootd.conf ]; then
501 echo -n ' rbootd'; rbootd $rbootd_flags
502 else
503 echo
504 logger -s "WARNING: /etc/rbootd.conf not readable; " \
505 "rbootd not started."
506 fi
507 fi
508
509 if checkyesno mopd; then
510 echo -n ' mopd'; mopd $mopd_flags
511 fi
512
513 if checkyesno apmd; then
514 echo -n ' apmd'; apmd $apmd_flags
515 fi
516
517 if checkyesno screenblank; then
518 echo -n ' screenblank'; screenblank $screenblank_flags
519 fi
520
521 if checkyesno inetd; then
522 if [ -r /etc/inetd.conf ]; then
523 echo -n ' inetd'; inetd $inetd_flags
524 else
525 echo
526 logger -s "WARNING: /etc/inetd.conf not readable; " \
527 "inetd not started."
528 fi
529 fi
530
531 echo '.'
532
533 # Kerberos runs ONLY on the Kerberos server machine
534 if checkyesno kerberos; then
535 echo -n 'starting kerberos daemons:'
536 echo -n ' kerberos'; kerberos >> /var/log/kerberos.log &
537 echo -n ' kadmind'; kadmind -n >> /var/log/kadmind.log &
538 echo '.'
539 fi
540
541 # xdm after wscons - need a virtual screen for X
542 if checkyesno xdm; then
543 echo 'starting xdm'
544 xdm $xdm_flags
545 fi
546
547 . /etc/rc.local
548
549 date
550 exit 0
551