2 # $Id: rc,v 1.186 1999/04/02 07:15:43 grog Exp $
3 # From: @(#)rc 5.27 (Berkeley) 6/5/91
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.
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.
16 # Set shell to ignore SIGINT (2), but not children;
17 # shell catches SIGQUIT (3) and returns to single user after fsck.
19 trap : 3 # shouldn't be needed
22 PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin
25 # BOOTP diskless boot. We have to run the rc file early in order to
26 # retarget various config files.
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
35 # If there is a global system configuration file, suck it in.
37 if [ -f /etc/defaults/rc.conf ]; then
38 . /etc/defaults/rc.conf
39 elif [ -f /etc/rc.conf ]; then
43 # Configure ccd devices.
44 if [ -f /etc/ccd.conf ]; then
48 if [ X$start_vinum = XYES ]; then
50 elif [ -n "$vinum_drives" ]; then
51 vinum read $vinum_drives
56 if [ $1x = autobootx ]; then
57 echo Automatic reboot in progress...
67 echo "reboot failed... help!"
71 echo "Automatic file system check failed... help!"
75 echo "Reboot interrupted"
79 # interrupt before catcher installed
83 echo "Unknown error in reboot"
88 echo Skipping disk checks ...
92 trap "echo 'Reboot interrupted'; exit 1" 3
94 # root normally must be read/write, but if this is a BOOTP NFS
95 # diskless boot it does not have to be.
98 if [ "X$root_rw_mount" != "XNO" ]; then
103 echo "Filesystem mount failed, startup aborted"
107 umount -a >/dev/null 2>&1
109 if [ "X$early_nfs_mounts" != "XYES" ]; then
115 echo "Filesystem mount failed, startup aborted"
119 # Run custom disk mounting function here
122 if [ "X$diskless_mount" != "X" ]; then
123 if [ -f $diskless_mount ]; then
131 if [ ! -f /var/run/clean_var ]; then
133 rm -f /var/spool/lock/*
134 rm -rf /var/spool/uucp/.Temp/*
135 # Keep a copy of the boot messages around
136 dmesg >/var/run/dmesg.boot
137 # And an initial utmp file
138 (cd /var/run && cp /dev/null utmp && chmod 644 utmp; )
143 if [ -d /var/run -a -d /var/spool/lock -a -d /var/spool/uucp/.Temp ]; then
144 # network_pass1() *may* end up writing stuff to /var - we don't want to
145 # remove it immediately afterwards - *nor* to we want to fail to clean
146 # an nfs-mounted /var.
150 # Add additional swapfile, if configured.
151 if [ "x$swapfile" != "xNO" -a -w "$swapfile" -a -b /dev/vn0b ]; then
152 echo "Adding $swapfile as additional swap."
153 vnconfig /dev/vn0b $swapfile && swapon /dev/vn0b
156 # set sysctl variables early as we can
157 if [ -f /etc/rc.sysctl ]; then
161 # configure serial devices
162 if [ -f /etc/rc.serial ]; then
166 # start up PC-card configuration
167 if [ -f /etc/rc.pccard ]; then
171 # start up the initial network configuration.
172 if [ -f /etc/rc.network ]; then
173 . /etc/rc.network # We only need to do this once.
177 echo -n "Mounting NFS file systems"
181 # Whack the pty perms back into shape.
182 chmod 666 /dev/tty[pqrsPQRS]*
183 chown root:wheel /dev/tty[pqrsPQRS]*
185 # clean up left-over files
186 clean_var # If it hasn't already been done
187 rm /var/run/clean_var
190 # Clearing /tmp at boot-time seems to have a long tradition. It doesn't
191 # help in any way for long-living systems, and it might accidentally
192 # clobber files you would rather like to have preserved after a crash
193 # (if not using mfs /tmp anyway).
195 # See also the example of another cleanup policy in /etc/periodic/daily.
197 if [ "X${clear_tmp_enable}" = X"YES" ]; then
200 # prune quickly with one rm, then use find to clean up /tmp/[lq]*
201 # (not needed with mfs /tmp, but doesn't hurt there...)
202 (cd /tmp && rm -rf [a-km-pr-zA-Z]* &&
203 find -d . ! -name . ! -name lost+found ! -name quotas -exec rm -rf -- {} \;)
207 # Remove X lock files, since they will prevent you from restarting X11
208 # after a system crash.
209 rm -f /tmp/.X*-lock /tmp/.X11-unix/*
211 # snapshot any kernel -c changes back to disk here <someday>
212 # this has changed with ELF and /kernel.config.
214 echo -n 'additional daemons:'
215 # start system logging and name service (named needs to start before syslogd
216 # if you don't have a /etc/resolv.conf)
218 if [ "X${syslogd_enable}" = X"YES" ]; then
219 # Transitional symlink (for the next couple of years :) until all
220 # binaries had a chance to move towards /var/run/log.
221 if [ ! -h /dev/log ] ; then
222 # might complain for r/o root f/s
223 ln -sf /var/run/log /dev/log
227 echo -n ' syslogd'; syslogd ${syslogd_flags}
231 # enable dumpdev so that savecore can see it
232 # /var/crash should be a directory or a symbolic link
233 # to the crash directory if core dumps are to be saved.
234 if [ "X${dumpdev}" != X"NO" -a -e ${dumpdev} -a -d /var/crash ]; then
236 echo -n checking for core dump...
240 if [ -n "$network_pass1_done" ]; then
244 # Enable/Check the quotas (must be after ypbind if using NIS)
245 if [ "X${enable_quotas}" = X"YES" ]; then
247 # Only check quotas if they have been previously enabled, and requested
248 if [ "X${check_quotas}" = X"YES" ]; then
249 echo -n 'checking quotas:'
254 echo -n 'enabling quotas:'
259 if [ -n "$network_pass2_done" ]; then
268 # check the password temp/lock file
271 logger -s -p auth.err \
272 "password file may be incorrect -- /etc/ptmp exists"
275 if [ "X${accounting_enable}" = X"YES" -a -d /var/account ]; then
276 echo 'turning on accounting'
277 if [ ! -e /var/account/acct ]; then
278 touch /var/account/acct
280 accton /var/account/acct
283 # Make shared lib searching a little faster. Leave /usr/lib first if you
284 # add your own entries or you may come to grief.
285 if [ -x /sbin/ldconfig ]; then
286 if [ X"`/usr/bin/objformat`" = X"elf" ]; then
288 for i in $ldconfig_paths; do
293 echo 'setting ELF ldconfig path:' ${_LDC}
294 ldconfig -elf ${_LDC}
297 # Legacy aout support for i386 only
298 if [ X"`sysctl -n hw.machine`" = X"i386" ]; then
299 # Default the a.out ldconfig path.
300 : ${ldconfig_paths_aout=${ldconfig_paths}}
302 for i in $ldconfig_paths_aout; do
307 echo 'setting a.out ldconfig path:' ${_LDC}
308 ldconfig -aout ${_LDC}
312 # Now start up miscellaneous daemons that don't belong anywhere else
314 echo -n starting standard daemons:
315 if [ "X${inetd_enable}" != X"NO" ]; then
316 echo -n ' inetd'; inetd ${inetd_flags}
319 if [ "X${cron_enable}" != X"NO" ]; then
320 echo -n ' cron'; cron
323 if [ "X${lpd_enable}" = X"YES" ]; then
324 echo -n ' printer'; ${lpd_program} ${lpd_flags}
327 if [ "X${sendmail_enable}" = X"YES" -a -r /etc/sendmail.cf ]; then
328 echo -n ' sendmail'; /usr/sbin/sendmail ${sendmail_flags}
331 if [ "X${usbd_enable}" = X"YES" ]; then
332 echo -n ' usbd'; /usr/sbin/usbd ${usbd_flags}
337 # configure implementation specific stuff
339 if [ -f /etc/rc.${arch} ]; then
343 # Recover vi editor files.
344 vibackup=`echo /var/tmp/vi.recover/vi.*`
345 if [ "$vibackup" != '/var/tmp/vi.recover/vi.*' ]; then
346 echo 'Recovering vi editor sessions'
347 for i in $vibackup; do
348 # Only test files that are readable.
349 if test ! -r $i; then
353 # Unmodified nvi editor backup files either have the
354 # execute bit set or are zero length. Delete them.
355 if test -x $i -o ! -s $i; then
360 # It is possible to get incomplete recovery files, if the editor
361 # crashes at the right time.
362 virecovery=`echo /var/tmp/vi.recover/recover.*`
363 if [ "$virecovery" != "/var/tmp/vi.recover/recover.*" ]; then
364 for i in $virecovery; do
365 # Only test files that are readable.
366 if test ! -r $i; then
370 # Delete any recovery files that are zero length,
371 # corrupted, or that have no corresponding backup file.
372 # Else send mail to the user.
373 recfile=`awk '/^X-vi-recover-path:/{print $2}' < $i`
374 if test -n "$recfile" -a -s "$recfile"; then
383 # make a bounds file for msgs(1) if there isn't one already
384 if [ ! -f /var/msgs/bounds ]; then
385 echo 0 > /var/msgs/bounds
388 # for each valid dir in $local_startup, search for init scripts matching *.sh
389 if [ "X${local_startup}" != X"NO" ]; then
390 echo -n 'Local package initialization:'
391 for dir in ${local_startup}; do
392 [ -d ${dir} ] && for script in ${dir}/*.sh; do
393 [ -x ${script} ] && \
394 (set -T ; trap 'exit 1' 2 ; ${script} start)
400 if [ "X${update_motd}" != X"NO" ]; then
403 uname -v | sed -e 's,^\([^#]*\) #\(.* [1-2][0-9][0-9][0-9]\).*/\([^\]*\) $,\1 (\3) #\2,' > $T
404 awk '{if (NR == 1) {if ($1 == "FreeBSD") {next} else {print "\n"$0}} else {print}}' < /etc/motd >> $T
410 # Run rc.devfs if present to customify devfs
411 [ -f /etc/rc.devfs ] && sh /etc/rc.devfs
413 # Do traditional (but rather obsolete) rc.local file if it exists. If you
414 # use this file and want to make it programmatic, source /etc/defaults/rc.conf
415 # in /etc/rc.local and add your custom variables to /etc/rc.conf, as
416 # shown below. Please do not put local extensions into /etc/rc itself.
420 # if [ -f /etc/defaults/rc.conf ]; then
421 # . /etc/defaults/rc.conf
424 # ... additional startup conditionals ...
427 if [ -f /etc/rc.local ]; then
428 echo -n 'starting local daemons:'
433 # Raise kernel security level. This should be done only after `fsck' has
434 # repaired local file systems if you want the securelevel to be greater than 1.
435 if [ "X${kern_securelevel_enable}" = X"YES" -a "${kern_securelevel}" -ge 0 ];
437 echo 'Raising kernel security level'
438 sysctl -w kern.securelevel=${kern_securelevel}