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