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