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