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