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