rc revision 42741
140123Sdes#!/bin/sh 242741Sgrog# $Id: rc,v 1.166 1999/01/11 09:07:38 asami Exp $ 3709Swollman# From: @(#)rc 5.27 (Berkeley) 6/5/91 437Srgrimes 537Srgrimes# System startup script run by init on autoboot 637Srgrimes# or after single-user. 737Srgrimes# Output and error are redirected to console by init, 837Srgrimes# and the console is the controlling terminal. 937Srgrimes 108460Sjkh# Note that almost all the user-configurable behavior is no longer in 1125184Sjkh# this file, but rather in /etc/rc.conf. Please check this file 128460Sjkh# first before contemplating any changes here. 138460Sjkh 1437Srgrimesstty status '^T' 1537Srgrimes 1637Srgrimes# Set shell to ignore SIGINT (2), but not children; 1737Srgrimes# shell catches SIGQUIT (3) and returns to single user after fsck. 1837Srgrimestrap : 2 1937Srgrimestrap : 3 # shouldn't be needed 2037Srgrimes 2137SrgrimesHOME=/; export HOME 2220684SjoergPATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin 2337Srgrimesexport PATH 2437Srgrimes 2515568Sasami# Configure ccd devices. 2625184Sjkhif [ -f /etc/ccd.conf ]; then 2715568Sasami ccdconfig -C 2815568Sasamifi 2915568Sasami 3042741Sgrogif [ -n $vinum_slices ]; then 3142741Sgrog if [ -r /modules/vinum.ko ]; then # jkh paranoia 3242741Sgrog kldload vinum 3342741Sgrog vinum read $vinum_slices 3442741Sgrog else 3542741Sgrog echo "Can't find /modules/vinum.ko" 3642741Sgrog fi 3742741Sgrogfi 3842741Sgrog 393843Sdgswapon -a 403843Sdg 4125184Sjkhif [ $1x = autobootx ]; then 4237Srgrimes echo Automatic reboot in progress... 4337Srgrimes fsck -p 4437Srgrimes case $? in 4537Srgrimes 0) 4637Srgrimes ;; 4737Srgrimes 2) 4837Srgrimes exit 1 4937Srgrimes ;; 5037Srgrimes 4) 5137Srgrimes reboot 5237Srgrimes echo "reboot failed... help!" 5337Srgrimes exit 1 5437Srgrimes ;; 5537Srgrimes 8) 5637Srgrimes echo "Automatic file system check failed... help!" 5737Srgrimes exit 1 5837Srgrimes ;; 5937Srgrimes 12) 6037Srgrimes echo "Reboot interrupted" 6137Srgrimes exit 1 6237Srgrimes ;; 6337Srgrimes 130) 6437Srgrimes # interrupt before catcher installed 6537Srgrimes exit 1 6637Srgrimes ;; 6737Srgrimes *) 6837Srgrimes echo "Unknown error in reboot" 6937Srgrimes exit 1 7037Srgrimes ;; 7137Srgrimes esac 722164Sdgelse 732164Sdg echo Skipping disk checks ... 7437Srgrimesfi 7537Srgrimes 7637Srgrimestrap "echo 'Reboot interrupted'; exit 1" 3 7737Srgrimes 7842346Speter# root must be read/write for NFS diskless before proceeding any further. 793036Sdgmount -u -o rw / 808530Sdgif [ $? != 0 ]; then 818530Sdg echo "Filesystem mount failed, startup aborted" 828530Sdg exit 1 838530Sdgfi 841692Sphk 8537Srgrimesumount -a >/dev/null 2>&1 868530Sdg 8737Srgrimesmount -a -t nonfs 888530Sdgif [ $? != 0 ]; then 898530Sdg echo "Filesystem mount failed, startup aborted" 908530Sdg exit 1 918530Sdgfi 9237Srgrimes 9325184Sjkh# If there is a global system configuration file, suck it in. 9425184Sjkhif [ -f /etc/rc.conf ]; then 9539384Sbrian . /etc/rc.conf 9625184Sjkhfi 9725184Sjkh 9825184Sjkh# If old file exists, whine until they fix it. 9925184Sjkhif [ -f /etc/sysconfig ]; then 10025184Sjkh echo "Warning: /etc/sysconfig has been replaced by /etc/rc.conf." 10125184Sjkh echo "You should switch to /etc/rc.conf ASAP to eliminate this warning." 10225184Sjkhfi 10325184Sjkh 1044091Sacheadjkerntz -i 105872Sache 10638237Sbrianclean_var() { 10739384Sbrian if [ ! -f /var/run/clean_var ]; then 10839384Sbrian rm -rf /var/run/* 10939384Sbrian rm -f /var/spool/lock/* 11039384Sbrian rm -rf /var/spool/uucp/.Temp/* 11139384Sbrian # Keep a copy of the boot messages around 11239384Sbrian dmesg >/var/run/dmesg.boot 11339384Sbrian # And an initial utmp file 11439384Sbrian (cd /var/run && cp /dev/null utmp && chmod 644 utmp; ) 11539384Sbrian >/var/run/clean_var 11639384Sbrian fi 11738237Sbrian} 11826450Sache 11938237Sbrianif [ -d /var/run -a -d /var/spool/lock -a -d /var/spool/uucp/.Temp ]; then 12039384Sbrian # network_pass1() *may* end up writing stuff to /var - we don't want to 12139384Sbrian # remove it immediately afterwards - *nor* to we want to fail to clean 12239384Sbrian # an nfs-mounted /var. 12339384Sbrian clean_var 12438237Sbrianfi 12521197Sphk 12617767Sjkh# Add additional swapfile, if configured. 12719363Sjoergif [ "x$swapfile" != "xNO" -a -w "$swapfile" -a -b /dev/vn0b ]; then 12817767Sjkh echo "Adding $swapfile as additional swap." 12925184Sjkh vnconfig /dev/vn0b $swapfile && swapon /dev/vn0b 13017767Sjkhfi 13117767Sjkh 1321675Sache# configure serial devices 1337219Sjkhif [ -f /etc/rc.serial ]; then 1347293Sjkh . /etc/rc.serial 1351675Sachefi 1361675Sache 13714596Snate# start up PC-card configuration 13814624Snateif [ -f /etc/rc.pccard ]; then 13914624Snate . /etc/rc.pccard 14014596Snatefi 14114596Snate 14225184Sjkh# start up the initial network configuration. 14325184Sjkhif [ -f /etc/rc.network ]; then 14425184Sjkh . /etc/rc.network # We only need to do this once. 14525184Sjkh network_pass1 1467460Sjkhfi 1477460Sjkh 14838456Sphkecho -n "Mounting NFS file systems" 14929319Sbrianmount -a -t nfs 15038456Sphkecho . 1517487Srgrimes 1527487Srgrimes# Whack the pty perms back into shape. 15320828Sjoergchmod 666 /dev/tty[pqrsPQRS]* 1547487Srgrimes 1557487Srgrimes# clean up left-over files 15638237Sbrianclean_var # If it hasn't already been done 15738237Sbrianrm /var/run/clean_var 15838237Sbrian 15931192Ssteve# 16031192Ssteve# Clearing /tmp at boot-time seems to have a long tradition. It doesn't 16131192Ssteve# help in any way for long-living systems, and it might accidentally 16231192Ssteve# clobber files you would rather like to have preserved after a crash 16331192Ssteve# (if not using mfs /tmp anyway). 16431192Ssteve# 16531192Ssteve# See also the example of another cleanup policy in /etc/periodic/daily. 16631192Ssteve# 16731192Ssteveif [ "X${clear_tmp_enable}" = X"YES" ]; then 16831192Ssteve echo clearing /tmp 16931192Ssteve 17031192Ssteve # prune quickly with one rm, then use find to clean up /tmp/[lq]* 17131192Ssteve # (not needed with mfs /tmp, but doesn't hurt there...) 17231192Ssteve (cd /tmp && rm -rf [a-km-pr-zA-Z]* && 17339384Sbrian find -d . ! -name . ! -name lost+found ! -name quotas -exec rm -rf -- {} \;) 17431192Ssteve 17531192Sstevefi 17631192Ssteve 17738915Scracauer# Remove X lock files, since they will prevent you from restarting X11 17838915Scracauer# after a system crash. 17938915Scracauerrm -f /tmp/.X*-lock /tmp/.X11-unix/* 18038915Scracauer 1817487Srgrimes# snapshot any kernel -c changes back to disk 1827487Srgrimesecho 'recording kernel -c changes' 18325339Sjkhdset -q 1847487Srgrimes 18525339Sjkhecho -n 'additional daemons:' 1867487Srgrimes# start system logging and name service (named needs to start before syslogd 1877487Srgrimes# if you don't have a /etc/resolv.conf) 1887259Sjkh# 18925412Sjkhif [ "X${syslogd_enable}" = X"YES" ]; then 19024463Spst # Transitional symlink (for the next couple of years :) until all 19124463Spst # binaries had a chance to move towards /var/run/log. 19224463Spst if [ ! -h /dev/log ] ; then 19324463Spst # might complain for r/o root f/s 19424463Spst ln -sf /var/run/log /dev/log 19524463Spst fi 19624463Spst 19724463Spst rm -f /var/run/log 19825339Sjkh echo -n ' syslogd'; syslogd ${syslogd_flags} 19919226Sjoergfi 20025339Sjkhecho '.' 20125339Sjkh 20232340Sjoerg# enable dumpdev so that savecore can see it 20332340Sjoerg# /var/crash should be a directory or a symbolic link 20432340Sjoerg# to the crash directory if core dumps are to be saved. 20532340Sjoergif [ "X${dumpdev}" != X"NO" -a -e ${dumpdev} -a -d /var/crash ]; then 20632340Sjoerg dumpon ${dumpdev} 20732340Sjoerg echo -n checking for core dump... 20832340Sjoerg savecore /var/crash 20932340Sjoergfi 21032340Sjoerg 21125184Sjkhif [ -n "$network_pass1_done" ]; then 21239384Sbrian network_pass2 213857Sdgfi 21437Srgrimes 21518812Speter# Check the quotas (must be after ypbind if using NIS) 21618812Speterif [ "X${check_quotas}" = X"YES" ]; then 21718812Speter echo -n 'checking quotas:' 21818812Speter quotacheck -a 21918812Speter echo ' done.' 22018812Speter quotaon -a 2217238Sachefi 2227238Sache 22325184Sjkhif [ -n "$network_pass2_done" ]; then 22439384Sbrian network_pass3 2257477Sachefi 2267477Sache 2277238Sache 2287487Srgrimes# build ps databases 2297487Srgrimeskvm_mkdb 2307487Srgrimesdev_mkdb 2317487Srgrimes 2327487Srgrimes# check the password temp/lock file 2337487Srgrimesif [ -f /etc/ptmp ] 2347487Srgrimesthen 2357487Srgrimes logger -s -p auth.err \ 2367487Srgrimes "password file may be incorrect -- /etc/ptmp exists" 2377238Sachefi 2387238Sache 23925184Sjkhif [ "X${accounting_enable}" = X"YES" -a -d /var/account ]; then 24011992Sache echo 'turning on accounting' 24111992Sache if [ ! -e /var/account/acct ]; then 24225412Sjkh touch /var/account/acct 24311992Sache fi 24411992Sache accton /var/account/acct 2457238Sachefi 2467238Sache 24727365Sjkh# Make shared lib searching a little faster. Leave /usr/lib first if you 24827365Sjkh# add your own entries or you may come to grief. 24938512Sgpalmerif [ -x /sbin/ldconfig ]; then 25039329Sjdp if [ X"`/usr/bin/objformat`" = X"elf" ]; then 25139329Sjdp _LDC=/usr/lib 25239329Sjdp for i in $ldconfig_paths; do 25339329Sjdp if test -d $i; then 25439329Sjdp _LDC="${_LDC} $i" 25539329Sjdp fi 25639329Sjdp done 25739329Sjdp echo 'setting ELF ldconfig path:' ${_LDC} 25839329Sjdp ldconfig -elf ${_LDC} 25939329Sjdp fi 26039329Sjdp 26141648Sjb # Legacy aout support for i386 only 26241676Sjb if [ X"`sysctl -n hw.machine`" = X"i386" ]; then 26341648Sjb # Default the a.out ldconfig path, in case the system's 26441648Sjb # /etc/rc.conf hasn't been updated. 26541648Sjb : ${ldconfig_paths_aout=${ldconfig_paths}} 26641648Sjb _LDC=/usr/lib/aout 26741648Sjb for i in $ldconfig_paths_aout; do 26841648Sjb if test -d $i; then 26941648Sjb _LDC="${_LDC} $i" 27041648Sjb fi 27141648Sjb done 27241648Sjb echo 'setting a.out ldconfig path:' ${_LDC} 27341648Sjb ldconfig -aout ${_LDC} 27441648Sjb fi 27538512Sgpalmerfi 2767296Sjkh 27717210Spst# Now start up miscellaneous daemons that don't belong anywhere else 27817210Spst# 27925339Sjkhecho -n starting standard daemons: 28029343Sbrianif [ "X${inetd_enable}" != X"NO" ]; then 28126727Spst echo -n ' inetd'; inetd ${inetd_flags} 28226727Spstfi 28317210Spst 28429343Sbrianif [ "X${cron_enable}" != X"NO" ]; then 28526727Spst echo -n ' cron'; cron 28626727Spstfi 28726727Spst 28825184Sjkhif [ "X${lpd_enable}" = X"YES" ]; then 28925916Sjkh echo -n ' printer'; lpd ${lpd_flags} 29017210Spstfi 29117210Spst 29225184Sjkhif [ "X${sendmail_enable}" = X"YES" -a -r /etc/sendmail.cf ]; then 29325530Sjkh echo -n ' sendmail'; /usr/sbin/sendmail ${sendmail_flags} 29417161Spstfi 29517161Spst 29642498Sn_hibmaif [ "X${usbd_enable}" = X"YES" ]; then 29742498Sn_hibma echo -n ' usbd'; /usr/sbin/usbd ${usbd_flags} 29842498Sn_hibmafi 29942498Sn_hibma 30017161Spstecho '.' 30117161Spst 3027487Srgrimes# configure implementation specific stuff 3037487Srgrimesarch=`uname -m` 30425469Sandreasif [ -f /etc/rc.${arch} ]; then 30525469Sandreas . /etc/rc.${arch} 30625469Sandreasfi 3077487Srgrimes 30816671Spst# Recover vi editor files. 30919314Spetervibackup=`echo /var/tmp/vi.recover/vi.*` 31019314Speterif [ "$vibackup" != '/var/tmp/vi.recover/vi.*' ]; then 31116671Spst echo 'Recovering vi editor sessions' 31219314Speter for i in $vibackup; do 31319314Speter # Only test files that are readable. 31419314Speter if test ! -r $i; then 31519314Speter continue 31619314Speter fi 31719314Speter 31819314Speter # Unmodified nvi editor backup files either have the 31919314Speter # execute bit set or are zero length. Delete them. 32019314Speter if test -x $i -o ! -s $i; then 32119314Speter rm -f $i 32219314Speter fi 32316671Spst done 32419314Speter 32519314Speter # It is possible to get incomplete recovery files, if the editor 32619314Speter # crashes at the right time. 32719314Speter virecovery=`echo /var/tmp/vi.recover/recover.*` 32819314Speter if [ "$virecovery" != "/var/tmp/vi.recover/recover.*" ]; then 32919314Speter for i in $virecovery; do 33019314Speter # Only test files that are readable. 33119314Speter if test ! -r $i; then 33219314Speter continue 33319314Speter fi 33419314Speter 33519314Speter # Delete any recovery files that are zero length, 33619314Speter # corrupted, or that have no corresponding backup file. 33719314Speter # Else send mail to the user. 33819314Speter recfile=`awk '/^X-vi-recover-path:/{print $2}' < $i` 33919314Speter if test -n "$recfile" -a -s "$recfile"; then 34019314Speter sendmail -t < $i 34119314Speter else 34219314Speter rm -f $i 34319314Speter fi 34419314Speter done 34519314Speter fi 34616671Spstfi 34716671Spst 34837899Snectar# make a bounds file for msgs(1) if there isn't one already 34937899Snectarif [ ! -f /var/msgs/bounds ]; then 35037899Snectar echo 0 > /var/msgs/bounds 35137899Snectarfi 35237899Snectar 35313071Sjkh# for each valid dir in $local_startup, search for init scripts matching *.sh 35413071Sjkhif [ "X${local_startup}" != X"NO" ]; then 35527365Sjkh echo -n 'Local package initialization:' 35613071Sjkh for dir in ${local_startup}; do 35713071Sjkh [ -d ${dir} ] && for script in ${dir}/*.sh; do 35839824Scracauer [ -x ${script} ] && \ 35939824Scracauer (trap 'exit 1' 2 ; ${script} start ; echo -n) 36013071Sjkh done 36110873Sjkh done 36216391Sjkh echo . 3637259Sjkhfi 36437Srgrimes 36541704Sdillonif [ "X${update_motd}" != X"NO" ]; then 36641704Sdillon T=/tmp/_motd 36741704Sdillon rm -f $T 36841704Sdillon uname -v | sed -e 's,^\([^#]*\) #\(.* [1-2][0-9][0-9][0-9]\).*/\([^\]*\) $,\1 (\3) #\2,' > $T 36941704Sdillon awk '{if (NR == 1) {if ($1 == "FreeBSD") {next} else {print "\n"$0}} else {print}}' < /etc/motd >> $T 37041704Sdillon cp $T /etc/motd 37141704Sdillon chmod 644 /etc/motd 37241704Sdillon rm -f $T 37341704Sdillonfi 37441704Sdillon 37539162Ssos# Run rc.devfs if present to customify devfs 37639162Ssos[ -f /etc/rc.devfs ] && sh /etc/rc.devfs 37739162Ssos 37841704Sdillon# Do traditional (but rather obsolete) rc.local file if it exists. If you 37941704Sdillon# use this file and want to make it programmatic, source /etc/rc.conf in 38041704Sdillon# /etc/rc.local and add your custom variables to /etc/rc.conf.local, as 38141704Sdillon# shown below. Please do not put local extensions into /etc/rc itself. 38241704Sdillon# Use /etc/rc.local 38341704Sdillon# 38441704Sdillon# ---- rc.local ---- 38541704Sdillon# if [ -f /etc/rc.conf ]; then 38641704Sdillon# . /etc/rc.conf 38741704Sdillon# fi 38841704Sdillon# 38941704Sdillon# ... additional startup conditionals ... 39041704Sdillon# ---- rc.local ---- 39141704Sdillon# 39210873Sjkh 39341704Sdillonif [ -f /etc/rc.local ]; then 39441704Sdillon echo -n 'starting local daemons:' 39541704Sdillon sh /etc/rc.local 39641704Sdillon echo '.' 39741704Sdillonfi 39841704Sdillon 39937106Sjkoshy# Raise kernel security level. This should be done only after `fsck' has 40037106Sjkoshy# repaired local file systems if you want the securelevel to be greater than 1. 40139030Sjraynardif [ "X${kern_securelevel_enable}" = X"YES" -a "${kern_securelevel}" -ge 0 ]; 40237106Sjkoshythen 40337106Sjkoshy echo 'Raising kernel security level' 40437106Sjkoshy sysctl -w kern.securelevel=${kern_securelevel} 40537106Sjkoshyfi 40637106Sjkoshy 40737Srgrimesdate 40837Srgrimesexit 0 409