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