rc revision 40123
140123Sdes#!/bin/sh 240123Sdes# $Id: rc,v 1.159 1998/10/08 18:47:29 des 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 8739384Sbrian . /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 9838237Sbrianclean_var() { 9939384Sbrian if [ ! -f /var/run/clean_var ]; then 10039384Sbrian rm -rf /var/run/* 10139384Sbrian rm -f /var/spool/lock/* 10239384Sbrian rm -rf /var/spool/uucp/.Temp/* 10339384Sbrian # Keep a copy of the boot messages around 10439384Sbrian dmesg >/var/run/dmesg.boot 10539384Sbrian # And an initial utmp file 10639384Sbrian (cd /var/run && cp /dev/null utmp && chmod 644 utmp; ) 10739384Sbrian >/var/run/clean_var 10839384Sbrian fi 10938237Sbrian} 11026450Sache 11138237Sbrianif [ -d /var/run -a -d /var/spool/lock -a -d /var/spool/uucp/.Temp ]; then 11239384Sbrian # network_pass1() *may* end up writing stuff to /var - we don't want to 11339384Sbrian # remove it immediately afterwards - *nor* to we want to fail to clean 11439384Sbrian # an nfs-mounted /var. 11539384Sbrian clean_var 11638237Sbrianfi 11721197Sphk 11817767Sjkh# Add additional swapfile, if configured. 11919363Sjoergif [ "x$swapfile" != "xNO" -a -w "$swapfile" -a -b /dev/vn0b ]; then 12017767Sjkh echo "Adding $swapfile as additional swap." 12125184Sjkh vnconfig /dev/vn0b $swapfile && swapon /dev/vn0b 12217767Sjkhfi 12317767Sjkh 1241675Sache# configure serial devices 1257219Sjkhif [ -f /etc/rc.serial ]; then 1267293Sjkh . /etc/rc.serial 1271675Sachefi 1281675Sache 12914596Snate# start up PC-card configuration 13014624Snateif [ -f /etc/rc.pccard ]; then 13114624Snate . /etc/rc.pccard 13214596Snatefi 13314596Snate 13425184Sjkh# start up the initial network configuration. 13525184Sjkhif [ -f /etc/rc.network ]; then 13625184Sjkh . /etc/rc.network # We only need to do this once. 13725184Sjkh network_pass1 1387460Sjkhfi 1397460Sjkh 14038456Sphkecho -n "Mounting NFS file systems" 14129319Sbrianmount -a -t nfs 14238456Sphkecho . 1437487Srgrimes 1447487Srgrimes# Whack the pty perms back into shape. 14520828Sjoergchmod 666 /dev/tty[pqrsPQRS]* 1467487Srgrimes 1477487Srgrimes# clean up left-over files 1487487Srgrimesrm -f /etc/nologin 1497487Srgrimes 15038237Sbrianclean_var # If it hasn't already been done 15138237Sbrianrm /var/run/clean_var 15238237Sbrian 15331192Ssteve# 15431192Ssteve# Clearing /tmp at boot-time seems to have a long tradition. It doesn't 15531192Ssteve# help in any way for long-living systems, and it might accidentally 15631192Ssteve# clobber files you would rather like to have preserved after a crash 15731192Ssteve# (if not using mfs /tmp anyway). 15831192Ssteve# 15931192Ssteve# See also the example of another cleanup policy in /etc/periodic/daily. 16031192Ssteve# 16131192Ssteveif [ "X${clear_tmp_enable}" = X"YES" ]; then 16231192Ssteve echo clearing /tmp 16331192Ssteve 16431192Ssteve # prune quickly with one rm, then use find to clean up /tmp/[lq]* 16531192Ssteve # (not needed with mfs /tmp, but doesn't hurt there...) 16631192Ssteve (cd /tmp && rm -rf [a-km-pr-zA-Z]* && 16739384Sbrian find -d . ! -name . ! -name lost+found ! -name quotas -exec rm -rf -- {} \;) 16831192Ssteve 16931192Sstevefi 17031192Ssteve 17138915Scracauer# Remove X lock files, since they will prevent you from restarting X11 17238915Scracauer# after a system crash. 17338915Scracauerrm -f /tmp/.X*-lock /tmp/.X11-unix/* 17438915Scracauer 1757487Srgrimes# snapshot any kernel -c changes back to disk 1767487Srgrimesecho 'recording kernel -c changes' 17725339Sjkhdset -q 1787487Srgrimes 17925339Sjkhecho -n 'additional daemons:' 1807487Srgrimes# start system logging and name service (named needs to start before syslogd 1817487Srgrimes# if you don't have a /etc/resolv.conf) 1827259Sjkh# 18325412Sjkhif [ "X${syslogd_enable}" = X"YES" ]; then 18424463Spst # Transitional symlink (for the next couple of years :) until all 18524463Spst # binaries had a chance to move towards /var/run/log. 18624463Spst if [ ! -h /dev/log ] ; then 18724463Spst # might complain for r/o root f/s 18824463Spst ln -sf /var/run/log /dev/log 18924463Spst fi 19024463Spst 19124463Spst rm -f /var/run/log 19225339Sjkh echo -n ' syslogd'; syslogd ${syslogd_flags} 19319226Sjoergfi 19425339Sjkhecho '.' 19525339Sjkh 19632340Sjoerg# enable dumpdev so that savecore can see it 19732340Sjoerg# /var/crash should be a directory or a symbolic link 19832340Sjoerg# to the crash directory if core dumps are to be saved. 19932340Sjoergif [ "X${dumpdev}" != X"NO" -a -e ${dumpdev} -a -d /var/crash ]; then 20032340Sjoerg dumpon ${dumpdev} 20132340Sjoerg echo -n checking for core dump... 20232340Sjoerg savecore /var/crash 20332340Sjoergfi 20432340Sjoerg 20525184Sjkhif [ -n "$network_pass1_done" ]; then 20639384Sbrian network_pass2 207857Sdgfi 20837Srgrimes 20918812Speter# Check the quotas (must be after ypbind if using NIS) 21018812Speterif [ "X${check_quotas}" = X"YES" ]; then 21118812Speter echo -n 'checking quotas:' 21218812Speter quotacheck -a 21318812Speter echo ' done.' 21418812Speter quotaon -a 2157238Sachefi 2167238Sache 21725184Sjkhif [ -n "$network_pass2_done" ]; then 21839384Sbrian network_pass3 2197477Sachefi 2207477Sache 2217238Sache 2227487Srgrimes# build ps databases 2237487Srgrimeskvm_mkdb 2247487Srgrimesdev_mkdb 2257487Srgrimes 2267487Srgrimes# check the password temp/lock file 2277487Srgrimesif [ -f /etc/ptmp ] 2287487Srgrimesthen 2297487Srgrimes logger -s -p auth.err \ 2307487Srgrimes "password file may be incorrect -- /etc/ptmp exists" 2317238Sachefi 2327238Sache 23325184Sjkhif [ "X${accounting_enable}" = X"YES" -a -d /var/account ]; then 23411992Sache echo 'turning on accounting' 23511992Sache if [ ! -e /var/account/acct ]; then 23625412Sjkh touch /var/account/acct 23711992Sache fi 23811992Sache accton /var/account/acct 2397238Sachefi 2407238Sache 24127365Sjkh# Make shared lib searching a little faster. Leave /usr/lib first if you 24227365Sjkh# add your own entries or you may come to grief. 24338512Sgpalmerif [ -x /sbin/ldconfig ]; then 24439329Sjdp if [ X"`/usr/bin/objformat`" = X"elf" ]; then 24539329Sjdp _LDC=/usr/lib 24639329Sjdp for i in $ldconfig_paths; do 24739329Sjdp if test -d $i; then 24839329Sjdp _LDC="${_LDC} $i" 24939329Sjdp fi 25039329Sjdp done 25139329Sjdp echo 'setting ELF ldconfig path:' ${_LDC} 25239329Sjdp ldconfig -elf ${_LDC} 25339329Sjdp fi 25439329Sjdp 25539329Sjdp # Default the a.out ldconfig path, in case the system's 25639329Sjdp # /etc/rc.conf hasn't been updated. 25739329Sjdp : ${ldconfig_paths_aout=${ldconfig_paths}} 25838512Sgpalmer _LDC=/usr/lib/aout 25939329Sjdp for i in $ldconfig_paths_aout; do 26038512Sgpalmer if test -d $i; then 26138512Sgpalmer _LDC="${_LDC} $i" 26238512Sgpalmer fi 26338512Sgpalmer done 26438837Sjdp echo 'setting a.out ldconfig path:' ${_LDC} 26538837Sjdp ldconfig -aout ${_LDC} 26638512Sgpalmerfi 2677296Sjkh 26817210Spst# Now start up miscellaneous daemons that don't belong anywhere else 26917210Spst# 27025339Sjkhecho -n starting standard daemons: 27129343Sbrianif [ "X${inetd_enable}" != X"NO" ]; then 27226727Spst echo -n ' inetd'; inetd ${inetd_flags} 27326727Spstfi 27417210Spst 27529343Sbrianif [ "X${cron_enable}" != X"NO" ]; then 27626727Spst echo -n ' cron'; cron 27726727Spstfi 27826727Spst 27925184Sjkhif [ "X${lpd_enable}" = X"YES" ]; then 28025916Sjkh echo -n ' printer'; lpd ${lpd_flags} 28117210Spstfi 28217210Spst 28325184Sjkhif [ "X${sendmail_enable}" = X"YES" -a -r /etc/sendmail.cf ]; then 28425530Sjkh echo -n ' sendmail'; /usr/sbin/sendmail ${sendmail_flags} 28517161Spstfi 28617161Spst 28717161Spstecho '.' 28817161Spst 2897487Srgrimes# configure implementation specific stuff 2907487Srgrimesarch=`uname -m` 29125469Sandreasif [ -f /etc/rc.${arch} ]; then 29225469Sandreas . /etc/rc.${arch} 29325469Sandreasfi 2947487Srgrimes 29516671Spst# Recover vi editor files. 29619314Spetervibackup=`echo /var/tmp/vi.recover/vi.*` 29719314Speterif [ "$vibackup" != '/var/tmp/vi.recover/vi.*' ]; then 29816671Spst echo 'Recovering vi editor sessions' 29919314Speter for i in $vibackup; do 30019314Speter # Only test files that are readable. 30119314Speter if test ! -r $i; then 30219314Speter continue 30319314Speter fi 30419314Speter 30519314Speter # Unmodified nvi editor backup files either have the 30619314Speter # execute bit set or are zero length. Delete them. 30719314Speter if test -x $i -o ! -s $i; then 30819314Speter rm -f $i 30919314Speter fi 31016671Spst done 31119314Speter 31219314Speter # It is possible to get incomplete recovery files, if the editor 31319314Speter # crashes at the right time. 31419314Speter virecovery=`echo /var/tmp/vi.recover/recover.*` 31519314Speter if [ "$virecovery" != "/var/tmp/vi.recover/recover.*" ]; then 31619314Speter for i in $virecovery; do 31719314Speter # Only test files that are readable. 31819314Speter if test ! -r $i; then 31919314Speter continue 32019314Speter fi 32119314Speter 32219314Speter # Delete any recovery files that are zero length, 32319314Speter # corrupted, or that have no corresponding backup file. 32419314Speter # Else send mail to the user. 32519314Speter recfile=`awk '/^X-vi-recover-path:/{print $2}' < $i` 32619314Speter if test -n "$recfile" -a -s "$recfile"; then 32719314Speter sendmail -t < $i 32819314Speter else 32919314Speter rm -f $i 33019314Speter fi 33119314Speter done 33219314Speter fi 33316671Spstfi 33416671Spst 33537899Snectar# make a bounds file for msgs(1) if there isn't one already 33637899Snectarif [ ! -f /var/msgs/bounds ]; then 33737899Snectar echo 0 > /var/msgs/bounds 33837899Snectarfi 33937899Snectar 34013071Sjkh# for each valid dir in $local_startup, search for init scripts matching *.sh 34113071Sjkhif [ "X${local_startup}" != X"NO" ]; then 34227365Sjkh echo -n 'Local package initialization:' 34313071Sjkh for dir in ${local_startup}; do 34413071Sjkh [ -d ${dir} ] && for script in ${dir}/*.sh; do 34539824Scracauer [ -x ${script} ] && \ 34639824Scracauer (trap 'exit 1' 2 ; ${script} start ; echo -n) 34713071Sjkh done 34810873Sjkh done 34916391Sjkh echo . 3507259Sjkhfi 35137Srgrimes 35239162Ssos# Run rc.devfs if present to customify devfs 35339162Ssos[ -f /etc/rc.devfs ] && sh /etc/rc.devfs 35439162Ssos 35510873Sjkh# Do traditional (but rather obsolete) rc.local file if it exists. 35626934Spst[ -f /etc/rc.local ] && sh /etc/rc.local 35710873Sjkh 35837106Sjkoshy# Raise kernel security level. This should be done only after `fsck' has 35937106Sjkoshy# repaired local file systems if you want the securelevel to be greater than 1. 36039030Sjraynardif [ "X${kern_securelevel_enable}" = X"YES" -a "${kern_securelevel}" -ge 0 ]; 36137106Sjkoshythen 36237106Sjkoshy echo 'Raising kernel security level' 36337106Sjkoshy sysctl -w kern.securelevel=${kern_securelevel} 36437106Sjkoshyfi 36537106Sjkoshy 36637Srgrimesdate 36737Srgrimesexit 0 368