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 # Mount everything except nfs filesystems.
123 echo "Mounting /etc/fstab filesystems failed, startup aborted"
128 # Run custom disk mounting function here
130 if [ -n "${diskless_mount}" -a -r "${diskless_mount}" ]; then
137 if [ ! -f /var/run/clean_var ]; then
139 rm -f /var/spool/lock/*
140 rm -rf /var/spool/uucp/.Temp/*
141 # Keep a copy of the boot messages around
142 dmesg >/var/run/dmesg.boot
143 # And an initial utmp file
144 (cd /var/run && cp /dev/null utmp && chmod 644 utmp;)
149 if [ -d /var/run -a -d /var/spool/lock -a -d /var/spool/uucp/.Temp ]; then
150 # network_pass1() *may* end up writing stuff to /var - we don't want to
151 # remove it immediately afterwards - *nor* to we want to fail to clean
152 # an nfs-mounted /var.
156 # Add additional swapfile, if configured.
162 if [ -w "${swapfile}" -a -b /dev/vn0b ]; then
163 echo "Adding ${swapfile} as additional swap."
164 vnconfig /dev/vn0b ${swapfile} && swapon /dev/vn0b
169 # Set sysctl variables as early as we can
171 if [ -r /etc/rc.sysctl ]; then
175 # Configure serial devices
177 if [ -r /etc/rc.serial ]; then
181 # Start up PC-card configuration
183 if [ -r /etc/rc.pccard ]; then
187 # Start up the initial network configuration.
189 if [ -r /etc/rc.network ]; then
190 . /etc/rc.network # We only need to do this once.
194 # Mount NFS filesystems.
195 echo -n "Mounting NFS file systems"
199 # Whack the pty perms back into shape.
201 chflags 0 /dev/tty[pqrsPQRS]*
202 chmod 666 /dev/tty[pqrsPQRS]*
203 chown root:wheel /dev/tty[pqrsPQRS]*
205 # Clean up left-over files
207 clean_var # If it hasn't already been done
208 rm /var/run/clean_var
210 # Clearing /tmp at boot-time seems to have a long tradition. It doesn't
211 # help in any way for long-living systems, and it might accidentally
212 # clobber files you would rather like to have preserved after a crash
213 # (if not using mfs /tmp anyway).
215 # See also the example of another cleanup policy in /etc/periodic/daily.
217 case ${clear_tmp_enable} in
220 # prune quickly with one rm, then use find to clean up /tmp/[lq]*
221 # (not needed with mfs /tmp, but doesn't hurt there...)
222 (cd /tmp && rm -rf [a-km-pr-zA-Z]* &&
223 find -d . ! -name . ! -name lost+found ! -name quota.user \
224 ! -name quota.group -exec rm -rf -- {} \;)
228 # Remove X lock files, since they will prevent you from restarting X11
229 # after a system crash.
231 rm -f /tmp/.X*-lock /tmp/.X11-unix/*
233 # Snapshot any kernel -c changes back to disk here <someday>.
234 # This has changed with ELF and /kernel.config.
236 echo -n 'additional daemons:'
238 # Start system logging and name service. Named needs to start before syslogd
239 # if you don't have a /etc/resolv.conf.
241 case ${syslogd_enable} in
243 # Transitional symlink (for the next couple of years :) until all
244 # binaries have had a chance to move towards /var/run/log.
245 if [ ! -h /dev/log ]; then
246 # might complain for r/o root f/s
247 ln -sf /var/run/log /dev/log
251 echo -n ' syslogd'; syslogd ${syslogd_flags}
257 # Enable dumpdev so that savecore can see it.
258 # /var/crash should be a directory or a symbolic link
259 # to the crash directory if core dumps are to be saved.
265 if [ -e "${dumpdev}" -a -d /var/crash ]; then
267 echo -n checking for core dump...
273 if [ -n "${network_pass1_done}" ]; then
277 # Enable/Check the quotas (must be after ypbind if using NIS)
279 case ${enable_quotas} in
281 case ${check_quotas} in
283 echo -n 'checking quotas:'
289 echo -n 'enabling quotas:'
295 if [ -n "${network_pass2_done}" ]; then
303 # Check the password temp/lock file
305 if [ -e /etc/ptmp ]; then
306 logger -s -p auth.err \
307 "password file may be incorrect -- /etc/ptmp exists"
310 case ${accounting_enable} in
312 if [ -d /var/account ]; then
313 echo 'turning on accounting'
314 if [ ! -e /var/account/acct ]; then
315 touch /var/account/acct
317 accton /var/account/acct
322 # Make shared lib searching a little faster. Leave /usr/lib first if you
323 # add your own entries or you may come to grief.
325 if [ -x /sbin/ldconfig ]; then
326 case `/usr/bin/objformat` in
329 for i in ${ldconfig_paths}; do
330 if [ -d "${i}" ]; then
334 echo 'setting ELF ldconfig path:' ${_LDC}
335 ldconfig -elf ${_LDC}
339 # Legacy aout support for i386 only
340 case `sysctl -n hw.machine` in
342 # Default the a.out ldconfig path.
343 : ${ldconfig_paths_aout=${ldconfig_paths}}
345 for i in ${ldconfig_paths_aout}; do
346 if [ -d "${i}" ]; then
350 echo 'setting a.out ldconfig path:' ${_LDC}
351 ldconfig -aout ${_LDC}
356 # Now start up miscellaneous daemons that don't belong anywhere else
358 echo -n starting standard daemons:
359 case ${inetd_enable} in
363 echo -n ' inetd'; inetd ${inetd_flags}
367 case ${cron_enable} in
371 echo -n ' cron'; cron
375 case ${lpd_enable} in
377 echo -n ' printer'; ${lpd_program:-/usr/sbin/lpd} ${lpd_flags}
381 case ${sendmail_enable} in
383 if [ -r /etc/mail/sendmail.cf ]; then
384 echo -n ' sendmail'; /usr/sbin/sendmail ${sendmail_flags}
389 case ${usbd_enable} in
391 echo -n ' usbd'; /usr/sbin/usbd ${usbd_flags}
397 # Recover vi editor files.
398 find /var/tmp/vi.recover ! -type f -a ! -type d -delete
399 vibackup=`echo /var/tmp/vi.recover/vi.*`
400 if [ "${vibackup}" != '/var/tmp/vi.recover/vi.*' ]; then
401 echo 'Recovering vi editor sessions'
402 for i in /var/tmp/vi.recover/vi.*; do
403 # Only test files that are readable.
404 if [ ! -r "${i}" ]; then
408 # Unmodified nvi editor backup files either have the
409 # execute bit set or are zero length. Delete them.
410 if [ -x "${i}" -o ! -s "${i}" ]; then
415 # It is possible to get incomplete recovery files, if the editor
416 # crashes at the right time.
417 virecovery=`echo /var/tmp/vi.recover/recover.*`
418 if [ "${virecovery}" != "/var/tmp/vi.recover/recover.*" ]; then
419 for i in /var/tmp/vi.recover/recover.*; do
420 # Only test files that are readable.
421 if [ ! -r "${i}" ]; then
425 # Delete any recovery files that are zero length,
426 # corrupted, or that have no corresponding backup file.
427 # Else send mail to the user.
428 recfile=`awk '/^X-vi-recover-path:/{print $2}' < "${i}"`
429 if [ -n "${recfile}" -a -s "${recfile}" ]; then
438 # Make a bounds file for msgs(1) if there isn't one already
439 # "Delete important files with symlink" security hole?
441 if [ -d /var/msgs -a ! -f /var/msgs/bounds ]; then
442 echo 0 > /var/msgs/bounds
445 case ${update_motd} in
449 if T=`mktemp /tmp/_motd.XXXXXX`; then
450 uname -v | sed -e 's,^\([^#]*\) #\(.* [1-2][0-9][0-9][0-9]\).*/\([^\]*\) $,\1 (\3) #\2,' > ${T}
451 awk '{if (NR == 1) {if ($1 == "FreeBSD") {next} else {print "\n"$0}} else {print}}' < /etc/motd >> ${T}
452 cmp -s ${T} /etc/motd || {
461 # Configure implementation specific stuff
464 if [ -r /etc/rc.${arch} ]; then
468 # Run rc.devfs if readable to customize devfs
470 if [ -r /etc/rc.devfs ]; then
474 # Do traditional (but rather obsolete) rc.local file if it exists. If you
475 # use this file and want to make it programmatic, source /etc/defaults/rc.conf
476 # in /etc/rc.local and add your custom variables to /etc/rc.conf, as
477 # shown below. Please do not put local extensions into /etc/rc itself.
481 # if [ -r /etc/defaults/rc.conf ]; then
482 # . /etc/defaults/rc.conf
485 # ... additional startup conditionals ...
488 if [ -r /etc/rc.local ]; then
489 echo -n 'starting local daemons:'
494 # For each valid dir in $local_startup, search for init scripts matching *.sh
496 case ${local_startup} in
500 echo -n 'Local package initialization:'
501 for dir in ${local_startup}; do
502 if [ -d "${dir}" ]; then
503 for script in ${dir}/*.sh; do
504 if [ -x "${script}" ]; then
516 if [ -n "${network_pass3_done}" ]; then
520 # Raise kernel security level. This should be done only after `fsck' has
521 # repaired local file systems if you want the securelevel to be greater than 1.
523 case ${kern_securelevel_enable} in
525 if [ "${kern_securelevel}" -ge 0 ]; then
526 echo 'Raising kernel security level'
527 sysctl -w kern.securelevel=${kern_securelevel}