rc revision 43803
1#!/bin/sh 2# $Id: rc,v 1.176 1999/02/09 05:20:46 dillon 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/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/rc.conf ]; then 38 . /etc/rc.conf 39fi 40 41# Configure ccd devices. 42if [ -f /etc/ccd.conf ]; then 43 ccdconfig -C 44fi 45 46if [ -n "$vinum_drives" ]; then 47 vinum read $vinum_drives 48fi 49 50swapon -a 51 52if [ $1x = autobootx ]; then 53 echo Automatic reboot in progress... 54 fsck -p 55 case $? in 56 0) 57 ;; 58 2) 59 exit 1 60 ;; 61 4) 62 reboot 63 echo "reboot failed... help!" 64 exit 1 65 ;; 66 8) 67 echo "Automatic file system check failed... help!" 68 exit 1 69 ;; 70 12) 71 echo "Reboot interrupted" 72 exit 1 73 ;; 74 130) 75 # interrupt before catcher installed 76 exit 1 77 ;; 78 *) 79 echo "Unknown error in reboot" 80 exit 1 81 ;; 82 esac 83else 84 echo Skipping disk checks ... 85fi 86 87trap "echo 'Reboot interrupted'; exit 1" 3 88 89# root normally must be read/write, but if this is a BOOTP NFS 90# diskless boot it does not have to be. 91# 92 93if [ "X$root_rw_mount" != "XNO" ]; then 94 mount -u -o rw / 95fi 96 97if [ $? != 0 ]; then 98 echo "Filesystem mount failed, startup aborted" 99 exit 1 100fi 101 102umount -a >/dev/null 2>&1 103 104if [ "X$early_nfs_mounts" != "XYES" ]; then 105 mount -a -t nonfs 106else 107 mount -a 108fi 109if [ $? != 0 ]; then 110 echo "Filesystem mount failed, startup aborted" 111 exit 1 112fi 113 114# Run custom disk mounting function here 115# 116 117if [ "X$diskless_mount" != "X" ]; then 118 if [ -f $diskless_mount ]; then 119 sh $diskless_mount 120 fi 121fi 122 123# If old file exists, whine until they fix it. 124if [ -f /etc/sysconfig ]; then 125 echo "Warning: /etc/sysconfig has been replaced by /etc/rc.conf." 126 echo "You should switch to /etc/rc.conf ASAP to eliminate this warning." 127fi 128 129adjkerntz -i 130 131clean_var() { 132 if [ ! -f /var/run/clean_var ]; then 133 rm -rf /var/run/* 134 rm -f /var/spool/lock/* 135 rm -rf /var/spool/uucp/.Temp/* 136 # Keep a copy of the boot messages around 137 dmesg >/var/run/dmesg.boot 138 # And an initial utmp file 139 (cd /var/run && cp /dev/null utmp && chmod 644 utmp; ) 140 >/var/run/clean_var 141 fi 142} 143 144if [ -d /var/run -a -d /var/spool/lock -a -d /var/spool/uucp/.Temp ]; then 145 # network_pass1() *may* end up writing stuff to /var - we don't want to 146 # remove it immediately afterwards - *nor* to we want to fail to clean 147 # an nfs-mounted /var. 148 clean_var 149fi 150 151# Add additional swapfile, if configured. 152if [ "x$swapfile" != "xNO" -a -w "$swapfile" -a -b /dev/vn0b ]; then 153 echo "Adding $swapfile as additional swap." 154 vnconfig /dev/vn0b $swapfile && swapon /dev/vn0b 155fi 156 157# configure serial devices 158if [ -f /etc/rc.serial ]; then 159 . /etc/rc.serial 160fi 161 162# start up PC-card configuration 163if [ -f /etc/rc.pccard ]; then 164 . /etc/rc.pccard 165fi 166 167# start up the initial network configuration. 168if [ -f /etc/rc.network ]; then 169 . /etc/rc.network # We only need to do this once. 170 network_pass1 171fi 172 173echo -n "Mounting NFS file systems" 174mount -a -t nfs 175echo . 176 177# Whack the pty perms back into shape. 178chmod 666 /dev/tty[pqrsPQRS]* 179 180# clean up left-over files 181clean_var # If it hasn't already been done 182rm /var/run/clean_var 183 184# 185# Clearing /tmp at boot-time seems to have a long tradition. It doesn't 186# help in any way for long-living systems, and it might accidentally 187# clobber files you would rather like to have preserved after a crash 188# (if not using mfs /tmp anyway). 189# 190# See also the example of another cleanup policy in /etc/periodic/daily. 191# 192if [ "X${clear_tmp_enable}" = X"YES" ]; then 193 echo clearing /tmp 194 195 # prune quickly with one rm, then use find to clean up /tmp/[lq]* 196 # (not needed with mfs /tmp, but doesn't hurt there...) 197 (cd /tmp && rm -rf [a-km-pr-zA-Z]* && 198 find -d . ! -name . ! -name lost+found ! -name quotas -exec rm -rf -- {} \;) 199 200fi 201 202# Remove X lock files, since they will prevent you from restarting X11 203# after a system crash. 204rm -f /tmp/.X*-lock /tmp/.X11-unix/* 205 206# snapshot any kernel -c changes back to disk here <someday> 207# this has changed with ELF and /kernel.config. 208 209echo -n 'additional daemons:' 210# start system logging and name service (named needs to start before syslogd 211# if you don't have a /etc/resolv.conf) 212# 213if [ "X${syslogd_enable}" = X"YES" ]; then 214 # Transitional symlink (for the next couple of years :) until all 215 # binaries had a chance to move towards /var/run/log. 216 if [ ! -h /dev/log ] ; then 217 # might complain for r/o root f/s 218 ln -sf /var/run/log /dev/log 219 fi 220 221 rm -f /var/run/log 222 echo -n ' syslogd'; syslogd ${syslogd_flags} 223fi 224echo '.' 225 226# enable dumpdev so that savecore can see it 227# /var/crash should be a directory or a symbolic link 228# to the crash directory if core dumps are to be saved. 229if [ "X${dumpdev}" != X"NO" -a -e ${dumpdev} -a -d /var/crash ]; then 230 dumpon ${dumpdev} 231 echo -n checking for core dump... 232 savecore /var/crash 233fi 234 235if [ -n "$network_pass1_done" ]; then 236 network_pass2 237fi 238 239# Check the quotas (must be after ypbind if using NIS) 240if [ "X${check_quotas}" = X"YES" ]; then 241 echo -n 'checking quotas:' 242 quotacheck -a 243 echo ' done.' 244 quotaon -a 245fi 246 247if [ -n "$network_pass2_done" ]; then 248 network_pass3 249fi 250 251 252# build ps databases 253kvm_mkdb 254dev_mkdb 255 256# check the password temp/lock file 257if [ -f /etc/ptmp ] 258then 259 logger -s -p auth.err \ 260 "password file may be incorrect -- /etc/ptmp exists" 261fi 262 263if [ "X${accounting_enable}" = X"YES" -a -d /var/account ]; then 264 echo 'turning on accounting' 265 if [ ! -e /var/account/acct ]; then 266 touch /var/account/acct 267 fi 268 accton /var/account/acct 269fi 270 271# Make shared lib searching a little faster. Leave /usr/lib first if you 272# add your own entries or you may come to grief. 273if [ -x /sbin/ldconfig ]; then 274 if [ X"`/usr/bin/objformat`" = X"elf" ]; then 275 _LDC=/usr/lib 276 for i in $ldconfig_paths; do 277 if test -d $i; then 278 _LDC="${_LDC} $i" 279 fi 280 done 281 echo 'setting ELF ldconfig path:' ${_LDC} 282 ldconfig -elf ${_LDC} 283 fi 284 285 # Legacy aout support for i386 only 286 if [ X"`sysctl -n hw.machine`" = X"i386" ]; then 287 # Default the a.out ldconfig path, in case the system's 288 # /etc/rc.conf hasn't been updated. 289 : ${ldconfig_paths_aout=${ldconfig_paths}} 290 _LDC=/usr/lib/aout 291 for i in $ldconfig_paths_aout; do 292 if test -d $i; then 293 _LDC="${_LDC} $i" 294 fi 295 done 296 echo 'setting a.out ldconfig path:' ${_LDC} 297 ldconfig -aout ${_LDC} 298 fi 299fi 300 301# Now start up miscellaneous daemons that don't belong anywhere else 302# 303echo -n starting standard daemons: 304if [ "X${inetd_enable}" != X"NO" ]; then 305 echo -n ' inetd'; inetd ${inetd_flags} 306fi 307 308if [ "X${cron_enable}" != X"NO" ]; then 309 echo -n ' cron'; cron 310fi 311 312if [ "X${lpd_enable}" = X"YES" ]; then 313 echo -n ' printer'; lpd ${lpd_flags} 314fi 315 316if [ "X${sendmail_enable}" = X"YES" -a -r /etc/sendmail.cf ]; then 317 echo -n ' sendmail'; /usr/sbin/sendmail ${sendmail_flags} 318fi 319 320if [ "X${usbd_enable}" = X"YES" ]; then 321 echo -n ' usbd'; /usr/sbin/usbd ${usbd_flags} 322fi 323 324echo '.' 325 326# configure implementation specific stuff 327arch=`uname -m` 328if [ -f /etc/rc.${arch} ]; then 329 . /etc/rc.${arch} 330fi 331 332# 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