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