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