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