rc revision 43849
140123Sdes#!/bin/sh 243849Sjkh# $Id: rc,v 1.177 1999/02/09 17:17:18 dillon 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 2543179Sdillon# BOOTP diskless boot. We have to run the rc file early in order to 2643803Sdillon# retarget various config files. 2743179Sdillon# 2843803Sdillonif [ -f /etc/rc.diskless1 ]; then 2943375Sdillon dlv=`/sbin/sysctl -n vfs.nfs.diskless_valid 2> /dev/null` 3043375Sdillon if [ ${dlv:=0} != 0 ]; then 3143803Sdillon . /etc/rc.diskless1 3243179Sdillon fi 3343179Sdillonfi 3443179Sdillon 3543219Speter# If there is a global system configuration file, suck it in. 3643219Speter# 3743849Sjkhif [ -f /etc/defaults/rc.conf ]; then 3843849Sjkh . /etc/defaults/rc.conf 3943849Sjkhelif [ -f /etc/rc.conf ]; then 4043219Speter . /etc/rc.conf 4143219Speterfi 4243219Speter 4315568Sasami# Configure ccd devices. 4443803Sdillonif [ -f /etc/ccd.conf ]; then 4515568Sasami ccdconfig -C 4615568Sasamifi 4715568Sasami 4843803Sdillonif [ -n "$vinum_drives" ]; then 4943454Sgrog vinum read $vinum_drives 5042741Sgrogfi 5142741Sgrog 5243803Sdillonswapon -a 533843Sdg 5443803Sdillonif [ $1x = autobootx ]; then 5537Srgrimes echo Automatic reboot in progress... 5637Srgrimes fsck -p 5737Srgrimes case $? in 5837Srgrimes 0) 5937Srgrimes ;; 6037Srgrimes 2) 6137Srgrimes exit 1 6237Srgrimes ;; 6337Srgrimes 4) 6437Srgrimes reboot 6537Srgrimes echo "reboot failed... help!" 6637Srgrimes exit 1 6737Srgrimes ;; 6837Srgrimes 8) 6937Srgrimes echo "Automatic file system check failed... help!" 7037Srgrimes exit 1 7137Srgrimes ;; 7237Srgrimes 12) 7337Srgrimes echo "Reboot interrupted" 7437Srgrimes exit 1 7537Srgrimes ;; 7637Srgrimes 130) 7737Srgrimes # interrupt before catcher installed 7837Srgrimes exit 1 7937Srgrimes ;; 8037Srgrimes *) 8137Srgrimes echo "Unknown error in reboot" 8237Srgrimes exit 1 8337Srgrimes ;; 8437Srgrimes esac 852164Sdgelse 862164Sdg echo Skipping disk checks ... 8737Srgrimesfi 8837Srgrimes 8937Srgrimestrap "echo 'Reboot interrupted'; exit 1" 3 9037Srgrimes 9143197Sdillon# root normally must be read/write, but if this is a BOOTP NFS 9243197Sdillon# diskless boot it does not have to be. 9343197Sdillon# 941692Sphk 9543803Sdillonif [ "X$root_rw_mount" != "XNO" ]; then 9643197Sdillon mount -u -o rw / 9743803Sdillonfi 988530Sdg 9943803Sdillonif [ $? != 0 ]; then 10043803Sdillon echo "Filesystem mount failed, startup aborted" 10143803Sdillon exit 1 10243803Sdillonfi 10343197Sdillon 10443803Sdillonumount -a >/dev/null 2>&1 10543197Sdillon 10643803Sdillonif [ "X$early_nfs_mounts" != "XYES" ]; then 10743197Sdillon mount -a -t nonfs 10843803Sdillonelse 10943803Sdillon mount -a 1108530Sdgfi 11143803Sdillonif [ $? != 0 ]; then 11243803Sdillon echo "Filesystem mount failed, startup aborted" 11343803Sdillon exit 1 11443803Sdillonfi 11537Srgrimes 11643197Sdillon# Run custom disk mounting function here 11743197Sdillon# 11843197Sdillon 11943803Sdillonif [ "X$diskless_mount" != "X" ]; then 12043803Sdillon if [ -f $diskless_mount ]; then 12143803Sdillon sh $diskless_mount 12243803Sdillon fi 12343197Sdillonfi 12443197Sdillon 12525184Sjkh# If old file exists, whine until they fix it. 12625184Sjkhif [ -f /etc/sysconfig ]; then 12725184Sjkh echo "Warning: /etc/sysconfig has been replaced by /etc/rc.conf." 12825184Sjkh echo "You should switch to /etc/rc.conf ASAP to eliminate this warning." 12925184Sjkhfi 13025184Sjkh 1314091Sacheadjkerntz -i 132872Sache 13338237Sbrianclean_var() { 13439384Sbrian if [ ! -f /var/run/clean_var ]; then 13539384Sbrian rm -rf /var/run/* 13639384Sbrian rm -f /var/spool/lock/* 13739384Sbrian rm -rf /var/spool/uucp/.Temp/* 13839384Sbrian # Keep a copy of the boot messages around 13939384Sbrian dmesg >/var/run/dmesg.boot 14039384Sbrian # And an initial utmp file 14139384Sbrian (cd /var/run && cp /dev/null utmp && chmod 644 utmp; ) 14239384Sbrian >/var/run/clean_var 14339384Sbrian fi 14438237Sbrian} 14526450Sache 14638237Sbrianif [ -d /var/run -a -d /var/spool/lock -a -d /var/spool/uucp/.Temp ]; then 14739384Sbrian # network_pass1() *may* end up writing stuff to /var - we don't want to 14839384Sbrian # remove it immediately afterwards - *nor* to we want to fail to clean 14939384Sbrian # an nfs-mounted /var. 15039384Sbrian clean_var 15138237Sbrianfi 15221197Sphk 15317767Sjkh# Add additional swapfile, if configured. 15419363Sjoergif [ "x$swapfile" != "xNO" -a -w "$swapfile" -a -b /dev/vn0b ]; then 15517767Sjkh echo "Adding $swapfile as additional swap." 15625184Sjkh vnconfig /dev/vn0b $swapfile && swapon /dev/vn0b 15717767Sjkhfi 15817767Sjkh 1591675Sache# configure serial devices 1607219Sjkhif [ -f /etc/rc.serial ]; then 1617293Sjkh . /etc/rc.serial 1621675Sachefi 1631675Sache 16414596Snate# start up PC-card configuration 16514624Snateif [ -f /etc/rc.pccard ]; then 16614624Snate . /etc/rc.pccard 16714596Snatefi 16814596Snate 16925184Sjkh# start up the initial network configuration. 17025184Sjkhif [ -f /etc/rc.network ]; then 17125184Sjkh . /etc/rc.network # We only need to do this once. 17225184Sjkh network_pass1 1737460Sjkhfi 1747460Sjkh 17538456Sphkecho -n "Mounting NFS file systems" 17629319Sbrianmount -a -t nfs 17738456Sphkecho . 1787487Srgrimes 1797487Srgrimes# Whack the pty perms back into shape. 18020828Sjoergchmod 666 /dev/tty[pqrsPQRS]* 1817487Srgrimes 1827487Srgrimes# clean up left-over files 18338237Sbrianclean_var # If it hasn't already been done 18438237Sbrianrm /var/run/clean_var 18538237Sbrian 18631192Ssteve# 18731192Ssteve# Clearing /tmp at boot-time seems to have a long tradition. It doesn't 18831192Ssteve# help in any way for long-living systems, and it might accidentally 18931192Ssteve# clobber files you would rather like to have preserved after a crash 19031192Ssteve# (if not using mfs /tmp anyway). 19131192Ssteve# 19231192Ssteve# See also the example of another cleanup policy in /etc/periodic/daily. 19331192Ssteve# 19431192Ssteveif [ "X${clear_tmp_enable}" = X"YES" ]; then 19531192Ssteve echo clearing /tmp 19631192Ssteve 19731192Ssteve # prune quickly with one rm, then use find to clean up /tmp/[lq]* 19831192Ssteve # (not needed with mfs /tmp, but doesn't hurt there...) 19931192Ssteve (cd /tmp && rm -rf [a-km-pr-zA-Z]* && 20039384Sbrian find -d . ! -name . ! -name lost+found ! -name quotas -exec rm -rf -- {} \;) 20131192Ssteve 20231192Sstevefi 20331192Ssteve 20438915Scracauer# Remove X lock files, since they will prevent you from restarting X11 20538915Scracauer# after a system crash. 20638915Scracauerrm -f /tmp/.X*-lock /tmp/.X11-unix/* 20738915Scracauer 20842897Sjkh# snapshot any kernel -c changes back to disk here <someday> 20942897Sjkh# this has changed with ELF and /kernel.config. 2107487Srgrimes 21125339Sjkhecho -n 'additional daemons:' 2127487Srgrimes# start system logging and name service (named needs to start before syslogd 2137487Srgrimes# if you don't have a /etc/resolv.conf) 2147259Sjkh# 21525412Sjkhif [ "X${syslogd_enable}" = X"YES" ]; then 21624463Spst # Transitional symlink (for the next couple of years :) until all 21724463Spst # binaries had a chance to move towards /var/run/log. 21824463Spst if [ ! -h /dev/log ] ; then 21924463Spst # might complain for r/o root f/s 22024463Spst ln -sf /var/run/log /dev/log 22124463Spst fi 22224463Spst 22324463Spst rm -f /var/run/log 22425339Sjkh echo -n ' syslogd'; syslogd ${syslogd_flags} 22519226Sjoergfi 22625339Sjkhecho '.' 22725339Sjkh 22832340Sjoerg# enable dumpdev so that savecore can see it 22932340Sjoerg# /var/crash should be a directory or a symbolic link 23032340Sjoerg# to the crash directory if core dumps are to be saved. 23132340Sjoergif [ "X${dumpdev}" != X"NO" -a -e ${dumpdev} -a -d /var/crash ]; then 23232340Sjoerg dumpon ${dumpdev} 23332340Sjoerg echo -n checking for core dump... 23432340Sjoerg savecore /var/crash 23532340Sjoergfi 23632340Sjoerg 23725184Sjkhif [ -n "$network_pass1_done" ]; then 23839384Sbrian network_pass2 239857Sdgfi 24037Srgrimes 24118812Speter# Check the quotas (must be after ypbind if using NIS) 24218812Speterif [ "X${check_quotas}" = X"YES" ]; then 24318812Speter echo -n 'checking quotas:' 24418812Speter quotacheck -a 24518812Speter echo ' done.' 24618812Speter quotaon -a 2477238Sachefi 2487238Sache 24925184Sjkhif [ -n "$network_pass2_done" ]; then 25039384Sbrian network_pass3 2517477Sachefi 2527477Sache 2537238Sache 2547487Srgrimes# build ps databases 2557487Srgrimeskvm_mkdb 2567487Srgrimesdev_mkdb 2577487Srgrimes 2587487Srgrimes# check the password temp/lock file 2597487Srgrimesif [ -f /etc/ptmp ] 2607487Srgrimesthen 2617487Srgrimes logger -s -p auth.err \ 2627487Srgrimes "password file may be incorrect -- /etc/ptmp exists" 2637238Sachefi 2647238Sache 26525184Sjkhif [ "X${accounting_enable}" = X"YES" -a -d /var/account ]; then 26611992Sache echo 'turning on accounting' 26711992Sache if [ ! -e /var/account/acct ]; then 26825412Sjkh touch /var/account/acct 26911992Sache fi 27011992Sache accton /var/account/acct 2717238Sachefi 2727238Sache 27327365Sjkh# Make shared lib searching a little faster. Leave /usr/lib first if you 27427365Sjkh# add your own entries or you may come to grief. 27538512Sgpalmerif [ -x /sbin/ldconfig ]; then 27639329Sjdp if [ X"`/usr/bin/objformat`" = X"elf" ]; then 27739329Sjdp _LDC=/usr/lib 27839329Sjdp for i in $ldconfig_paths; do 27939329Sjdp if test -d $i; then 28039329Sjdp _LDC="${_LDC} $i" 28139329Sjdp fi 28239329Sjdp done 28339329Sjdp echo 'setting ELF ldconfig path:' ${_LDC} 28439329Sjdp ldconfig -elf ${_LDC} 28539329Sjdp fi 28639329Sjdp 28741648Sjb # Legacy aout support for i386 only 28841676Sjb if [ X"`sysctl -n hw.machine`" = X"i386" ]; then 28941648Sjb # Default the a.out ldconfig path, in case the system's 29041648Sjb # /etc/rc.conf hasn't been updated. 29141648Sjb : ${ldconfig_paths_aout=${ldconfig_paths}} 29241648Sjb _LDC=/usr/lib/aout 29341648Sjb for i in $ldconfig_paths_aout; do 29441648Sjb if test -d $i; then 29541648Sjb _LDC="${_LDC} $i" 29641648Sjb fi 29741648Sjb done 29841648Sjb echo 'setting a.out ldconfig path:' ${_LDC} 29941648Sjb ldconfig -aout ${_LDC} 30041648Sjb fi 30138512Sgpalmerfi 3027296Sjkh 30317210Spst# Now start up miscellaneous daemons that don't belong anywhere else 30417210Spst# 30525339Sjkhecho -n starting standard daemons: 30629343Sbrianif [ "X${inetd_enable}" != X"NO" ]; then 30726727Spst echo -n ' inetd'; inetd ${inetd_flags} 30826727Spstfi 30917210Spst 31029343Sbrianif [ "X${cron_enable}" != X"NO" ]; then 31126727Spst echo -n ' cron'; cron 31226727Spstfi 31326727Spst 31425184Sjkhif [ "X${lpd_enable}" = X"YES" ]; then 31525916Sjkh echo -n ' printer'; lpd ${lpd_flags} 31617210Spstfi 31717210Spst 31825184Sjkhif [ "X${sendmail_enable}" = X"YES" -a -r /etc/sendmail.cf ]; then 31925530Sjkh echo -n ' sendmail'; /usr/sbin/sendmail ${sendmail_flags} 32017161Spstfi 32117161Spst 32242498Sn_hibmaif [ "X${usbd_enable}" = X"YES" ]; then 32342498Sn_hibma echo -n ' usbd'; /usr/sbin/usbd ${usbd_flags} 32442498Sn_hibmafi 32542498Sn_hibma 32617161Spstecho '.' 32717161Spst 3287487Srgrimes# configure implementation specific stuff 3297487Srgrimesarch=`uname -m` 33025469Sandreasif [ -f /etc/rc.${arch} ]; then 33125469Sandreas . /etc/rc.${arch} 33225469Sandreasfi 3337487Srgrimes 33416671Spst# Recover vi editor files. 33519314Spetervibackup=`echo /var/tmp/vi.recover/vi.*` 33619314Speterif [ "$vibackup" != '/var/tmp/vi.recover/vi.*' ]; then 33716671Spst echo 'Recovering vi editor sessions' 33819314Speter for i in $vibackup; do 33919314Speter # Only test files that are readable. 34019314Speter if test ! -r $i; then 34119314Speter continue 34219314Speter fi 34319314Speter 34419314Speter # Unmodified nvi editor backup files either have the 34519314Speter # execute bit set or are zero length. Delete them. 34619314Speter if test -x $i -o ! -s $i; then 34719314Speter rm -f $i 34819314Speter fi 34916671Spst done 35019314Speter 35119314Speter # It is possible to get incomplete recovery files, if the editor 35219314Speter # crashes at the right time. 35319314Speter virecovery=`echo /var/tmp/vi.recover/recover.*` 35419314Speter if [ "$virecovery" != "/var/tmp/vi.recover/recover.*" ]; then 35519314Speter for i in $virecovery; do 35619314Speter # Only test files that are readable. 35719314Speter if test ! -r $i; then 35819314Speter continue 35919314Speter fi 36019314Speter 36119314Speter # Delete any recovery files that are zero length, 36219314Speter # corrupted, or that have no corresponding backup file. 36319314Speter # Else send mail to the user. 36419314Speter recfile=`awk '/^X-vi-recover-path:/{print $2}' < $i` 36519314Speter if test -n "$recfile" -a -s "$recfile"; then 36619314Speter sendmail -t < $i 36719314Speter else 36819314Speter rm -f $i 36919314Speter fi 37019314Speter done 37119314Speter fi 37216671Spstfi 37316671Spst 37437899Snectar# make a bounds file for msgs(1) if there isn't one already 37537899Snectarif [ ! -f /var/msgs/bounds ]; then 37637899Snectar echo 0 > /var/msgs/bounds 37737899Snectarfi 37837899Snectar 37913071Sjkh# for each valid dir in $local_startup, search for init scripts matching *.sh 38013071Sjkhif [ "X${local_startup}" != X"NO" ]; then 38127365Sjkh echo -n 'Local package initialization:' 38213071Sjkh for dir in ${local_startup}; do 38313071Sjkh [ -d ${dir} ] && for script in ${dir}/*.sh; do 38439824Scracauer [ -x ${script} ] && \ 38539824Scracauer (trap 'exit 1' 2 ; ${script} start ; echo -n) 38613071Sjkh done 38710873Sjkh done 38816391Sjkh echo . 3897259Sjkhfi 39037Srgrimes 39141704Sdillonif [ "X${update_motd}" != X"NO" ]; then 39241704Sdillon T=/tmp/_motd 39341704Sdillon rm -f $T 39441704Sdillon uname -v | sed -e 's,^\([^#]*\) #\(.* [1-2][0-9][0-9][0-9]\).*/\([^\]*\) $,\1 (\3) #\2,' > $T 39541704Sdillon awk '{if (NR == 1) {if ($1 == "FreeBSD") {next} else {print "\n"$0}} else {print}}' < /etc/motd >> $T 39641704Sdillon cp $T /etc/motd 39741704Sdillon chmod 644 /etc/motd 39841704Sdillon rm -f $T 39941704Sdillonfi 40041704Sdillon 40139162Ssos# Run rc.devfs if present to customify devfs 40239162Ssos[ -f /etc/rc.devfs ] && sh /etc/rc.devfs 40339162Ssos 40441704Sdillon# Do traditional (but rather obsolete) rc.local file if it exists. If you 40541704Sdillon# use this file and want to make it programmatic, source /etc/rc.conf in 40641704Sdillon# /etc/rc.local and add your custom variables to /etc/rc.conf.local, as 40741704Sdillon# shown below. Please do not put local extensions into /etc/rc itself. 40841704Sdillon# Use /etc/rc.local 40941704Sdillon# 41041704Sdillon# ---- rc.local ---- 41141704Sdillon# if [ -f /etc/rc.conf ]; then 41241704Sdillon# . /etc/rc.conf 41341704Sdillon# fi 41441704Sdillon# 41541704Sdillon# ... additional startup conditionals ... 41641704Sdillon# ---- rc.local ---- 41741704Sdillon# 41810873Sjkh 41943197Sdillon# Do traditional rc.local file if it exists. 42043197Sdillon# 42143197Sdillon 42243797Sdillonif [ -f /etc/rc.local ]; then 42343197Sdillon echo -n 'starting local daemons:' 42443797Sdillon sh /etc/rc.local 42543197Sdillon echo '.' 42641704Sdillonfi 42741704Sdillon 42837106Sjkoshy# Raise kernel security level. This should be done only after `fsck' has 42937106Sjkoshy# repaired local file systems if you want the securelevel to be greater than 1. 43039030Sjraynardif [ "X${kern_securelevel_enable}" = X"YES" -a "${kern_securelevel}" -ge 0 ]; 43137106Sjkoshythen 43237106Sjkoshy echo 'Raising kernel security level' 43337106Sjkoshy sysctl -w kern.securelevel=${kern_securelevel} 43437106Sjkoshyfi 43537106Sjkoshy 43637Srgrimesdate 43737Srgrimesexit 0 438