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
42 elif [ -r /etc/rc.conf ]; then
46 # Configure ccd devices.
48 if [ -r /etc/ccd.conf ]; then
52 case ${start_vinum} in
62 echo Automatic boot in progress...
72 echo "reboot failed... help!"
76 echo "Automatic file system check failed... help!"
80 echo "Reboot interrupted"
84 # interrupt before catcher installed
88 echo "Unknown error in reboot"
94 echo Skipping disk checks ...
99 trap "echo 'Reboot interrupted'; exit 1" 3
101 # root normally must be read/write, but if this is a BOOTP NFS
102 # diskless boot it does not have to be.
104 case ${root_rw_mount} in
108 if ! mount -u -o rw / ; then
109 echo "Mounting root filesystem rw failed, startup aborted"
115 umount -a >/dev/null 2>&1
117 # Mount everything except nfs filesystems.
124 echo "Mounting /etc/fstab filesystems failed, startup aborted"
129 # Run custom disk mounting function here
131 if [ -n "${diskless_mount}" -a -r "${diskless_mount}" ]; then
135 # Recover some entropy so the rebooting /dev/random can reseed
137 case ${entropy_file} in
141 if [ -f ${entropy_file} -a -r ${entropy_file} ]; then
142 echo "Reading entropy file"
143 cat ${entropy_file} > /dev/random
144 rm -f ${entropy_file}
152 if [ ! -f /var/run/clean_var ]; then
154 find /var/spool/lock ! -type d -delete
155 rm -rf /var/spool/uucp/.Temp/*
156 # Keep a copy of the boot messages around
157 dmesg >/var/run/dmesg.boot
158 # And an initial utmp file
159 (cd /var/run && cp /dev/null utmp && chmod 644 utmp;)
164 if [ -d /var/run -a -d /var/spool/lock -a -d /var/spool/uucp/.Temp ]; then
165 # network_pass1() *may* end up writing stuff to /var - we don't want to
166 # remove it immediately afterwards - *nor* to we want to fail to clean
167 # an nfs-mounted /var.
171 # Add additional swapfile, if configured.
177 if [ -w "${swapfile}" -a -c /dev/vn0b ]; then
178 echo "Adding ${swapfile} as additional swap."
179 vnconfig /dev/vn0b ${swapfile} && swapon /dev/vn0b
184 # Set sysctl variables as early as we can
186 if [ -r /etc/rc.sysctl ]; then
190 # Configure serial devices
192 if [ -r /etc/rc.serial ]; then
196 # Start up PC-card configuration
198 if [ -r /etc/rc.pccard ]; then
202 # Start up the initial network configuration.
204 if [ -r /etc/rc.network ]; then
205 . /etc/rc.network # We only need to do this once.
209 case ${ipv6_enable} in
211 if [ -r /etc/rc.network6 ]; then
212 . /etc/rc.network6 # We only need to do this once also.
218 # Mount NFS filesystems if present in /etc/fstab
219 case "`mount -d -a -t nfs`" in
221 echo -n "Mounting NFS file systems"
227 # Whack the pty perms back into shape.
229 chflags 0 /dev/tty[pqrsPQRS]*
230 chmod 666 /dev/tty[pqrsPQRS]*
231 chown root:wheel /dev/tty[pqrsPQRS]*
233 # Clean up left-over files
235 clean_var # If it hasn't already been done
236 rm /var/run/clean_var
238 # Clearing /tmp at boot-time seems to have a long tradition. It doesn't
239 # help in any way for long-living systems, and it might accidentally
240 # clobber files you would rather like to have preserved after a crash
241 # (if not using mfs /tmp anyway).
243 # See also the example of another cleanup policy in /etc/periodic/daily.
245 case ${clear_tmp_enable} in
248 # prune quickly with one rm, then use find to clean up /tmp/[lq]*
249 # (not needed with mfs /tmp, but doesn't hurt there...)
250 (cd /tmp && rm -rf [a-km-pr-zA-Z]* &&
251 find -d . ! -name . ! -name lost+found ! -name quota.user \
252 ! -name quota.group -exec rm -rf -- {} \;)
256 # Remove X lock files, since they will prevent you from restarting X11
257 # after a system crash.
259 rm -f /tmp/.X*-lock /tmp/.X11-unix/*
261 # Snapshot any kernel -c changes back to disk here <someday>.
262 # This has changed with ELF and /kernel.config.
264 echo -n 'additional daemons:'
266 # Start system logging and name service. Named needs to start before syslogd
267 # if you don't have a /etc/resolv.conf.
269 case ${syslogd_enable} in
271 # Transitional symlink (for the next couple of years :) until all
272 # binaries have had a chance to move towards /var/run/log.
273 if [ ! -h /dev/log ]; then
274 # might complain for r/o root f/s
275 ln -sf /var/run/log /dev/log
279 echo -n ' syslogd'; syslogd ${syslogd_flags}
285 # Enable dumpdev so that savecore can see it.
286 # /var/crash should be a directory or a symbolic link
287 # to the crash directory if core dumps are to be saved.
293 if [ -e "${dumpdev}" -a -d /var/crash ]; then
295 echo -n checking for core dump...
301 if [ -n "${network_pass1_done}" ]; then
305 # Enable/Check the quotas (must be after ypbind if using NIS)
307 case ${enable_quotas} in
309 case ${check_quotas} in
311 echo -n 'checking quotas:'
317 echo -n 'enabling quotas:'
323 if [ -n "${network_pass2_done}" ]; then
331 # Check the password temp/lock file
333 if [ -e /etc/ptmp ]; then
334 logger -s -p auth.err \
335 "password file may be incorrect -- /etc/ptmp exists"
338 case ${accounting_enable} in
340 if [ -d /var/account ]; then
341 echo 'turning on accounting'
342 if [ ! -e /var/account/acct ]; then
343 touch /var/account/acct
345 accton /var/account/acct
350 # Make shared lib searching a little faster. Leave /usr/lib first if you
351 # add your own entries or you may come to grief.
353 if [ -x /sbin/ldconfig ]; then
354 case `/usr/bin/objformat` in
357 for i in ${ldconfig_paths}; do
358 if [ -d "${i}" ]; then
362 echo 'setting ELF ldconfig path:' ${_LDC}
363 ldconfig -elf ${_LDC}
367 # Legacy aout support for i386 only
368 case `sysctl -n hw.machine` in
370 # Default the a.out ldconfig path.
371 : ${ldconfig_paths_aout=${ldconfig_paths}}
373 for i in ${ldconfig_paths_aout}; do
374 if [ -d "${i}" ]; then
378 echo 'setting a.out ldconfig path:' ${_LDC}
379 ldconfig -aout ${_LDC}
384 # Now start up miscellaneous daemons that don't belong anywhere else
386 echo -n starting standard daemons:
387 case ${inetd_enable} in
391 echo -n ' inetd'; inetd ${inetd_flags}
395 case ${cron_enable} in
399 echo -n ' cron'; cron
403 case ${lpd_enable} in
405 echo -n ' printer'; ${lpd_program:-/usr/sbin/lpd} ${lpd_flags}
409 case ${sendmail_enable} in
411 if [ -r /etc/mail/sendmail.cf ]; then
412 echo -n ' sendmail'; /usr/sbin/sendmail ${sendmail_flags}
417 case ${sshd_enable} in
419 if [ -x ${sshd_program:-/usr/sbin/sshd} ]; then
421 ${sshd_program:-/usr/sbin/sshd} ${sshd_flags}
426 case ${usbd_enable} in
428 echo -n ' usbd'; /usr/sbin/usbd ${usbd_flags}
434 # Recover vi editor files.
435 find /var/tmp/vi.recover ! -type f -a ! -type d -delete
436 vibackup=`echo /var/tmp/vi.recover/vi.*`
437 if [ "${vibackup}" != '/var/tmp/vi.recover/vi.*' ]; then
438 echo 'Recovering vi editor sessions'
439 for i in /var/tmp/vi.recover/vi.*; do
440 # Only test files that are readable.
441 if [ ! -r "${i}" ]; then
445 # Unmodified nvi editor backup files either have the
446 # execute bit set or are zero length. Delete them.
447 if [ -x "${i}" -o ! -s "${i}" ]; then
452 # It is possible to get incomplete recovery files, if the editor
453 # crashes at the right time.
454 virecovery=`echo /var/tmp/vi.recover/recover.*`
455 if [ "${virecovery}" != "/var/tmp/vi.recover/recover.*" ]; then
456 for i in /var/tmp/vi.recover/recover.*; do
457 # Only test files that are readable.
458 if [ ! -r "${i}" ]; then
462 # Delete any recovery files that are zero length,
463 # corrupted, or that have no corresponding backup file.
464 # Else send mail to the user.
465 recfile=`awk '/^X-vi-recover-path:/{print $2}' < "${i}"`
466 if [ -n "${recfile}" -a -s "${recfile}" ]; then
475 # Make a bounds file for msgs(1) if there isn't one already
476 # "Delete important files with symlink" security hole?
478 if [ -d /var/msgs -a ! -f /var/msgs/bounds ]; then
479 echo 0 > /var/msgs/bounds
482 case ${update_motd} in
486 if T=`mktemp /tmp/_motd.XXXXXX`; then
487 uname -v | sed -e 's,^\([^#]*\) #\(.* [1-2][0-9][0-9][0-9]\).*/\([^\]*\) $,\1 (\3) #\2,' > ${T}
488 awk '{if (NR == 1) {if ($1 == "FreeBSD") {next} else {print "\n"$0}} else {print}}' < /etc/motd >> ${T}
489 cmp -s ${T} /etc/motd || {
498 # Configure implementation specific stuff
501 if [ -r /etc/rc.${arch} ]; then
505 # Run rc.devfs if readable to customize devfs
507 if [ -r /etc/rc.devfs ]; then
511 # Do traditional (but rather obsolete) rc.local file if it exists. If you
512 # use this file and want to make it programmatic, source /etc/defaults/rc.conf
513 # in /etc/rc.local and add your custom variables to /etc/rc.conf, as
514 # shown below. Please do not put local extensions into /etc/rc itself.
518 # if [ -r /etc/defaults/rc.conf ]; then
519 # . /etc/defaults/rc.conf
521 # elif [ -r /etc/rc.conf ]; then
525 # ... additional startup conditionals ...
528 if [ -r /etc/rc.local ]; then
529 echo -n 'starting local daemons:'
534 # For each valid dir in $local_startup, search for init scripts matching *.sh
536 case ${local_startup} in
540 echo -n 'Local package initialization:'
541 for dir in ${local_startup}; do
542 if [ -d "${dir}" ]; then
543 for script in ${dir}/*.sh; do
544 if [ -x "${script}" ]; then
556 if [ -n "${network_pass3_done}" ]; then
560 # Raise kernel security level. This should be done only after `fsck' has
561 # repaired local file systems if you want the securelevel to be greater than 1.
563 case ${kern_securelevel_enable} in
565 if [ "${kern_securelevel}" -ge 0 ]; then
566 echo 'Raising kernel security level'
567 sysctl -w kern.securelevel=${kern_securelevel}