rc revision 37899
1709Swollman#!/bin/sh 237899Snectar# $Id: rc,v 1.146 1998/06/22 06:34:12 jkoshy 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 303843Sdgswapon -a 313843Sdg 3225184Sjkhif [ $1x = autobootx ]; then 3337Srgrimes echo Automatic reboot in progress... 3437Srgrimes fsck -p 3537Srgrimes case $? in 3637Srgrimes 0) 3737Srgrimes ;; 3837Srgrimes 2) 3937Srgrimes exit 1 4037Srgrimes ;; 4137Srgrimes 4) 4237Srgrimes reboot 4337Srgrimes echo "reboot failed... help!" 4437Srgrimes exit 1 4537Srgrimes ;; 4637Srgrimes 8) 4737Srgrimes echo "Automatic file system check failed... help!" 4837Srgrimes exit 1 4937Srgrimes ;; 5037Srgrimes 12) 5137Srgrimes echo "Reboot interrupted" 5237Srgrimes exit 1 5337Srgrimes ;; 5437Srgrimes 130) 5537Srgrimes # interrupt before catcher installed 5637Srgrimes exit 1 5737Srgrimes ;; 5837Srgrimes *) 5937Srgrimes echo "Unknown error in reboot" 6037Srgrimes exit 1 6137Srgrimes ;; 6237Srgrimes esac 632164Sdgelse 642164Sdg echo Skipping disk checks ... 6537Srgrimesfi 6637Srgrimes 6737Srgrimestrap "echo 'Reboot interrupted'; exit 1" 3 6837Srgrimes 693036Sdg# root must be read/write both for NFS diskless and for VFS LKMs before 703036Sdg# proceeding any further. 713036Sdgmount -u -o rw / 728530Sdgif [ $? != 0 ]; then 738530Sdg echo "Filesystem mount failed, startup aborted" 748530Sdg exit 1 758530Sdgfi 761692Sphk 7737Srgrimesumount -a >/dev/null 2>&1 788530Sdg 7937Srgrimesmount -a -t nonfs 808530Sdgif [ $? != 0 ]; then 818530Sdg echo "Filesystem mount failed, startup aborted" 828530Sdg exit 1 838530Sdgfi 8437Srgrimes 8525184Sjkh# If there is a global system configuration file, suck it in. 8625184Sjkhif [ -f /etc/rc.conf ]; then 8725184Sjkh . /etc/rc.conf 8825184Sjkhfi 8925184Sjkh 9025184Sjkh# If old file exists, whine until they fix it. 9125184Sjkhif [ -f /etc/sysconfig ]; then 9225184Sjkh echo "Warning: /etc/sysconfig has been replaced by /etc/rc.conf." 9325184Sjkh echo "You should switch to /etc/rc.conf ASAP to eliminate this warning." 9425184Sjkhfi 9525184Sjkh 964091Sacheadjkerntz -i 97872Sache 9836584Sphkrm -rf /var/run/* 9926450Sache 10021197Sphk# Keep a copy of the boot messages around 10125184Sjkhdmesg > /var/run/dmesg.boot 10221197Sphk 10317767Sjkh# Add additional swapfile, if configured. 10419363Sjoergif [ "x$swapfile" != "xNO" -a -w "$swapfile" -a -b /dev/vn0b ]; then 10517767Sjkh echo "Adding $swapfile as additional swap." 10625184Sjkh vnconfig /dev/vn0b $swapfile && swapon /dev/vn0b 10717767Sjkhfi 10817767Sjkh 1091675Sache# configure serial devices 1107219Sjkhif [ -f /etc/rc.serial ]; then 1117293Sjkh . /etc/rc.serial 1121675Sachefi 1131675Sache 11414596Snate# start up PC-card configuration 11514624Snateif [ -f /etc/rc.pccard ]; then 11614624Snate . /etc/rc.pccard 11714596Snatefi 11814596Snate 11925184Sjkh# start up the initial network configuration. 12025184Sjkhif [ -f /etc/rc.network ]; then 12125184Sjkh . /etc/rc.network # We only need to do this once. 12225184Sjkh network_pass1 1237460Sjkhfi 1247460Sjkh 12529319Sbrianmount -a -t nfs 1267487Srgrimes 1277487Srgrimes# Whack the pty perms back into shape. 12820828Sjoergchmod 666 /dev/tty[pqrsPQRS]* 1297487Srgrimes 1307487Srgrimes# clean up left-over files 1317487Srgrimesrm -f /etc/nologin 1327487Srgrimesrm -f /var/spool/lock/* 1337761Sacherm -rf /var/spool/uucp/.Temp/* 13415684Sjkh(cd /var/run && { cp /dev/null utmp; chmod 644 utmp; }) 1357487Srgrimes 13631192Ssteve# 13731192Ssteve# Clearing /tmp at boot-time seems to have a long tradition. It doesn't 13831192Ssteve# help in any way for long-living systems, and it might accidentally 13931192Ssteve# clobber files you would rather like to have preserved after a crash 14031192Ssteve# (if not using mfs /tmp anyway). 14131192Ssteve# 14231192Ssteve# See also the example of another cleanup policy in /etc/periodic/daily. 14331192Ssteve# 14431192Ssteveif [ "X${clear_tmp_enable}" = X"YES" ]; then 14531192Ssteve echo clearing /tmp 14631192Ssteve 14731192Ssteve # prune quickly with one rm, then use find to clean up /tmp/[lq]* 14831192Ssteve # (not needed with mfs /tmp, but doesn't hurt there...) 14931192Ssteve (cd /tmp && rm -rf [a-km-pr-zA-Z]* && 15031192Ssteve find -d . ! -name . ! -name lost+found ! -name quotas -exec rm -rf -- {} \;) 15131192Ssteve 15231192Ssteve # Also remove X lock files since it will prevent you from 15331192Ssteve # restarting X11 after a system crash. 15431192Ssteve rm -f /tmp/.X*-lock /tmp/.X11-unix/* 15531192Sstevefi 15631192Ssteve 1577487Srgrimes# snapshot any kernel -c changes back to disk 1587487Srgrimesecho 'recording kernel -c changes' 15925339Sjkhdset -q 1607487Srgrimes 16125339Sjkhecho -n 'additional daemons:' 1627487Srgrimes# start system logging and name service (named needs to start before syslogd 1637487Srgrimes# if you don't have a /etc/resolv.conf) 1647259Sjkh# 16525412Sjkhif [ "X${syslogd_enable}" = X"YES" ]; then 16624463Spst # Transitional symlink (for the next couple of years :) until all 16724463Spst # binaries had a chance to move towards /var/run/log. 16824463Spst if [ ! -h /dev/log ] ; then 16924463Spst # might complain for r/o root f/s 17024463Spst ln -sf /var/run/log /dev/log 17124463Spst fi 17224463Spst 17324463Spst rm -f /var/run/log 17425339Sjkh echo -n ' syslogd'; syslogd ${syslogd_flags} 17519226Sjoergfi 1767487Srgrimes 17725339Sjkhif [ "X${tickadj_enable}" = X"YES" ]; then 17825412Sjkh echo -n ' tickadj'; tickadj ${tickadj_flags--Aq} 17925339Sjkhfi 18025339Sjkhecho '.' 18125339Sjkh 18232340Sjoerg# enable dumpdev so that savecore can see it 18332340Sjoerg# /var/crash should be a directory or a symbolic link 18432340Sjoerg# to the crash directory if core dumps are to be saved. 18532340Sjoergif [ "X${dumpdev}" != X"NO" -a -e ${dumpdev} -a -d /var/crash ]; then 18632340Sjoerg dumpon ${dumpdev} 18732340Sjoerg echo -n checking for core dump... 18832340Sjoerg savecore /var/crash 18932340Sjoergfi 19032340Sjoerg 19125184Sjkhif [ -n "$network_pass1_done" ]; then 19225184Sjkh network_pass2 193857Sdgfi 19437Srgrimes 19518812Speter# Check the quotas (must be after ypbind if using NIS) 19618812Speterif [ "X${check_quotas}" = X"YES" ]; then 19718812Speter echo -n 'checking quotas:' 19818812Speter quotacheck -a 19918812Speter echo ' done.' 20018812Speter quotaon -a 2017238Sachefi 2027238Sache 20325184Sjkhif [ -n "$network_pass2_done" ]; then 20425184Sjkh network_pass3 2057477Sachefi 2067477Sache 2077238Sache 2087487Srgrimes# build ps databases 2097487Srgrimeskvm_mkdb 2107487Srgrimesdev_mkdb 2117487Srgrimes 2127487Srgrimes# check the password temp/lock file 2137487Srgrimesif [ -f /etc/ptmp ] 2147487Srgrimesthen 2157487Srgrimes logger -s -p auth.err \ 2167487Srgrimes "password file may be incorrect -- /etc/ptmp exists" 2177238Sachefi 2187238Sache 21925184Sjkhif [ "X${accounting_enable}" = X"YES" -a -d /var/account ]; then 22011992Sache echo 'turning on accounting' 22111992Sache if [ ! -e /var/account/acct ]; then 22225412Sjkh touch /var/account/acct 22311992Sache fi 22411992Sache accton /var/account/acct 2257238Sachefi 2267238Sache 22727365Sjkh# Make shared lib searching a little faster. Leave /usr/lib first if you 22827365Sjkh# add your own entries or you may come to grief. 22936397Ssos_LDC=/usr/lib/aout 23032028Sstevefor i in $ldconfig_paths; do 23132028Ssteve if test -d $i; then 23232028Ssteve _LDC="${_LDC} $i" 23332028Ssteve fi 23432028Sstevedone 23525184Sjkhecho 'setting ldconfig path:' ${_LDC} 23625184Sjkhldconfig ${_LDC} 2377296Sjkh 23817210Spst# Now start up miscellaneous daemons that don't belong anywhere else 23917210Spst# 24025339Sjkhecho -n starting standard daemons: 24129343Sbrianif [ "X${inetd_enable}" != X"NO" ]; then 24226727Spst echo -n ' inetd'; inetd ${inetd_flags} 24326727Spstfi 24417210Spst 24529343Sbrianif [ "X${cron_enable}" != X"NO" ]; then 24626727Spst echo -n ' cron'; cron 24726727Spstfi 24826727Spst 24925184Sjkhif [ "X${lpd_enable}" = X"YES" ]; then 25025916Sjkh echo -n ' printer'; lpd ${lpd_flags} 25117210Spstfi 25217210Spst 25325184Sjkhif [ "X${sendmail_enable}" = X"YES" -a -r /etc/sendmail.cf ]; then 25425530Sjkh echo -n ' sendmail'; /usr/sbin/sendmail ${sendmail_flags} 25517161Spstfi 25617161Spst 25717161Spstecho '.' 25817161Spst 2597487Srgrimes# configure implementation specific stuff 2607487Srgrimesarch=`uname -m` 26125469Sandreasif [ -f /etc/rc.${arch} ]; then 26225469Sandreas . /etc/rc.${arch} 26325469Sandreasfi 2647487Srgrimes 26516671Spst# Recover vi editor files. 26619314Spetervibackup=`echo /var/tmp/vi.recover/vi.*` 26719314Speterif [ "$vibackup" != '/var/tmp/vi.recover/vi.*' ]; then 26816671Spst echo 'Recovering vi editor sessions' 26919314Speter for i in $vibackup; do 27019314Speter # Only test files that are readable. 27119314Speter if test ! -r $i; then 27219314Speter continue 27319314Speter fi 27419314Speter 27519314Speter # Unmodified nvi editor backup files either have the 27619314Speter # execute bit set or are zero length. Delete them. 27719314Speter if test -x $i -o ! -s $i; then 27819314Speter rm -f $i 27919314Speter fi 28016671Spst done 28119314Speter 28219314Speter # It is possible to get incomplete recovery files, if the editor 28319314Speter # crashes at the right time. 28419314Speter virecovery=`echo /var/tmp/vi.recover/recover.*` 28519314Speter if [ "$virecovery" != "/var/tmp/vi.recover/recover.*" ]; then 28619314Speter for i in $virecovery; do 28719314Speter # Only test files that are readable. 28819314Speter if test ! -r $i; then 28919314Speter continue 29019314Speter fi 29119314Speter 29219314Speter # Delete any recovery files that are zero length, 29319314Speter # corrupted, or that have no corresponding backup file. 29419314Speter # Else send mail to the user. 29519314Speter recfile=`awk '/^X-vi-recover-path:/{print $2}' < $i` 29619314Speter if test -n "$recfile" -a -s "$recfile"; then 29719314Speter sendmail -t < $i 29819314Speter else 29919314Speter rm -f $i 30019314Speter fi 30119314Speter done 30219314Speter fi 30316671Spstfi 30416671Spst 30537899Snectar# make a bounds file for msgs(1) if there isn't one already 30637899Snectarif [ ! -f /var/msgs/bounds ]; then 30737899Snectar echo 0 > /var/msgs/bounds 30837899Snectarfi 30937899Snectar 31013071Sjkh# for each valid dir in $local_startup, search for init scripts matching *.sh 31113071Sjkhif [ "X${local_startup}" != X"NO" ]; then 31227365Sjkh echo -n 'Local package initialization:' 31313071Sjkh for dir in ${local_startup}; do 31413071Sjkh [ -d ${dir} ] && for script in ${dir}/*.sh; do 31513071Sjkh [ -x ${script} ] && ${script} start 31613071Sjkh done 31710873Sjkh done 31816391Sjkh echo . 3197259Sjkhfi 32037Srgrimes 32110873Sjkh# Do traditional (but rather obsolete) rc.local file if it exists. 32226934Spst[ -f /etc/rc.local ] && sh /etc/rc.local 32310873Sjkh 32437106Sjkoshy# Raise kernel security level. This should be done only after `fsck' has 32537106Sjkoshy# repaired local file systems if you want the securelevel to be greater than 1. 32637106Sjkoshyif [ "X${kern_securelevel_enable}" != X"NO" -a "${kern_securelevel}" -ge 0 ]; 32737106Sjkoshythen 32837106Sjkoshy echo 'Raising kernel security level' 32937106Sjkoshy sysctl -w kern.securelevel=${kern_securelevel} 33037106Sjkoshyfi 33137106Sjkoshy 33237Srgrimesdate 33337Srgrimesexit 0 334