rc revision 43803
151090Ssheldonh#!/bin/sh 251090Ssheldonh# $Id: rc,v 1.176 1999/02/09 05:20:46 dillon Exp $ 351090Ssheldonh# From: @(#)rc 5.27 (Berkeley) 6/5/91 451090Ssheldonh 551090Ssheldonh# System startup script run by init on autoboot 651090Ssheldonh# or after single-user. 751090Ssheldonh# Output and error are redirected to console by init, 851090Ssheldonh# and the console is the controlling terminal. 951090Ssheldonh 1051090Ssheldonh# Note that almost all the user-configurable behavior is no longer in 1151090Ssheldonh# this file, but rather in /etc/rc.conf. Please check this file 1251090Ssheldonh# first before contemplating any changes here. 1351090Ssheldonh 1451090Ssheldonhstty status '^T' 1551090Ssheldonh 1651090Ssheldonh# Set shell to ignore SIGINT (2), but not children; 1751090Ssheldonh# shell catches SIGQUIT (3) and returns to single user after fsck. 1851090Ssheldonhtrap : 2 1951090Ssheldonhtrap : 3 # shouldn't be needed 2051090Ssheldonh 2151090SsheldonhHOME=/; export HOME 2251090SsheldonhPATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin 2351090Ssheldonhexport PATH 2451090Ssheldonh 2551090Ssheldonh# BOOTP diskless boot. We have to run the rc file early in order to 2651090Ssheldonh# retarget various config files. 27141580Sru# 2851090Ssheldonhif [ -f /etc/rc.diskless1 ]; then 29216629Sjilles dlv=`/sbin/sysctl -n vfs.nfs.diskless_valid 2> /dev/null` 3051090Ssheldonh if [ ${dlv:=0} != 0 ]; then 3151090Ssheldonh . /etc/rc.diskless1 3251090Ssheldonh fi 3351090Ssheldonhfi 34149912Sgarys 35165559Sru# If there is a global system configuration file, suck it in. 36149912Sgarys# 37149912Sgarysif [ -f /etc/rc.conf ]; then 38165559Sru . /etc/rc.conf 39207166Sjillesfi 40165559Sru 41165559Sru# Configure ccd devices. 4251090Ssheldonhif [ -f /etc/ccd.conf ]; then 4351090Ssheldonh ccdconfig -C 4451090Ssheldonhfi 45100574Stjr 4660261Ssheldonhif [ -n "$vinum_drives" ]; then 4751090Ssheldonh vinum read $vinum_drives 4851090Ssheldonhfi 4960261Ssheldonh 5051090Ssheldonhswapon -a 5151090Ssheldonh 5251090Ssheldonhif [ $1x = autobootx ]; then 5351090Ssheldonh echo Automatic reboot in progress... 5460261Ssheldonh fsck -p 5551090Ssheldonh case $? in 5651090Ssheldonh 0) 5751090Ssheldonh ;; 5851090Ssheldonh 2) 5951090Ssheldonh exit 1 6051090Ssheldonh ;; 6160261Ssheldonh 4) 6251090Ssheldonh reboot 6351090Ssheldonh echo "reboot failed... help!" 6451090Ssheldonh exit 1 6551090Ssheldonh ;; 6651090Ssheldonh 8) 6751090Ssheldonh echo "Automatic file system check failed... help!" 6851090Ssheldonh exit 1 6951090Ssheldonh ;; 7051090Ssheldonh 12) 7151090Ssheldonh echo "Reboot interrupted" 7286505Sknu exit 1 7351090Ssheldonh ;; 7451090Ssheldonh 130) 7560261Ssheldonh # interrupt before catcher installed 7651090Ssheldonh exit 1 7751090Ssheldonh ;; 7851090Ssheldonh *) 7951090Ssheldonh echo "Unknown error in reboot" 8051090Ssheldonh exit 1 8151090Ssheldonh ;; 8251090Ssheldonh esac 8351090Ssheldonhelse 8451090Ssheldonh echo Skipping disk checks ... 8560261Ssheldonhfi 8651090Ssheldonh 8751090Ssheldonhtrap "echo 'Reboot interrupted'; exit 1" 3 8851090Ssheldonh 8951090Ssheldonh# root normally must be read/write, but if this is a BOOTP NFS 9051090Ssheldonh# diskless boot it does not have to be. 91149912Sgarys# 9260261Ssheldonh 9351090Ssheldonhif [ "X$root_rw_mount" != "XNO" ]; then 9451090Ssheldonh mount -u -o rw / 9560261Ssheldonhfi 9651090Ssheldonh 9751090Ssheldonhif [ $? != 0 ]; then 9851090Ssheldonh echo "Filesystem mount failed, startup aborted" 9951090Ssheldonh exit 1 10051090Ssheldonhfi 10160261Ssheldonh 102215520Sjillesumount -a >/dev/null 2>&1 10351090Ssheldonh 10451090Ssheldonhif [ "X$early_nfs_mounts" != "XYES" ]; then 10557674Ssheldonh mount -a -t nonfs 10651090Ssheldonhelse 10751090Ssheldonh mount -a 10851090Ssheldonhfi 109149912Sgarysif [ $? != 0 ]; then 11060261Ssheldonh echo "Filesystem mount failed, startup aborted" 11151090Ssheldonh exit 1 11251090Ssheldonhfi 11360261Ssheldonh 11460261Ssheldonh# Run custom disk mounting function here 11551090Ssheldonh# 11651090Ssheldonh 11751090Ssheldonhif [ "X$diskless_mount" != "X" ]; then 11851090Ssheldonh if [ -f $diskless_mount ]; then 11951090Ssheldonh sh $diskless_mount 12051090Ssheldonh fi 12160261Ssheldonhfi 12286505Sknu 12351090Ssheldonh# If old file exists, whine until they fix it. 12451090Ssheldonhif [ -f /etc/sysconfig ]; then 125153092Sstefanf echo "Warning: /etc/sysconfig has been replaced by /etc/rc.conf." 12651090Ssheldonh echo "You should switch to /etc/rc.conf ASAP to eliminate this warning." 12786505Sknufi 12851090Ssheldonh 12951090Ssheldonhadjkerntz -i 13051090Ssheldonh 13151090Ssheldonhclean_var() { 13260261Ssheldonh if [ ! -f /var/run/clean_var ]; then 13351090Ssheldonh rm -rf /var/run/* 13451090Ssheldonh rm -f /var/spool/lock/* 13551090Ssheldonh rm -rf /var/spool/uucp/.Temp/* 13651090Ssheldonh # Keep a copy of the boot messages around 13751090Ssheldonh dmesg >/var/run/dmesg.boot 13851090Ssheldonh # And an initial utmp file 13960261Ssheldonh (cd /var/run && cp /dev/null utmp && chmod 644 utmp; ) 14051090Ssheldonh >/var/run/clean_var 14151090Ssheldonh fi 142149912Sgarys} 14351090Ssheldonh 144163326Sruif [ -d /var/run -a -d /var/spool/lock -a -d /var/spool/uucp/.Temp ]; then 14551090Ssheldonh # network_pass1() *may* end up writing stuff to /var - we don't want to 14651090Ssheldonh # remove it immediately afterwards - *nor* to we want to fail to clean 14751090Ssheldonh # an nfs-mounted /var. 14851090Ssheldonh clean_var 14951090Ssheldonhfi 15051090Ssheldonh 15151090Ssheldonh# Add additional swapfile, if configured. 15251090Ssheldonhif [ "x$swapfile" != "xNO" -a -w "$swapfile" -a -b /dev/vn0b ]; then 15379727Sschweikh echo "Adding $swapfile as additional swap." 154165559Sru vnconfig /dev/vn0b $swapfile && swapon /dev/vn0b 15551090Ssheldonhfi 15651275Ssheldonh 15751275Ssheldonh# configure serial devices 158165559Sruif [ -f /etc/rc.serial ]; then 15951090Ssheldonh . /etc/rc.serial 160149912Sgarysfi 161149912Sgarys 16251090Ssheldonh# start up PC-card configuration 163165559Sruif [ -f /etc/rc.pccard ]; then 16451090Ssheldonh . /etc/rc.pccard 165165559Srufi 16651090Ssheldonh 16751090Ssheldonh# start up the initial network configuration. 16851090Ssheldonhif [ -f /etc/rc.network ]; then 16951090Ssheldonh . /etc/rc.network # We only need to do this once. 17051090Ssheldonh network_pass1 17151090Ssheldonhfi 17251090Ssheldonh 17351090Ssheldonhecho -n "Mounting NFS file systems" 17451090Ssheldonhmount -a -t nfs 17551090Ssheldonhecho . 17651090Ssheldonh 17751275Ssheldonh# Whack the pty perms back into shape. 178149912Sgaryschmod 666 /dev/tty[pqrsPQRS]* 179149912Sgarys 180149912Sgarys# clean up left-over files 181149912Sgarysclean_var # If it hasn't already been done 182149912Sgarysrm /var/run/clean_var 183149912Sgarys 184149912Sgarys# 185149912Sgarys# Clearing /tmp at boot-time seems to have a long tradition. It doesn't 186149912Sgarys# help in any way for long-living systems, and it might accidentally 187149912Sgarys# clobber files you would rather like to have preserved after a crash 188149912Sgarys# (if not using mfs /tmp anyway). 189149912Sgarys# 190142331Strhodes# See also the example of another cleanup policy in /etc/periodic/daily. 191142331Strhodes# 192142331Strhodesif [ "X${clear_tmp_enable}" = X"YES" ]; then 193142331Strhodes echo clearing /tmp 194142331Strhodes 195142331Strhodes # prune quickly with one rm, then use find to clean up /tmp/[lq]* 19681285Sru # (not needed with mfs /tmp, but doesn't hurt there...) 197209033Suqs (cd /tmp && rm -rf [a-km-pr-zA-Z]* && 198207168Sjilles find -d . ! -name . ! -name lost+found ! -name quotas -exec rm -rf -- {} \;) 199149912Sgarys 200207168Sjillesfi 201207168Sjilles 202207817Sjilles# Remove X lock files, since they will prevent you from restarting X11 203207166Sjilles# after a system crash. 204165559Srurm -f /tmp/.X*-lock /tmp/.X11-unix/* 205165559Sru 206165559Sru# snapshot any kernel -c changes back to disk here <someday> 20751090Ssheldonh# this has changed with ELF and /kernel.config. 208142331Strhodes 209100574Stjrecho -n 'additional daemons:' 21060261Ssheldonh# start system logging and name service (named needs to start before syslogd 211165559Sru# if you don't have a /etc/resolv.conf) 21251090Ssheldonh# 213142331Strhodesif [ "X${syslogd_enable}" = X"YES" ]; then 21460261Ssheldonh # Transitional symlink (for the next couple of years :) until all 21551090Ssheldonh # binaries had a chance to move towards /var/run/log. 216165559Sru if [ ! -h /dev/log ] ; then 217165559Sru # might complain for r/o root f/s 218165559Sru ln -sf /var/run/log /dev/log 21960261Ssheldonh fi 220165559Sru 22151090Ssheldonh rm -f /var/run/log 22251090Ssheldonh echo -n ' syslogd'; syslogd ${syslogd_flags} 22351090Ssheldonhfi 22451090Ssheldonhecho '.' 22551090Ssheldonh 22660261Ssheldonh# enable dumpdev so that savecore can see it 22751090Ssheldonh# /var/crash should be a directory or a symbolic link 228165559Sru# to the crash directory if core dumps are to be saved. 22951090Ssheldonhif [ "X${dumpdev}" != X"NO" -a -e ${dumpdev} -a -d /var/crash ]; then 23051090Ssheldonh dumpon ${dumpdev} 23151090Ssheldonh echo -n checking for core dump... 23251090Ssheldonh savecore /var/crash 23351090Ssheldonhfi 23451090Ssheldonh 23551090Ssheldonhif [ -n "$network_pass1_done" ]; then 23651090Ssheldonh network_pass2 23786505Sknufi 238165559Sru 239165559Sru# Check the quotas (must be after ypbind if using NIS) 24060261Ssheldonhif [ "X${check_quotas}" = X"YES" ]; then 24151090Ssheldonh echo -n 'checking quotas:' 24251090Ssheldonh quotacheck -a 24351090Ssheldonh echo ' done.' 244165559Sru quotaon -a 24551090Ssheldonhfi 24651090Ssheldonh 247207196Sjillesif [ -n "$network_pass2_done" ]; then 24851090Ssheldonh network_pass3 24951090Ssheldonhfi 25060261Ssheldonh 251165559Sru 25251090Ssheldonh# build ps databases 253165559Srukvm_mkdb 254216629Sjillesdev_mkdb 25551090Ssheldonh 256149912Sgarys# check the password temp/lock file 25760261Ssheldonhif [ -f /etc/ptmp ] 25851090Ssheldonhthen 25951090Ssheldonh logger -s -p auth.err \ 26060261Ssheldonh "password file may be incorrect -- /etc/ptmp exists" 26151090Ssheldonhfi 26251090Ssheldonh 26351090Ssheldonhif [ "X${accounting_enable}" = X"YES" -a -d /var/account ]; then 26451090Ssheldonh echo 'turning on accounting' 26551090Ssheldonh if [ ! -e /var/account/acct ]; then 26660261Ssheldonh touch /var/account/acct 267215520Sjilles fi 26851090Ssheldonh accton /var/account/acct 26951090Ssheldonhfi 270165559Sru 27151090Ssheldonh# Make shared lib searching a little faster. Leave /usr/lib first if you 27251090Ssheldonh# add your own entries or you may come to grief. 27351090Ssheldonhif [ -x /sbin/ldconfig ]; then 274149912Sgarys if [ X"`/usr/bin/objformat`" = X"elf" ]; then 27560261Ssheldonh _LDC=/usr/lib 276165559Sru for i in $ldconfig_paths; do 27751090Ssheldonh if test -d $i; then 27860261Ssheldonh _LDC="${_LDC} $i" 27960261Ssheldonh fi 28051090Ssheldonh done 28151090Ssheldonh echo 'setting ELF ldconfig path:' ${_LDC} 28251090Ssheldonh ldconfig -elf ${_LDC} 28351090Ssheldonh fi 28451090Ssheldonh 28551090Ssheldonh # Legacy aout support for i386 only 28660261Ssheldonh if [ X"`sysctl -n hw.machine`" = X"i386" ]; then 28786505Sknu # Default the a.out ldconfig path, in case the system's 28851090Ssheldonh # /etc/rc.conf hasn't been updated. 28951090Ssheldonh : ${ldconfig_paths_aout=${ldconfig_paths}} 290153092Sstefanf _LDC=/usr/lib/aout 29151090Ssheldonh for i in $ldconfig_paths_aout; do 29286505Sknu if test -d $i; then 293207196Sjilles _LDC="${_LDC} $i" 294207196Sjilles fi 295165559Sru done 296165559Sru echo 'setting a.out ldconfig path:' ${_LDC} 29760261Ssheldonh ldconfig -aout ${_LDC} 29851090Ssheldonh fi 29951090Ssheldonhfi 30051090Ssheldonh 30151090Ssheldonh# Now start up miscellaneous daemons that don't belong anywhere else 30251090Ssheldonh# 303165559Sruecho -n starting standard daemons: 30460261Ssheldonhif [ "X${inetd_enable}" != X"NO" ]; then 30551090Ssheldonh echo -n ' inetd'; inetd ${inetd_flags} 306165559Srufi 30751090Ssheldonh 30851090Ssheldonhif [ "X${cron_enable}" != X"NO" ]; then 30951090Ssheldonh echo -n ' cron'; cron 31051090Ssheldonhfi 31186654Sknu 312142331Strhodesif [ "X${lpd_enable}" = X"YES" ]; then 31351090Ssheldonh echo -n ' printer'; lpd ${lpd_flags} 31451090Ssheldonhfi 31551090Ssheldonh 31651090Ssheldonhif [ "X${sendmail_enable}" = X"YES" -a -r /etc/sendmail.cf ]; then 31760261Ssheldonh echo -n ' sendmail'; /usr/sbin/sendmail ${sendmail_flags} 318215520Sjillesfi 31951090Ssheldonh 32051090Ssheldonhif [ "X${usbd_enable}" = X"YES" ]; then 32186654Sknu echo -n ' usbd'; /usr/sbin/usbd ${usbd_flags} 32251090Ssheldonhfi 32386654Sknu 32451090Ssheldonhecho '.' 32551090Ssheldonh 32651090Ssheldonh# configure implementation specific stuff 32751090Ssheldonharch=`uname -m` 32851090Ssheldonhif [ -f /etc/rc.${arch} ]; then 32957714Ssheldonh . /etc/rc.${arch} 33051090Ssheldonhfi 33151090Ssheldonh 332267776Sbapt# Recover vi editor files. 333vibackup=`echo /var/tmp/vi.recover/vi.*` 334if [ "$vibackup" != '/var/tmp/vi.recover/vi.*' ]; then 335 echo 'Recovering vi editor sessions' 336 for i in $vibackup; do 337 # Only test files that are readable. 338 if test ! -r $i; then 339 continue 340 fi 341 342 # Unmodified nvi editor backup files either have the 343 # execute bit set or are zero length. Delete them. 344 if test -x $i -o ! -s $i; then 345 rm -f $i 346 fi 347 done 348 349 # It is possible to get incomplete recovery files, if the editor 350 # crashes at the right time. 351 virecovery=`echo /var/tmp/vi.recover/recover.*` 352 if [ "$virecovery" != "/var/tmp/vi.recover/recover.*" ]; then 353 for i in $virecovery; do 354 # Only test files that are readable. 355 if test ! -r $i; then 356 continue 357 fi 358 359 # Delete any recovery files that are zero length, 360 # corrupted, or that have no corresponding backup file. 361 # Else send mail to the user. 362 recfile=`awk '/^X-vi-recover-path:/{print $2}' < $i` 363 if test -n "$recfile" -a -s "$recfile"; then 364 sendmail -t < $i 365 else 366 rm -f $i 367 fi 368 done 369 fi 370fi 371 372# make a bounds file for msgs(1) if there isn't one already 373if [ ! -f /var/msgs/bounds ]; then 374 echo 0 > /var/msgs/bounds 375fi 376 377# for each valid dir in $local_startup, search for init scripts matching *.sh 378if [ "X${local_startup}" != X"NO" ]; then 379 echo -n 'Local package initialization:' 380 for dir in ${local_startup}; do 381 [ -d ${dir} ] && for script in ${dir}/*.sh; do 382 [ -x ${script} ] && \ 383 (trap 'exit 1' 2 ; ${script} start ; echo -n) 384 done 385 done 386 echo . 387fi 388 389if [ "X${update_motd}" != X"NO" ]; then 390 T=/tmp/_motd 391 rm -f $T 392 uname -v | sed -e 's,^\([^#]*\) #\(.* [1-2][0-9][0-9][0-9]\).*/\([^\]*\) $,\1 (\3) #\2,' > $T 393 awk '{if (NR == 1) {if ($1 == "FreeBSD") {next} else {print "\n"$0}} else {print}}' < /etc/motd >> $T 394 cp $T /etc/motd 395 chmod 644 /etc/motd 396 rm -f $T 397fi 398 399# Run rc.devfs if present to customify devfs 400[ -f /etc/rc.devfs ] && sh /etc/rc.devfs 401 402# Do traditional (but rather obsolete) rc.local file if it exists. If you 403# use this file and want to make it programmatic, source /etc/rc.conf in 404# /etc/rc.local and add your custom variables to /etc/rc.conf.local, as 405# shown below. Please do not put local extensions into /etc/rc itself. 406# Use /etc/rc.local 407# 408# ---- rc.local ---- 409# if [ -f /etc/rc.conf ]; then 410# . /etc/rc.conf 411# fi 412# 413# ... additional startup conditionals ... 414# ---- rc.local ---- 415# 416 417# Do traditional rc.local file if it exists. 418# 419 420if [ -f /etc/rc.local ]; then 421 echo -n 'starting local daemons:' 422 sh /etc/rc.local 423 echo '.' 424fi 425 426# Raise kernel security level. This should be done only after `fsck' has 427# repaired local file systems if you want the securelevel to be greater than 1. 428if [ "X${kern_securelevel_enable}" = X"YES" -a "${kern_securelevel}" -ge 0 ]; 429then 430 echo 'Raising kernel security level' 431 sysctl -w kern.securelevel=${kern_securelevel} 432fi 433 434date 435exit 0 436