]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - etc/rc
This commit was generated by cvs2svn to compensate for changes in r42788,
[FreeBSD/FreeBSD.git] / etc / rc
1 #!/bin/sh
2 #       $Id: rc,v 1.167 1999/01/17 03:32:07 grog Exp $
3 #       From: @(#)rc    5.27 (Berkeley) 6/5/91
4
5 # System startup script run by init on autoboot
6 # or after single-user.
7 # Output and error are redirected to console by init,
8 # and the console is the controlling terminal.
9
10 # Note that almost all the user-configurable behavior is no longer in
11 # this file, but rather in /etc/rc.conf.  Please check this file
12 # first before contemplating any changes here.
13
14 stty status '^T'
15
16 # Set shell to ignore SIGINT (2), but not children;
17 # shell catches SIGQUIT (3) and returns to single user after fsck.
18 trap : 2
19 trap : 3        # shouldn't be needed
20
21 HOME=/; export HOME
22 PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin
23 export PATH
24
25 # Configure ccd devices.
26 if [ -f /etc/ccd.conf ]; then
27         ccdconfig -C
28 fi
29
30 if [ -n "$vinum_slices" ]; then
31         if [ -r /modules/vinum.ko ]; then       # jkh paranoia
32                 kldload vinum
33                 vinum read $vinum_slices
34         else
35                 echo "Can't find /modules/vinum.ko"
36         fi
37 fi
38
39 swapon -a
40
41 if [ $1x = autobootx ]; then
42         echo Automatic reboot in progress...
43         fsck -p
44         case $? in
45         0)
46                 ;;
47         2)
48                 exit 1
49                 ;;
50         4)
51                 reboot
52                 echo "reboot failed... help!"
53                 exit 1
54                 ;;
55         8)
56                 echo "Automatic file system check failed... help!"
57                 exit 1
58                 ;;
59         12)
60                 echo "Reboot interrupted"
61                 exit 1
62                 ;;
63         130)
64                 # interrupt before catcher installed
65                 exit 1
66                 ;;
67         *)
68                 echo "Unknown error in reboot"
69                 exit 1
70                 ;;
71         esac
72 else
73         echo Skipping disk checks ...
74 fi
75
76 trap "echo 'Reboot interrupted'; exit 1" 3
77
78 # root must be read/write for NFS diskless before proceeding any further.
79 mount -u -o rw /
80 if [ $? != 0 ]; then
81         echo "Filesystem mount failed, startup aborted"
82         exit 1
83 fi
84
85 umount -a >/dev/null 2>&1
86
87 mount -a -t nonfs
88 if [ $? != 0 ]; then
89         echo "Filesystem mount failed, startup aborted"
90         exit 1
91 fi
92
93 # If there is a global system configuration file, suck it in.
94 if [ -f /etc/rc.conf ]; then
95         . /etc/rc.conf
96 fi
97
98 # If old file exists, whine until they fix it.
99 if [ -f /etc/sysconfig ]; then
100         echo "Warning: /etc/sysconfig has been replaced by /etc/rc.conf."
101         echo "You should switch to /etc/rc.conf ASAP to eliminate this warning."
102 fi
103
104 adjkerntz -i
105
106 clean_var() {
107         if [ ! -f /var/run/clean_var ]; then
108                 rm -rf /var/run/*
109                 rm -f /var/spool/lock/*
110                 rm -rf /var/spool/uucp/.Temp/*
111                 # Keep a copy of the boot messages around
112                 dmesg >/var/run/dmesg.boot
113                 # And an initial utmp file
114                 (cd /var/run && cp /dev/null utmp && chmod 644 utmp; )
115                 >/var/run/clean_var
116         fi
117 }
118
119 if [ -d /var/run -a -d /var/spool/lock -a -d /var/spool/uucp/.Temp ]; then
120         # network_pass1() *may* end up writing stuff to /var - we don't want to
121         # remove it immediately afterwards - *nor* to we want to fail to clean
122         # an nfs-mounted /var.
123         clean_var
124 fi
125
126 # Add additional swapfile, if configured.
127 if [ "x$swapfile" != "xNO" -a -w "$swapfile" -a -b /dev/vn0b ]; then
128         echo "Adding $swapfile as additional swap."
129         vnconfig /dev/vn0b $swapfile && swapon /dev/vn0b
130 fi
131
132 # configure serial devices
133 if [ -f /etc/rc.serial ]; then
134         . /etc/rc.serial
135 fi
136
137 # start up PC-card configuration
138 if [ -f /etc/rc.pccard ]; then
139         . /etc/rc.pccard
140 fi
141
142 # start up the initial network configuration.
143 if [ -f /etc/rc.network ]; then
144         . /etc/rc.network       # We only need to do this once.
145         network_pass1
146 fi
147
148 echo -n "Mounting NFS file systems"
149 mount -a -t nfs
150 echo .
151
152 # Whack the pty perms back into shape.
153 chmod 666 /dev/tty[pqrsPQRS]*
154
155 # clean up left-over files
156 clean_var                       # If it hasn't already been done
157 rm /var/run/clean_var
158
159 #
160 # Clearing /tmp at boot-time seems to have a long tradition.  It doesn't
161 # help in any way for long-living systems, and it might accidentally
162 # clobber files you would rather like to have preserved after a crash
163 # (if not using mfs /tmp anyway).
164 #
165 # See also the example of another cleanup policy in /etc/periodic/daily.
166 #
167 if [ "X${clear_tmp_enable}" = X"YES" ]; then
168         echo clearing /tmp
169
170         # prune quickly with one rm, then use find to clean up /tmp/[lq]*
171         # (not needed with mfs /tmp, but doesn't hurt there...)
172         (cd /tmp && rm -rf [a-km-pr-zA-Z]* &&
173                 find -d . ! -name . ! -name lost+found ! -name quotas -exec rm -rf -- {} \;)
174
175 fi
176
177 # Remove X lock files, since they will prevent you from restarting X11 
178 # after a system crash.
179 rm -f /tmp/.X*-lock /tmp/.X11-unix/*
180
181 # snapshot any kernel -c changes back to disk
182 echo 'recording kernel -c changes'
183 dset -q
184
185 echo -n 'additional daemons:'
186 # start system logging and name service (named needs to start before syslogd
187 # if you don't have a /etc/resolv.conf)
188 #
189 if [ "X${syslogd_enable}" = X"YES" ]; then
190         # Transitional symlink (for the next couple of years :) until all
191         # binaries had a chance to move towards /var/run/log.
192         if [ ! -h /dev/log ] ; then
193                 # might complain for r/o root f/s
194                 ln -sf /var/run/log /dev/log
195         fi
196
197         rm -f /var/run/log
198         echo -n ' syslogd';             syslogd ${syslogd_flags}
199 fi
200 echo '.'
201
202 # enable dumpdev so that savecore can see it
203 # /var/crash should be a directory or a symbolic link
204 # to the crash directory if core dumps are to be saved.
205 if [ "X${dumpdev}" != X"NO" -a -e ${dumpdev} -a -d /var/crash ]; then
206         dumpon ${dumpdev}
207         echo -n checking for core dump...
208         savecore /var/crash
209 fi
210
211 if [ -n "$network_pass1_done" ]; then
212         network_pass2
213 fi
214
215 # Check the quotas (must be after ypbind if using NIS)
216 if [ "X${check_quotas}" = X"YES" ]; then
217         echo -n 'checking quotas:'
218         quotacheck -a
219         echo ' done.'
220         quotaon -a
221 fi
222
223 if [ -n "$network_pass2_done" ]; then
224         network_pass3
225 fi
226
227
228 # build ps databases
229 kvm_mkdb 
230 dev_mkdb
231
232 # check the password temp/lock file
233 if [ -f /etc/ptmp ]
234 then
235         logger -s -p auth.err \
236         "password file may be incorrect -- /etc/ptmp exists"
237 fi
238
239 if [ "X${accounting_enable}" = X"YES" -a -d /var/account ]; then
240         echo 'turning on accounting'
241         if [ ! -e /var/account/acct ]; then
242                 touch /var/account/acct
243         fi
244         accton /var/account/acct
245 fi
246
247 # Make shared lib searching a little faster.  Leave /usr/lib first if you
248 # add your own entries or you may come to grief.
249 if [ -x /sbin/ldconfig ]; then
250         if [ X"`/usr/bin/objformat`" = X"elf" ]; then
251                 _LDC=/usr/lib
252                 for i in $ldconfig_paths; do
253                         if test -d $i; then
254                                 _LDC="${_LDC} $i"
255                         fi
256                 done
257                 echo 'setting ELF ldconfig path:' ${_LDC}
258                 ldconfig -elf ${_LDC}
259         fi
260
261         # Legacy aout support for i386 only
262         if [ X"`sysctl -n hw.machine`" = X"i386" ]; then
263                 # Default the a.out ldconfig path, in case the system's
264                 # /etc/rc.conf hasn't been updated.
265                 : ${ldconfig_paths_aout=${ldconfig_paths}}
266                 _LDC=/usr/lib/aout
267                 for i in $ldconfig_paths_aout; do
268                         if test -d $i; then
269                                 _LDC="${_LDC} $i"
270                         fi
271                 done
272                 echo 'setting a.out ldconfig path:' ${_LDC}
273                 ldconfig -aout ${_LDC}
274         fi
275 fi
276
277 # Now start up miscellaneous daemons that don't belong anywhere else
278 #
279 echo -n starting standard daemons:
280 if [ "X${inetd_enable}" != X"NO" ]; then
281         echo -n ' inetd';       inetd ${inetd_flags}
282 fi
283
284 if [ "X${cron_enable}" != X"NO" ]; then
285         echo -n ' cron';        cron
286 fi
287
288 if [ "X${lpd_enable}" = X"YES" ]; then
289         echo -n ' printer';             lpd ${lpd_flags}
290 fi
291
292 if [ "X${sendmail_enable}" = X"YES" -a -r /etc/sendmail.cf ]; then
293         echo -n ' sendmail';    /usr/sbin/sendmail ${sendmail_flags}
294 fi
295
296 if [ "X${usbd_enable}" = X"YES" ]; then
297         echo -n ' usbd';        /usr/sbin/usbd ${usbd_flags}
298 fi
299
300 echo '.'
301
302 # configure implementation specific stuff
303 arch=`uname -m`
304 if [ -f /etc/rc.${arch} ]; then
305         . /etc/rc.${arch}
306 fi
307
308 # Recover vi editor files.
309 vibackup=`echo /var/tmp/vi.recover/vi.*`
310 if [ "$vibackup" != '/var/tmp/vi.recover/vi.*' ]; then
311         echo 'Recovering vi editor sessions'
312         for i in $vibackup; do
313                 # Only test files that are readable.
314                 if test ! -r $i; then
315                         continue
316                 fi
317
318                 # Unmodified nvi editor backup files either have the
319                 # execute bit set or are zero length.  Delete them.
320                 if test -x $i -o ! -s $i; then
321                         rm -f $i
322                 fi
323         done
324
325         # It is possible to get incomplete recovery files, if the editor
326         # crashes at the right time.
327         virecovery=`echo /var/tmp/vi.recover/recover.*`
328         if [ "$virecovery" != "/var/tmp/vi.recover/recover.*" ]; then
329                 for i in $virecovery; do
330                         # Only test files that are readable.
331                         if test ! -r $i; then
332                                 continue
333                         fi
334
335                         # Delete any recovery files that are zero length,
336                         # corrupted, or that have no corresponding backup file.
337                         # Else send mail to the user.
338                         recfile=`awk '/^X-vi-recover-path:/{print $2}' < $i`
339                         if test -n "$recfile" -a -s "$recfile"; then
340                                 sendmail -t < $i
341                         else
342                                 rm -f $i
343                         fi
344                 done
345         fi
346 fi
347
348 # make a bounds file for msgs(1) if there isn't one already
349 if [ ! -f /var/msgs/bounds ]; then
350         echo 0 > /var/msgs/bounds
351 fi
352
353 # for each valid dir in $local_startup, search for init scripts matching *.sh
354 if [ "X${local_startup}" != X"NO" ]; then
355         echo -n 'Local package initialization:'
356         for dir in ${local_startup}; do
357                 [ -d ${dir} ] && for script in ${dir}/*.sh; do
358                         [ -x ${script} ] && \
359                                 (trap 'exit 1' 2 ; ${script} start ; echo -n)
360                 done
361         done
362         echo .
363 fi
364
365 if [ "X${update_motd}" != X"NO" ]; then
366         T=/tmp/_motd
367         rm -f $T
368         uname -v | sed -e 's,^\([^#]*\) #\(.* [1-2][0-9][0-9][0-9]\).*/\([^\]*\) $,\1 (\3) #\2,' > $T
369         awk '{if (NR == 1) {if ($1 == "FreeBSD") {next} else {print "\n"$0}} else {print}}' < /etc/motd >> $T
370         cp $T /etc/motd
371         chmod 644 /etc/motd
372         rm -f $T
373 fi
374
375 # Run rc.devfs if present to customify devfs
376 [ -f /etc/rc.devfs ] && sh /etc/rc.devfs
377
378 # Do traditional (but rather obsolete) rc.local file if it exists.  If you
379 # use this file and want to make it programmatic, source /etc/rc.conf in
380 # /etc/rc.local and add your custom variables to /etc/rc.conf.local, as
381 # shown below.  Please do not put local extensions into /etc/rc itself. 
382 # Use /etc/rc.local
383 #
384 # ---- rc.local  ----
385 #     if [ -f /etc/rc.conf ]; then
386 #             . /etc/rc.conf
387 #     fi
388 #
389 #     ... additional startup conditionals ...
390 # ---- rc.local  ----
391 #
392
393 if [ -f /etc/rc.local ]; then
394     echo -n 'starting local daemons:'
395     sh /etc/rc.local
396     echo '.'
397 fi
398
399 # Raise kernel security level.  This should be done only after `fsck' has
400 # repaired local file systems if you want the securelevel to be greater than 1.
401 if [ "X${kern_securelevel_enable}" = X"YES" -a "${kern_securelevel}" -ge 0 ]; 
402 then
403         echo 'Raising kernel security level'
404         sysctl -w kern.securelevel=${kern_securelevel}
405 fi
406
407 date
408 exit 0