rc revision 1.100 1 # $NetBSD: rc,v 1.100 1998/01/26 12:02:50 lukem 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 # Add all block-type swap devices; these might be necessary
25 # during disk checks.
26 swapctl -A -t blk
27
28 if [ -e /fastboot ]; then
29 echo "Fast boot: skipping disk checks."
30 elif [ "$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
62 fi
63
64 trap "echo 'Boot interrupted.'; exit 1" 3
65
66 umount -a >/dev/null 2>&1
67 mount /
68 rm -f /fastboot # XXX (root now writeable)
69
70 if [ -f /etc/rc.subr ]; then
71 . /etc/rc.subr
72 else
73 echo "Can't read /etc/rc.subr; aborting."
74 exit 1;
75 fi
76
77 if [ -f /etc/rc.conf ]; then
78 . /etc/rc.conf
79 fi
80
81 if [ "$rc_configured" != YES ]; then
82 echo "/etc/rc.conf is not configured. Multiuser boot aborted."
83 exit 1
84 fi
85
86 # set flags on ttys. (do early, in case they use tty for SLIP in netstart)
87 echo 'setting tty flags'
88 ttyflags -a
89
90 # load kernel modules specified in /etc/lkm.conf if the /usr filesystem
91 # is already present with "/" or can be mounted now
92 if checkyesno lkm && [ -f /etc/rc.lkm ]; then
93 mount /usr >/dev/null 2>&1
94 if [ -x /usr/bin/ld ]; then
95 lkmstage=BEFORENET
96 . /etc/rc.lkm
97 fi
98 fi
99
100 # set hostname, turn on network
101 echo 'starting network'
102 sh /etc/netstart
103 if [ $? -ne 0 ]; then
104 exit 1
105 fi
106
107 for fs in /usr /var $critical_filesystems; do
108 mount | (
109 ismounted=no
110 while read what _on on _type type; do
111 if [ $on = $fs ]; then
112 ismounted=yes
113 fi
114 done
115 if [ $ismounted = no ]; then
116 mount $fs >/dev/null 2>&1
117 fi
118 )
119 done
120
121 # Network Address Translation...
122 if checkyesno ipnat && [ -f /etc/ipnat.conf ]; then
123 echo 'installing NAT rules ... '
124 if ! checkyesno ipfilter || [ ! -f /etc/ipf.conf ]; then
125 ipf -E -Fa
126 fi
127 ipnat -F -f /etc/ipnat.conf
128 fi
129
130 # "Critical" file systems are now mounted. Go ahead and swap
131 # to files now, since they will be residing in the critical file
132 # systems (or, at least, better).
133 swapctl -A -t noblk
134
135 # Check for no swap, and warn about it unless that is desired.
136 if ! checkyesno no_swap; then
137 swapctl -s | grep 'no swap devices configured' > /dev/null && \
138 echo "WARNING: no swap space configured!"
139 fi
140
141 # clean up left-over files
142 rm -f /etc/nologin
143 rm -f /var/spool/lock/LCK.*
144 rm -f /var/spool/uucp/STST/*
145 (cd /var/run && { rm -rf -- *; install -c -m 664 -g utmp /dev/null utmp; })
146
147 # start the system logger first, so that all messages from daemons
148 # are logged, then start savecore to get a dump on low memory systems
149 # and then start the name server.
150
151 if checkyesno syslogd; then
152 echo 'starting system logger'
153 rm -f /dev/log
154 syslogd $syslogd_flags
155 fi
156
157 # Enable ipmon (only useful if ipfilter is running)
158 # NOTE: requires the IPFILTER_LOG kernel option.
159 if checkyesno ipmon; then
160 echo 'starting ipmon'
161 ipmon $ipmon_flags &
162 fi
163
164 # /var/crash should be a directory or a symbolic link
165 # to the crash directory if core dumps are to be saved.
166 if checkyesno savecore; then
167 if [ -d /var/crash ]; then
168 echo checking for core dump...
169 savecore $savecore_flags /var/crash
170 else
171 logger -s "WARNING: no /var/crash directory; savecore not run."
172 fi
173 fi
174
175 if checkyesno named; then
176 echo 'starting name server'; named $named_flags
177 fi
178
179 # set time, if requested
180 if checkyesno ntpdate; then
181 if [ -z "$ntpdate_hosts" ]; then
182 ntpdate_hosts=`awk '/^server/ {print $2}' </etc/ntp.conf`
183 fi
184 if [ -n "$ntpdate_hosts" ]; then
185 echo 'Setting date via ntp.'
186 ntpdate -b $ntpdate_hosts
187 fi
188 fi
189
190 # now start the rpc servers, for YP server/client.
191 echo -n 'starting rpc daemons:'
192
193 # note that portmap is generally required for all other rpc services.
194 if checkyesno portmap; then
195 echo -n ' portmap'; portmap
196 fi
197
198 if checkyesno ypserv; then
199 echo -n ' ypserv'; ypserv $ypserv_flags
200 fi
201
202 if checkyesno ypbind; then
203 echo -n ' ypbind'; ypbind $ypbind_flags
204 fi
205
206 if checkyesno yppasswdd; then
207 echo -n ' rpc.yppasswdd'; rpc.yppasswdd $yppasswdd_flags
208 fi
209
210 if checkyesno bootparamd; then
211 if [ -r /etc/bootparams ]; then
212 echo -n ' rpc.bootparamd'; rpc.bootparamd $bootparamd_flags
213 else
214 echo
215 logger -s "WARNING: /etc/bootparams not found. " \
216 "bootparamd not started."
217 fi
218 fi
219
220 echo '.'
221
222 # load kernel modules specified in /etc/lkm.conf
223 if checkyesno lkm; then
224 if [ -r /etc/rc.lkm ]; then
225 lkmstage=BEFOREMOUNT
226 . /etc/rc.lkm
227 else
228 logger -s "WARNING: /etc/rc.lkm not found; LKMs not loaded."
229 fi
230 fi
231
232 mount -a
233
234 # now start the rpc servers, for NFS server/client.
235 echo -n 'starting nfs daemons:'
236
237 nfs_locking=NO
238
239 if checkyesno nfs_server; then
240 if [ -r /etc/exports ]; then
241 rm -f /var/db/mountdtab
242 echo -n > /var/db/mountdtab
243 echo -n ' mountd'; mountd $mountd_flags
244 echo -n ' nfsd'; nfsd $nfsd_flags
245 nfs_locking=YES
246 else
247 echo
248 logger -s "WARNING: /etc/exports not readable; " \
249 "NFS server not started."
250 fi
251 fi
252
253 if checkyesno nfs_client; then
254 echo -n ' nfsiod'; nfsiod $nfsiod_flags
255 nfs_locking=YES
256 fi
257
258 if checkyesno nfs_locking; then
259 if checkyesno statd; then
260 echo -n ' rpc.statd'; rpc.statd $statd_flags
261 fi
262 if checkyesno lockd; then
263 echo -n ' rpc.lockd'; rpc.lockd $lockd_flags
264 fi
265 fi
266
267 if checkyesno amd; then
268 if [ -d "$amd_dir" ]; then
269 if [ -r "$amd_master" ]; then
270 echo -n ' amd'
271 amd $amd_flags -p -a $amd_dir `cat $amd_master` \
272 > /var/run/amd.pid
273 else
274 echo
275 logger -s "WARNING: \$amd_master ($amd_master)not " \
276 "readable; amd not started."
277 fi
278 else
279 echo
280 logger -s "WARNING: \$amd_dir ($amd_dir) not a directory; " \
281 "amd not started."
282 fi
283 fi
284
285 echo '.'
286
287 if [ -f /sbin/ldconfig ]; then
288 echo 'creating runtime link editor directory cache.'
289 ldconfig
290 fi
291
292 # load kernel modules specified in /etc/lkm.conf
293 if checkyesno lkm && [ -f /etc/rc.lkm ]; then
294 lkmstage=AFTERMOUNT
295 . /etc/rc.lkm
296 fi
297
298 echo -n 'checking quotas:'; quotacheck -a; echo ' done.'
299 quotaon -a
300
301 # build ps databases
302 echo 'building databases...'
303 kvm_mkdb /netbsd
304 dev_mkdb
305
306 chmod 666 /dev/tty[pqrs]*
307
308 # check the password temp/lock file
309 if [ -f /etc/ptmp ]
310 then
311 logger -s -p auth.err \
312 'password file may be incorrect -- /etc/ptmp exists'
313 fi
314
315 virecovery=`echo /var/tmp/vi.recover/recover.*`
316 if [ "$virecovery" != "/var/tmp/vi.recover/recover.*" ]; then
317 echo preserving editor files
318 for i in $virecovery; do
319 sendmail -t < $i
320 done
321 fi
322
323 echo clearing /tmp
324
325 # Prune quickly with one rm, then use find to clean up /tmp/[lq]* (this
326 # is not needed with mfs /tmp, but doesn't hurt anything).
327 (cd /tmp && rm -rf [a-km-pr-zA-Z]* &&
328 find . ! -name . ! -name lost+found ! -name quota.user \
329 ! -name quota.group -exec rm -rf -- {} \; -type d -prune)
330
331 # Update kernel info in /etc/motd
332 # Must be done *before* interactive logins are possible to prevent
333 # possible race conditions.
334 if checkyesno update_motd; then
335 echo 'updating motd.'
336 if [ ! -f /etc/motd ]; then
337 install -c -o root -g wheel -m 664 /dev/null /etc/motd
338 fi
339 T=/tmp/_motd
340 rm -f $T
341 sysctl -n kern.version | sed 1q > $T
342 echo "" >> $T
343 sed '1,/^$/d' < /etc/motd >> $T
344 cmp -s $T /etc/motd || cp $T /etc/motd
345 rm -f $T
346 fi
347
348 if [ -f /var/account/acct ]; then
349 echo 'turning on accounting'; accton /var/account/acct
350 fi
351
352 echo -n standard daemons:
353 if checkyesno update; then
354 echo -n ' update'; update $update_flags
355 fi
356 echo -n ' cron'; cron
357 echo '.'
358
359 # now start all the other daemons
360 echo -n starting network daemons:
361
362 if checkyesno gated && checkyesno routed; then
363 echo
364 logger -s "WARNING: gated and routed both requested to be run: " \
365 "running only gated."
366 routed=NO
367 fi
368
369 if checkyesno gated; then
370 if [ -r /etc/gated.conf ]; then
371 echo -n ' gated'; gated $gated_flags
372 else
373 logger -s "WARNING: no /etc/gated.conf; gated not started."
374 fi
375 fi
376
377 if checkyesno routed; then
378 echo -n ' routed'; routed $routed_flags
379 fi
380
381 if checkyesno mrouted; then
382 echo -n ' mrouted'; mrouted $mrouted_flags
383 fi
384
385 if checkyesno timed; then
386 echo -n ' timed'; timed $timed_flags
387 fi
388
389 if checkyesno xntpd; then
390 echo -n ' xntpd'; xntpd $xntpd_flags
391 fi
392
393 if checkyesno dhcpd; then
394 if [ -r /etc/dhcpd.conf ]; then
395 echo -n ' dhcpd'; dhcpd $dhcpd_flags
396 else
397 echo
398 logger -s "WARNING: /etc/dhcpd.conf not readable; " \
399 "dhcpd not started."
400 fi
401 fi
402
403 if checkyesno rwhod; then
404 echo -n ' rwhod'; rwhod
405 fi
406
407 if checkyesno lpd; then
408 echo -n ' lpd'; lpd $lpd_flags
409 fi
410
411 # We call sendmail with a full path so that SIGHUP works.
412 if checkyesno sendmail; then
413 if [ -r /etc/sendmail.cf ]; then
414 echo -n ' sendmail'; /usr/sbin/sendmail $sendmail_flags
415 else
416 echo
417 logger -s "WARNING: /etc/sendmail.cf not readable; " \
418 "sendmail not started."
419 fi
420 fi
421
422 # Start xfs before boot daemons, so its ready before client xterminals.
423 if checkyesno xfs; then
424 echo -n ' xfs'; xfs $xfs_flags &
425 sleep 2
426 fi
427
428 if checkyesno rarpd; then
429 if [ -r /etc/ethers ]; then
430 echo -n ' rarpd'; rarpd $rarpd_flags
431 else
432 echo
433 logger -s "WARNING: /etc/ethers not readable; " \
434 "rarpd not started."
435 fi
436 fi
437
438 if checkyesno rbootd; then
439 if [ -r /etc/rbootd.conf ]; then
440 echo -n ' rbootd'; rbootd $rbootd_flags
441 else
442 echo
443 logger -s "WARNING: /etc/rbootd.conf not readable; " \
444 "rarpd not started."
445 fi
446 fi
447
448 if checkyesno mopd; then
449 echo -n ' mopd'; mopd $mopd_flags
450 fi
451
452 if checkyesno apmd; then
453 echo -n ' apmd'; apmd $apmd_flags
454 fi
455
456 if checkyesno inetd; then
457 if [ -r /etc/inetd.conf ]; then
458 echo -n ' inetd'; inetd $inetd_flags
459 else
460 echo
461 logger -s "WARNING: /etc/inetd.conf not readable; " \
462 "inetd not started."
463 fi
464 fi
465
466 if checkyesno xdm; then
467 echo -n ' xdm'; xdm $xdm_flags
468 fi
469
470 echo '.'
471
472 # Kerberos runs ONLY on the Kerberos server machine
473 if checkyesno kerberos; then
474 echo -n 'starting kerberos daemons:'
475 echo -n ' kerberos'; kerberos >> /var/log/kerberos.log &
476 echo -n ' kadmind'; kadmind -n >> /var/log/kadmind.log &
477 echo '.'
478 fi
479
480 . /etc/rc.local
481
482 date
483 exit 0
484