rc revision 45222
1#!/bin/sh 2# $Id: rc,v 1.184 1999/03/28 20:36:03 imp Exp $ 3# From: @(#)rc 5.27 (Berkeley) 6/5/91 4 5# System startup script run by init on autoboot 6# or after single-user. 7# Output and error are redirected to console by init, 8# and the console is the controlling terminal. 9 10# Note that almost all the user-configurable behavior is no longer in 11# this file, but rather in /etc/defaults/rc.conf. Please check this file 12# first before contemplating any changes here. 13 14stty status '^T' 15 16# Set shell to ignore SIGINT (2), but not children; 17# shell catches SIGQUIT (3) and returns to single user after fsck. 18trap : 2 19trap : 3 # shouldn't be needed 20 21HOME=/; export HOME 22PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin 23export PATH 24 25# BOOTP diskless boot. We have to run the rc file early in order to 26# retarget various config files. 27# 28if [ -f /etc/rc.diskless1 ]; then 29 dlv=`/sbin/sysctl -n vfs.nfs.diskless_valid 2> /dev/null` 30 if [ ${dlv:=0} != 0 ]; then 31 . /etc/rc.diskless1 32 fi 33fi 34 35# If there is a global system configuration file, suck it in. 36# 37if [ -f /etc/defaults/rc.conf ]; then 38 . /etc/defaults/rc.conf 39elif [ -f /etc/rc.conf ]; then 40 . /etc/rc.conf 41fi 42 43# Configure ccd devices. 44if [ -f /etc/ccd.conf ]; then 45 ccdconfig -C 46fi 47 48if [ -n "$vinum_drives" ]; then 49 vinum read $vinum_drives 50fi 51 52swapon -a 53 54if [ $1x = autobootx ]; then 55 echo Automatic reboot in progress... 56 fsck -p 57 case $? in 58 0) 59 ;; 60 2) 61 exit 1 62 ;; 63 4) 64 reboot 65 echo "reboot failed... help!" 66 exit 1 67 ;; 68 8) 69 echo "Automatic file system check failed... help!" 70 exit 1 71 ;; 72 12) 73 echo "Reboot interrupted" 74 exit 1 75 ;; 76 130) 77 # interrupt before catcher installed 78 exit 1 79 ;; 80 *) 81 echo "Unknown error in reboot" 82 exit 1 83 ;; 84 esac 85else 86 echo Skipping disk checks ... 87fi 88 89set -T 90trap "echo 'Reboot interrupted'; exit 1" 3 91 92# root normally must be read/write, but if this is a BOOTP NFS 93# diskless boot it does not have to be. 94# 95 96if [ "X$root_rw_mount" != "XNO" ]; then 97 mount -u -o rw / 98fi 99 100if [ $? != 0 ]; then 101 echo "Filesystem mount failed, startup aborted" 102 exit 1 103fi 104 105umount -a >/dev/null 2>&1 106 107if [ "X$early_nfs_mounts" != "XYES" ]; then 108 mount -a -t nonfs 109else 110 mount -a 111fi 112if [ $? != 0 ]; then 113 echo "Filesystem mount failed, startup aborted" 114 exit 1 115fi 116 117# Run custom disk mounting function here 118# 119 120if [ "X$diskless_mount" != "X" ]; then 121 if [ -f $diskless_mount ]; then 122 sh $diskless_mount 123 fi 124fi 125 126adjkerntz -i 127 128clean_var() { 129 if [ ! -f /var/run/clean_var ]; then 130 rm -rf /var/run/* 131 rm -f /var/spool/lock/* 132 rm -rf /var/spool/uucp/.Temp/* 133 # Keep a copy of the boot messages around 134 dmesg >/var/run/dmesg.boot 135 # And an initial utmp file 136 (cd /var/run && cp /dev/null utmp && chmod 644 utmp; ) 137 >/var/run/clean_var 138 fi 139} 140 141if [ -d /var/run -a -d /var/spool/lock -a -d /var/spool/uucp/.Temp ]; then 142 # network_pass1() *may* end up writing stuff to /var - we don't want to 143 # remove it immediately afterwards - *nor* to we want to fail to clean 144 # an nfs-mounted /var. 145 clean_var 146fi 147 148# Add additional swapfile, if configured. 149if [ "x$swapfile" != "xNO" -a -w "$swapfile" -a -b /dev/vn0b ]; then 150 echo "Adding $swapfile as additional swap." 151 vnconfig /dev/vn0b $swapfile && swapon /dev/vn0b 152fi 153 154# set sysctl variables early as we can 155if [ -f /etc/rc.sysctl ]; then 156 . /etc/rc.sysctl 157fi 158 159# configure serial devices 160if [ -f /etc/rc.serial ]; then 161 . /etc/rc.serial 162fi 163 164# start up PC-card configuration 165if [ -f /etc/rc.pccard ]; then 166 . /etc/rc.pccard 167fi 168 169# start up the initial network configuration. 170if [ -f /etc/rc.network ]; then 171 . /etc/rc.network # We only need to do this once. 172 network_pass1 173fi 174 175echo -n "Mounting NFS file systems" 176mount -a -t nfs 177echo . 178 179# Whack the pty perms back into shape. 180chmod 666 /dev/tty[pqrsPQRS]* 181chown root:wheel /dev/tty[pqrsPQRS]* 182 183# clean up left-over files 184clean_var # If it hasn't already been done 185rm /var/run/clean_var 186 187# 188# Clearing /tmp at boot-time seems to have a long tradition. It doesn't 189# help in any way for long-living systems, and it might accidentally 190# clobber files you would rather like to have preserved after a crash 191# (if not using mfs /tmp anyway). 192# 193# See also the example of another cleanup policy in /etc/periodic/daily. 194# 195if [ "X${clear_tmp_enable}" = X"YES" ]; then 196 echo clearing /tmp 197 198 # prune quickly with one rm, then use find to clean up /tmp/[lq]* 199 # (not needed with mfs /tmp, but doesn't hurt there...) 200 (cd /tmp && rm -rf [a-km-pr-zA-Z]* && 201 find -d . ! -name . ! -name lost+found ! -name quotas -exec rm -rf -- {} \;) 202 203fi 204 205# Remove X lock files, since they will prevent you from restarting X11 206# after a system crash. 207rm -f /tmp/.X*-lock /tmp/.X11-unix/* 208 209# snapshot any kernel -c changes back to disk here <someday> 210# this has changed with ELF and /kernel.config. 211 212echo -n 'additional daemons:' 213# start system logging and name service (named needs to start before syslogd 214# if you don't have a /etc/resolv.conf) 215# 216if [ "X${syslogd_enable}" = X"YES" ]; then 217 # Transitional symlink (for the next couple of years :) until all 218 # binaries had a chance to move towards /var/run/log. 219 if [ ! -h /dev/log ] ; then 220 # might complain for r/o root f/s 221 ln -sf /var/run/log /dev/log 222 fi 223 224 rm -f /var/run/log 225 echo -n ' syslogd'; syslogd ${syslogd_flags} 226fi 227echo '.' 228 229# enable dumpdev so that savecore can see it 230# /var/crash should be a directory or a symbolic link 231# to the crash directory if core dumps are to be saved. 232if [ "X${dumpdev}" != X"NO" -a -e ${dumpdev} -a -d /var/crash ]; then 233 dumpon ${dumpdev} 234 echo -n checking for core dump... 235 savecore /var/crash 236fi 237 238if [ -n "$network_pass1_done" ]; then 239 network_pass2 240fi 241 242# Enable/Check the quotas (must be after ypbind if using NIS) 243if [ "X${enable_quotas}" = X"YES" ]; then 244 245 # Only check quotas if they have been previously enabled, and requested 246 if [ "X${check_quotas}" = X"YES" ]; then 247 echo -n 'checking quotas:' 248 quotacheck -a 249 echo ' done.' 250 fi 251 252 echo -n 'enabling quotas:' 253 quotaon -a 254 echo ' done.' 255fi 256 257if [ -n "$network_pass2_done" ]; then 258 network_pass3 259fi 260 261 262# build ps databases 263kvm_mkdb 264dev_mkdb 265 266# check the password temp/lock file 267if [ -f /etc/ptmp ] 268then 269 logger -s -p auth.err \ 270 "password file may be incorrect -- /etc/ptmp exists" 271fi 272 273if [ "X${accounting_enable}" = X"YES" -a -d /var/account ]; then 274 echo 'turning on accounting' 275 if [ ! -e /var/account/acct ]; then 276 touch /var/account/acct 277 fi 278 accton /var/account/acct 279fi 280 281# Make shared lib searching a little faster. Leave /usr/lib first if you 282# add your own entries or you may come to grief. 283if [ -x /sbin/ldconfig ]; then 284 if [ X"`/usr/bin/objformat`" = X"elf" ]; then 285 _LDC=/usr/lib 286 for i in $ldconfig_paths; do 287 if test -d $i; then 288 _LDC="${_LDC} $i" 289 fi 290 done 291 echo 'setting ELF ldconfig path:' ${_LDC} 292 ldconfig -elf ${_LDC} 293 fi 294 295 # Legacy aout support for i386 only 296 if [ X"`sysctl -n hw.machine`" = X"i386" ]; then 297 # Default the a.out ldconfig path. 298 : ${ldconfig_paths_aout=${ldconfig_paths}} 299 _LDC=/usr/lib/aout 300 for i in $ldconfig_paths_aout; do 301 if test -d $i; then 302 _LDC="${_LDC} $i" 303 fi 304 done 305 echo 'setting a.out ldconfig path:' ${_LDC} 306 ldconfig -aout ${_LDC} 307 fi 308fi 309 310# Now start up miscellaneous daemons that don't belong anywhere else 311# 312echo -n starting standard daemons: 313if [ "X${inetd_enable}" != X"NO" ]; then 314 echo -n ' inetd'; inetd ${inetd_flags} 315fi 316 317if [ "X${cron_enable}" != X"NO" ]; then 318 echo -n ' cron'; cron 319fi 320 321if [ "X${lpd_enable}" = X"YES" ]; then 322 echo -n ' printer'; ${lpd_program} ${lpd_flags} 323fi 324 325if [ "X${sendmail_enable}" = X"YES" -a -r /etc/sendmail.cf ]; then 326 echo -n ' sendmail'; /usr/sbin/sendmail ${sendmail_flags} 327fi 328 329if [ "X${usbd_enable}" = X"YES" ]; then 330 echo -n ' usbd'; /usr/sbin/usbd ${usbd_flags} 331fi 332 333echo '.' 334 335# configure implementation specific stuff 336arch=`uname -m` 337if [ -f /etc/rc.${arch} ]; then 338 . /etc/rc.${arch} 339fi 340 341# Recover vi editor files. 342vibackup=`echo /var/tmp/vi.recover/vi.*` 343if [ "$vibackup" != '/var/tmp/vi.recover/vi.*' ]; then 344 echo 'Recovering vi editor sessions' 345 for i in $vibackup; do 346 # Only test files that are readable. 347 if test ! -r $i; then 348 continue 349 fi 350 351 # Unmodified nvi editor backup files either have the 352 # execute bit set or are zero length. Delete them. 353 if test -x $i -o ! -s $i; then 354 rm -f $i 355 fi 356 done 357 358 # It is possible to get incomplete recovery files, if the editor 359 # crashes at the right time. 360 virecovery=`echo /var/tmp/vi.recover/recover.*` 361 if [ "$virecovery" != "/var/tmp/vi.recover/recover.*" ]; then 362 for i in $virecovery; do 363 # Only test files that are readable. 364 if test ! -r $i; then 365 continue 366 fi 367 368 # Delete any recovery files that are zero length, 369 # corrupted, or that have no corresponding backup file. 370 # Else send mail to the user. 371 recfile=`awk '/^X-vi-recover-path:/{print $2}' < $i` 372 if test -n "$recfile" -a -s "$recfile"; then 373 sendmail -t < $i 374 else 375 rm -f $i 376 fi 377 done 378 fi 379fi 380 381# make a bounds file for msgs(1) if there isn't one already 382if [ ! -f /var/msgs/bounds ]; then 383 echo 0 > /var/msgs/bounds 384fi 385 386# for each valid dir in $local_startup, search for init scripts matching *.sh 387if [ "X${local_startup}" != X"NO" ]; then 388 echo -n 'Local package initialization:' 389 for dir in ${local_startup}; do 390 [ -d ${dir} ] && for script in ${dir}/*.sh; do 391 [ -x ${script} ] && (set -T ; trap 'exit 1' 2 ; ${script} start) 392 done 393 done 394 echo . 395fi 396 397if [ "X${update_motd}" != X"NO" ]; then 398 T=/tmp/_motd 399 rm -f $T 400 uname -v | sed -e 's,^\([^#]*\) #\(.* [1-2][0-9][0-9][0-9]\).*/\([^\]*\) $,\1 (\3) #\2,' > $T 401 awk '{if (NR == 1) {if ($1 == "FreeBSD") {next} else {print "\n"$0}} else {print}}' < /etc/motd >> $T 402 cp $T /etc/motd 403 chmod 644 /etc/motd 404 rm -f $T 405fi 406 407# Run rc.devfs if present to customify devfs 408[ -f /etc/rc.devfs ] && sh /etc/rc.devfs 409 410# Do traditional (but rather obsolete) rc.local file if it exists. If you 411# use this file and want to make it programmatic, source /etc/defaults/rc.conf 412# in /etc/rc.local and add your custom variables to /etc/rc.conf, as 413# shown below. Please do not put local extensions into /etc/rc itself. 414# Use /etc/rc.local 415# 416# ---- rc.local ---- 417# if [ -f /etc/defaults/rc.conf ]; then 418# . /etc/defaults/rc.conf 419# fi 420# 421# ... additional startup conditionals ... 422# ---- rc.local ---- 423# 424if [ -f /etc/rc.local ]; then 425 echo -n 'starting local daemons:' 426 sh /etc/rc.local 427 echo '.' 428fi 429 430# Raise kernel security level. This should be done only after `fsck' has 431# repaired local file systems if you want the securelevel to be greater than 1. 432if [ "X${kern_securelevel_enable}" = X"YES" -a "${kern_securelevel}" -ge 0 ]; 433then 434 echo 'Raising kernel security level' 435 sysctl -w kern.securelevel=${kern_securelevel} 436fi 437 438date 439exit 0 440