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 of the user-configurable behavior is no longer in
11 # this file, but rather in /etc/defaults/rc.conf. Please check that file
12 # first before contemplating any changes here. If you do need to change
13 # this file for some reason, we would like to know about it.
17 # Set shell to ignore SIGINT (2), but not children;
18 # shell catches SIGQUIT (3) and returns to single user after fsck.
21 trap : 3 # shouldn't be needed
24 PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin
27 # BOOTP diskless boot. We have to run the rc file early in order to
28 # retarget various config files.
30 if [ -r /etc/rc.diskless1 ]; then
31 dlv=`/sbin/sysctl -n vfs.nfs.diskless_valid 2> /dev/null`
32 if [ ${dlv:=0} != 0 ]; then
37 # If there is a global system configuration file, suck it in.
39 if [ -r /etc/defaults/rc.conf ]; then
40 . /etc/defaults/rc.conf
41 elif [ -r /etc/rc.conf ]; then
45 # Configure ccd devices.
47 if [ -r /etc/ccd.conf ]; then
51 case ${start_vinum} in
61 echo Automatic reboot in progress...
71 echo "reboot failed... help!"
75 echo "Automatic file system check failed... help!"
79 echo "Reboot interrupted"
83 # interrupt before catcher installed
87 echo "Unknown error in reboot"
93 echo Skipping disk checks ...
98 trap "echo 'Reboot interrupted'; exit 1" 3
100 # root normally must be read/write, but if this is a BOOTP NFS
101 # diskless boot it does not have to be.
103 case ${root_rw_mount} in
107 if ! mount -u -o rw / ; then
108 echo "Mounting root filesystem rw failed, startup aborted"
114 umount -a >/dev/null 2>&1
116 # Where/how would this get set?
118 case ${early_nfs_mounts} in
131 echo "Mounting /etc/fstab filesystems failed, startup aborted"
136 # Run custom disk mounting function here
138 if [ -n "${diskless_mount}" -a -r "${diskless_mount}" ]; then
145 if [ ! -f /var/run/clean_var ]; then
147 rm -f /var/spool/lock/*
148 rm -rf /var/spool/uucp/.Temp/*
149 # Keep a copy of the boot messages around
150 dmesg >/var/run/dmesg.boot
151 # And an initial utmp file
152 (cd /var/run && cp /dev/null utmp && chmod 644 utmp;)
157 if [ -d /var/run -a -d /var/spool/lock -a -d /var/spool/uucp/.Temp ]; then
158 # network_pass1() *may* end up writing stuff to /var - we don't want to
159 # remove it immediately afterwards - *nor* to we want to fail to clean
160 # an nfs-mounted /var.
164 # Add additional swapfile, if configured.
170 if [ -w "${swapfile}" -a -b /dev/vn0b ]; then
171 echo "Adding ${swapfile} as additional swap."
172 vnconfig /dev/vn0b ${swapfile} && swapon /dev/vn0b
177 # Set sysctl variables as early as we can
179 if [ -r /etc/rc.sysctl ]; then
183 # Configure serial devices
185 if [ -r /etc/rc.serial ]; then
189 # Start up PC-card configuration
191 if [ -r /etc/rc.pccard ]; then
195 # Start up the initial network configuration.
197 if [ -r /etc/rc.network ]; then
198 . /etc/rc.network # We only need to do this once.
202 # Retest for early_nfs here?
204 echo -n "Mounting NFS file systems"
208 # Whack the pty perms back into shape.
210 chflags 0 /dev/tty[pqrsPQRS]*
211 chmod 666 /dev/tty[pqrsPQRS]*
212 chown root:wheel /dev/tty[pqrsPQRS]*
214 # Clean up left-over files
216 clean_var # If it hasn't already been done
217 rm /var/run/clean_var
219 # Clearing /tmp at boot-time seems to have a long tradition. It doesn't
220 # help in any way for long-living systems, and it might accidentally
221 # clobber files you would rather like to have preserved after a crash
222 # (if not using mfs /tmp anyway).
224 # See also the example of another cleanup policy in /etc/periodic/daily.
226 case ${clear_tmp_enable} in
229 # prune quickly with one rm, then use find to clean up /tmp/[lq]*
230 # (not needed with mfs /tmp, but doesn't hurt there...)
231 (cd /tmp && rm -rf [a-km-pr-zA-Z]* &&
232 find -d . ! -name . ! -name lost+found ! -name quota.user \
233 ! -name quota.group -exec rm -rf -- {} \;)
237 # Remove X lock files, since they will prevent you from restarting X11
238 # after a system crash.
240 rm -f /tmp/.X*-lock /tmp/.X11-unix/*
242 # Snapshot any kernel -c changes back to disk here <someday>.
243 # This has changed with ELF and /kernel.config.
245 echo -n 'additional daemons:'
247 # Start system logging and name service. Named needs to start before syslogd
248 # if you don't have a /etc/resolv.conf.
250 case ${syslogd_enable} in
252 # Transitional symlink (for the next couple of years :) until all
253 # binaries have had a chance to move towards /var/run/log.
254 if [ ! -h /dev/log ]; then
255 # might complain for r/o root f/s
256 ln -sf /var/run/log /dev/log
260 echo -n ' syslogd'; syslogd ${syslogd_flags}
266 # Enable dumpdev so that savecore can see it.
267 # /var/crash should be a directory or a symbolic link
268 # to the crash directory if core dumps are to be saved.
274 if [ -e "${dumpdev}" -a -d /var/crash ]; then
276 echo -n checking for core dump...
282 if [ -n "${network_pass1_done}" ]; then
286 # Enable/Check the quotas (must be after ypbind if using NIS)
288 case ${enable_quotas} in
290 case ${check_quotas} in
292 echo -n 'checking quotas:'
298 echo -n 'enabling quotas:'
304 if [ -n "${network_pass2_done}" ]; then
313 # Check the password temp/lock file
315 if [ -e /etc/ptmp ]; then
316 logger -s -p auth.err \
317 "password file may be incorrect -- /etc/ptmp exists"
320 case ${accounting_enable} in
322 if [ -d /var/account ]; then
323 echo 'turning on accounting'
324 if [ ! -e /var/account/acct ]; then
325 touch /var/account/acct
327 accton /var/account/acct
332 # Make shared lib searching a little faster. Leave /usr/lib first if you
333 # add your own entries or you may come to grief.
335 if [ -x /sbin/ldconfig ]; then
336 case `/usr/bin/objformat` in
339 for i in ${ldconfig_paths}; do
340 if [ -d "${i}" ]; then
344 echo 'setting ELF ldconfig path:' ${_LDC}
345 ldconfig -elf ${_LDC}
349 # Legacy aout support for i386 only
350 case `sysctl -n hw.machine` in
352 # Default the a.out ldconfig path.
353 : ${ldconfig_paths_aout=${ldconfig_paths}}
355 for i in ${ldconfig_paths_aout}; do
356 if [ -d "${i}" ]; then
360 echo 'setting a.out ldconfig path:' ${_LDC}
361 ldconfig -aout ${_LDC}
366 # Now start up miscellaneous daemons that don't belong anywhere else
368 echo -n starting standard daemons:
369 case ${inetd_enable} in
373 echo -n ' inetd'; inetd ${inetd_flags}
377 case ${cron_enable} in
381 echo -n ' cron'; cron
385 case ${lpd_enable} in
387 echo -n ' printer'; ${lpd_program:-/usr/sbin/lpd} ${lpd_flags}
391 case ${sendmail_enable} in
393 if [ -r /etc/sendmail.cf ]; then
394 echo -n ' sendmail'; /usr/sbin/sendmail ${sendmail_flags}
399 case ${usbd_enable} in
401 echo -n ' usbd'; /usr/sbin/usbd ${usbd_flags}
407 # Recover vi editor files.
408 find /var/tmp/vi.recover ! -type f -a ! -type d -delete
409 vibackup=`echo /var/tmp/vi.recover/vi.*`
410 if [ "${vibackup}" != '/var/tmp/vi.recover/vi.*' ]; then
411 echo 'Recovering vi editor sessions'
412 for i in ${vibackup}; do
413 # Only test files that are readable.
414 if [ ! -r "${i}" ]; then
418 # Unmodified nvi editor backup files either have the
419 # execute bit set or are zero length. Delete them.
420 if [ -x "${i}" -o ! -s "${i}" ]; then
425 # It is possible to get incomplete recovery files, if the editor
426 # crashes at the right time.
427 virecovery=`echo /var/tmp/vi.recover/recover.*`
428 if [ "${virecovery}" != "/var/tmp/vi.recover/recover.*" ]; then
429 for i in ${virecovery}; do
430 # Only test files that are readable.
431 if [ ! -r "${i}" ]; then
435 # Delete any recovery files that are zero length,
436 # corrupted, or that have no corresponding backup file.
437 # Else send mail to the user.
438 recfile=`awk '/^X-vi-recover-path:/{print $2}' < ${i}`
439 if [ -n "${recfile}" -a -s "${recfile}" ]; then
448 # Make a bounds file for msgs(1) if there isn't one already
449 # "Delete important files with symlink" security hole?
451 if [ -d /var/msgs -a ! -f /var/msgs/bounds ]; then
452 echo 0 > /var/msgs/bounds
455 case ${update_motd} in
459 if T=`mktemp /tmp/_motd.XXXXXX`; then
460 uname -v | sed -e 's,^\([^#]*\) #\(.* [1-2][0-9][0-9][0-9]\).*/\([^\]*\) $,\1 (\3) #\2,' > ${T}
461 awk '{if (NR == 1) {if ($1 == "FreeBSD") {next} else {print "\n"$0}} else {print}}' < /etc/motd >> ${T}
462 cmp -s ${T} /etc/motd || {
471 # Configure implementation specific stuff
474 if [ -r /etc/rc.${arch} ]; then
478 # Run rc.devfs if readable to customize devfs
480 if [ -r /etc/rc.devfs ]; then
484 # Do traditional (but rather obsolete) rc.local file if it exists. If you
485 # use this file and want to make it programmatic, source /etc/defaults/rc.conf
486 # in /etc/rc.local and add your custom variables to /etc/rc.conf, as
487 # shown below. Please do not put local extensions into /etc/rc itself.
491 # if [ -r /etc/defaults/rc.conf ]; then
492 # . /etc/defaults/rc.conf
495 # ... additional startup conditionals ...
498 if [ -r /etc/rc.local ]; then
499 echo -n 'starting local daemons:'
504 # For each valid dir in $local_startup, search for init scripts matching *.sh
506 case ${local_startup} in
510 echo -n 'Local package initialization:'
511 for dir in ${local_startup}; do
512 if [ -d "${dir}" ]; then
513 for script in ${dir}/*.sh; do
514 if [ -x "${script}" ]; then
526 # Raise kernel security level. This should be done only after `fsck' has
527 # repaired local file systems if you want the securelevel to be greater than 1.
529 case ${kern_securelevel_enable} in
531 if [ "${kern_securelevel}" -ge 0 ]; then
532 echo 'Raising kernel security level'
533 sysctl -w kern.securelevel=${kern_securelevel}