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