rc revision 56969
133965Sjdp#!/bin/sh 233965Sjdp# $FreeBSD: head/etc/rc 56969 2000-02-03 06:06:36Z nsayer $ 333965Sjdp# From: @(#)rc 5.27 (Berkeley) 6/5/91 433965Sjdp 533965Sjdp# System startup script run by init on autoboot 633965Sjdp# or after single-user. 733965Sjdp# Output and error are redirected to console by init, 833965Sjdp# and the console is the controlling terminal. 933965Sjdp 1033965Sjdp# Note that almost all of the user-configurable behavior is no longer in 1133965Sjdp# this file, but rather in /etc/defaults/rc.conf. Please check that file 1233965Sjdp# first before contemplating any changes here. If you do need to change 1333965Sjdp# this file for some reason, we would like to know about it. 1433965Sjdp 1533965Sjdpstty status '^T' 1633965Sjdp 1733965Sjdp# Set shell to ignore SIGINT (2), but not children; 1833965Sjdp# shell catches SIGQUIT (3) and returns to single user after fsck. 1933965Sjdp# 2033965Sjdptrap : 2 2133965Sjdptrap : 3 # shouldn't be needed 2233965Sjdp 2333965SjdpHOME=/ 2433965SjdpPATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin 2533965Sjdpexport HOME PATH 2633965Sjdp 2733965Sjdp# BOOTP diskless boot. We have to run the rc file early in order to 2833965Sjdp# retarget various config files. 2933965Sjdp# 3033965Sjdpif [ -r /etc/rc.diskless1 ]; then 3133965Sjdp dlv=`/sbin/sysctl -n vfs.nfs.diskless_valid 2> /dev/null` 3233965Sjdp if [ ${dlv:=0} != 0 ]; then 3333965Sjdp . /etc/rc.diskless1 3433965Sjdp fi 3533965Sjdpfi 3633965Sjdp 3733965Sjdp# If there is a global system configuration file, suck it in. 3833965Sjdp# 3933965Sjdpif [ -r /etc/defaults/rc.conf ]; then 4033965Sjdp . /etc/defaults/rc.conf 4133965Sjdpelif [ -r /etc/rc.conf ]; then 4233965Sjdp . /etc/rc.conf 4333965Sjdpfi 4433965Sjdp 4533965Sjdp# Configure ccd devices. 4633965Sjdp# 4733965Sjdpif [ -r /etc/ccd.conf ]; then 4833965Sjdp ccdconfig -C 4933965Sjdpfi 5033965Sjdp 5133965Sjdpcase ${start_vinum} in 5233965Sjdp[Yy][Ee][Ss]) 5333965Sjdp vinum start 5433965Sjdp ;; 5533965Sjdpesac 5633965Sjdp 5733965Sjdpswapon -a 5833965Sjdp 5933965Sjdpcase $1 in 6033965Sjdpautoboot) 6133965Sjdp echo Automatic reboot in progress... 6233965Sjdp fsck -p 6333965Sjdp case $? in 6433965Sjdp 0) 6533965Sjdp ;; 6633965Sjdp 2) 6733965Sjdp exit 1 6833965Sjdp ;; 6933965Sjdp 4) 7033965Sjdp reboot 7133965Sjdp echo "reboot failed... help!" 7233965Sjdp exit 1 7333965Sjdp ;; 7433965Sjdp 8) 7533965Sjdp echo "Automatic file system check failed... help!" 7633965Sjdp exit 1 7733965Sjdp ;; 7833965Sjdp 12) 7933965Sjdp echo "Reboot interrupted" 8033965Sjdp exit 1 8133965Sjdp ;; 8233965Sjdp 130) 8333965Sjdp # interrupt before catcher installed 8433965Sjdp exit 1 8533965Sjdp ;; 8633965Sjdp *) 8733965Sjdp echo "Unknown error in reboot" 8833965Sjdp exit 1 8933965Sjdp ;; 9033965Sjdp esac 9133965Sjdp ;; 9233965Sjdp*) 9333965Sjdp echo Skipping disk checks ... 9433965Sjdp ;; 9533965Sjdpesac 9633965Sjdp 9733965Sjdpset -T 9833965Sjdptrap "echo 'Reboot interrupted'; exit 1" 3 9933965Sjdp 10033965Sjdp# root normally must be read/write, but if this is a BOOTP NFS 10133965Sjdp# diskless boot it does not have to be. 10233965Sjdp# 10333965Sjdpcase ${root_rw_mount} in 10433965Sjdp[Nn][Oo] | '') 10533965Sjdp ;; 10633965Sjdp*) 10733965Sjdp if ! mount -u -o rw / ; then 10833965Sjdp echo "Mounting root filesystem rw failed, startup aborted" 10933965Sjdp exit 1 11033965Sjdp fi 11133965Sjdp ;; 11233965Sjdpesac 11333965Sjdp 11433965Sjdpumount -a >/dev/null 2>&1 11533965Sjdp 11633965Sjdp# Mount everything except nfs filesystems. 11733965Sjdpmount -a -t nonfs 11833965Sjdp 11933965Sjdpcase $? in 12033965Sjdp0) 12133965Sjdp ;; 12233965Sjdp*) 12333965Sjdp echo "Mounting /etc/fstab filesystems failed, startup aborted" 12433965Sjdp exit 1 12533965Sjdp ;; 12633965Sjdpesac 12733965Sjdp 12833965Sjdp# Run custom disk mounting function here 12933965Sjdp# 13033965Sjdpif [ -n "${diskless_mount}" -a -r "${diskless_mount}" ]; then 13133965Sjdp sh ${diskless_mount} 13233965Sjdpfi 13333965Sjdp 13433965Sjdpadjkerntz -i 13533965Sjdp 13633965Sjdpclean_var() { 13733965Sjdp if [ ! -f /var/run/clean_var ]; then 13833965Sjdp rm -rf /var/run/* 13933965Sjdp rm -f /var/spool/lock/* 14033965Sjdp rm -rf /var/spool/uucp/.Temp/* 14133965Sjdp # Keep a copy of the boot messages around 14233965Sjdp dmesg >/var/run/dmesg.boot 14333965Sjdp # And an initial utmp file 14433965Sjdp (cd /var/run && cp /dev/null utmp && chmod 644 utmp;) 14533965Sjdp >/var/run/clean_var 14633965Sjdp fi 14733965Sjdp} 14833965Sjdp 14933965Sjdpif [ -d /var/run -a -d /var/spool/lock -a -d /var/spool/uucp/.Temp ]; then 15033965Sjdp # network_pass1() *may* end up writing stuff to /var - we don't want to 15133965Sjdp # remove it immediately afterwards - *nor* to we want to fail to clean 15233965Sjdp # an nfs-mounted /var. 15333965Sjdp clean_var 15433965Sjdpfi 15533965Sjdp 15633965Sjdp# Add additional swapfile, if configured. 15733965Sjdp# 15833965Sjdpcase ${swapfile} in 159[Nn][Oo] | '') 160 ;; 161*) 162 if [ -w "${swapfile}" -a -c /dev/vn0b ]; then 163 echo "Adding ${swapfile} as additional swap." 164 vnconfig /dev/vn0b ${swapfile} && swapon /dev/vn0b 165 fi 166 ;; 167esac 168 169# Set sysctl variables as early as we can 170# 171if [ -r /etc/rc.sysctl ]; then 172 . /etc/rc.sysctl 173fi 174 175# Configure serial devices 176# 177if [ -r /etc/rc.serial ]; then 178 . /etc/rc.serial 179fi 180 181# Start up PC-card configuration 182# 183if [ -r /etc/rc.pccard ]; then 184 . /etc/rc.pccard 185fi 186 187# Start up the initial network configuration. 188# 189if [ -r /etc/rc.network ]; then 190 . /etc/rc.network # We only need to do this once. 191 network_pass1 192fi 193 194# Mount NFS filesystems. 195echo -n "Mounting NFS file systems" 196mount -a -t nfs 197echo . 198 199# Whack the pty perms back into shape. 200# 201chflags 0 /dev/tty[pqrsPQRS]* 202chmod 666 /dev/tty[pqrsPQRS]* 203chown root:wheel /dev/tty[pqrsPQRS]* 204 205# Clean up left-over files 206# 207clean_var # If it hasn't already been done 208rm /var/run/clean_var 209 210# Clearing /tmp at boot-time seems to have a long tradition. It doesn't 211# help in any way for long-living systems, and it might accidentally 212# clobber files you would rather like to have preserved after a crash 213# (if not using mfs /tmp anyway). 214# 215# See also the example of another cleanup policy in /etc/periodic/daily. 216# 217case ${clear_tmp_enable} in 218[Yy][Ee][Ss]) 219 echo clearing /tmp 220 # prune quickly with one rm, then use find to clean up /tmp/[lq]* 221 # (not needed with mfs /tmp, but doesn't hurt there...) 222 (cd /tmp && rm -rf [a-km-pr-zA-Z]* && 223 find -d . ! -name . ! -name lost+found ! -name quota.user \ 224 ! -name quota.group -exec rm -rf -- {} \;) 225 ;; 226esac 227 228# Remove X lock files, since they will prevent you from restarting X11 229# after a system crash. 230# 231rm -f /tmp/.X*-lock /tmp/.X11-unix/* 232 233# Snapshot any kernel -c changes back to disk here <someday>. 234# This has changed with ELF and /kernel.config. 235 236echo -n 'additional daemons:' 237 238# Start system logging and name service. Named needs to start before syslogd 239# if you don't have a /etc/resolv.conf. 240# 241case ${syslogd_enable} in 242[Yy][Ee][Ss]) 243 # Transitional symlink (for the next couple of years :) until all 244 # binaries have had a chance to move towards /var/run/log. 245 if [ ! -h /dev/log ]; then 246 # might complain for r/o root f/s 247 ln -sf /var/run/log /dev/log 248 fi 249 250 rm -f /var/run/log 251 echo -n ' syslogd'; syslogd ${syslogd_flags} 252 ;; 253esac 254 255echo '.' 256 257# Enable dumpdev so that savecore can see it. 258# /var/crash should be a directory or a symbolic link 259# to the crash directory if core dumps are to be saved. 260# 261case ${dumpdev} in 262[Nn][Oo] | '') 263 ;; 264*) 265 if [ -e "${dumpdev}" -a -d /var/crash ]; then 266 dumpon ${dumpdev} 267 echo -n checking for core dump... 268 savecore /var/crash 269 fi 270 ;; 271esac 272 273if [ -n "${network_pass1_done}" ]; then 274 network_pass2 275fi 276 277# Enable/Check the quotas (must be after ypbind if using NIS) 278# 279case ${enable_quotas} in 280[Yy][Ee][Ss]) 281 case ${check_quotas} in 282 [Yy][Ee][Ss]) 283 echo -n 'checking quotas:' 284 quotacheck -a 285 echo ' done.' 286 ;; 287 esac 288 289 echo -n 'enabling quotas:' 290 quotaon -a 291 echo ' done.' 292 ;; 293esac 294 295if [ -n "${network_pass2_done}" ]; then 296 network_pass3 297fi 298 299# Build ps databases 300# 301dev_mkdb 302 303# Check the password temp/lock file 304# 305if [ -e /etc/ptmp ]; then 306 logger -s -p auth.err \ 307 "password file may be incorrect -- /etc/ptmp exists" 308fi 309 310case ${accounting_enable} in 311[Yy][Ee][Ss]) 312 if [ -d /var/account ]; then 313 echo 'turning on accounting' 314 if [ ! -e /var/account/acct ]; then 315 touch /var/account/acct 316 fi 317 accton /var/account/acct 318 fi 319 ;; 320esac 321 322# Make shared lib searching a little faster. Leave /usr/lib first if you 323# add your own entries or you may come to grief. 324# 325if [ -x /sbin/ldconfig ]; then 326 case `/usr/bin/objformat` in 327 elf) 328 _LDC=/usr/lib 329 for i in ${ldconfig_paths}; do 330 if [ -d "${i}" ]; then 331 _LDC="${_LDC} ${i}" 332 fi 333 done 334 echo 'setting ELF ldconfig path:' ${_LDC} 335 ldconfig -elf ${_LDC} 336 ;; 337 esac 338 339 # Legacy aout support for i386 only 340 case `sysctl -n hw.machine` in 341 i386) 342 # Default the a.out ldconfig path. 343 : ${ldconfig_paths_aout=${ldconfig_paths}} 344 _LDC=/usr/lib/aout 345 for i in ${ldconfig_paths_aout}; do 346 if [ -d "${i}" ]; then 347 _LDC="${_LDC} ${i}" 348 fi 349 done 350 echo 'setting a.out ldconfig path:' ${_LDC} 351 ldconfig -aout ${_LDC} 352 ;; 353 esac 354fi 355 356# Now start up miscellaneous daemons that don't belong anywhere else 357# 358echo -n starting standard daemons: 359case ${inetd_enable} in 360[Nn][Oo]) 361 ;; 362*) 363 echo -n ' inetd'; inetd ${inetd_flags} 364 ;; 365esac 366 367case ${cron_enable} in 368[Nn][Oo]) 369 ;; 370*) 371 echo -n ' cron'; cron 372 ;; 373esac 374 375case ${lpd_enable} in 376[Yy][Ee][Ss]) 377 echo -n ' printer'; ${lpd_program:-/usr/sbin/lpd} ${lpd_flags} 378 ;; 379esac 380 381case ${sendmail_enable} in 382[Yy][Ee][Ss]) 383 if [ -r /etc/mail/sendmail.cf ]; then 384 echo -n ' sendmail'; /usr/sbin/sendmail ${sendmail_flags} 385 fi 386 ;; 387esac 388 389case ${usbd_enable} in 390[Yy][Ee][Ss]) 391 echo -n ' usbd'; /usr/sbin/usbd ${usbd_flags} 392 ;; 393esac 394 395echo '.' 396 397# Recover vi editor files. 398find /var/tmp/vi.recover ! -type f -a ! -type d -delete 399vibackup=`echo /var/tmp/vi.recover/vi.*` 400if [ "${vibackup}" != '/var/tmp/vi.recover/vi.*' ]; then 401 echo 'Recovering vi editor sessions' 402 for i in /var/tmp/vi.recover/vi.*; do 403 # Only test files that are readable. 404 if [ ! -r "${i}" ]; then 405 continue 406 fi 407 408 # Unmodified nvi editor backup files either have the 409 # execute bit set or are zero length. Delete them. 410 if [ -x "${i}" -o ! -s "${i}" ]; then 411 rm -f "${i}" 412 fi 413 done 414 415 # It is possible to get incomplete recovery files, if the editor 416 # crashes at the right time. 417 virecovery=`echo /var/tmp/vi.recover/recover.*` 418 if [ "${virecovery}" != "/var/tmp/vi.recover/recover.*" ]; then 419 for i in /var/tmp/vi.recover/recover.*; do 420 # Only test files that are readable. 421 if [ ! -r "${i}" ]; then 422 continue 423 fi 424 425 # Delete any recovery files that are zero length, 426 # corrupted, or that have no corresponding backup file. 427 # Else send mail to the user. 428 recfile=`awk '/^X-vi-recover-path:/{print $2}' < "${i}"` 429 if [ -n "${recfile}" -a -s "${recfile}" ]; then 430 sendmail -t < "${i}" 431 else 432 rm -f "${i}" 433 fi 434 done 435 fi 436fi 437 438# Make a bounds file for msgs(1) if there isn't one already 439# "Delete important files with symlink" security hole? 440# 441if [ -d /var/msgs -a ! -f /var/msgs/bounds ]; then 442 echo 0 > /var/msgs/bounds 443fi 444 445case ${update_motd} in 446[Nn][Oo] | '') 447 ;; 448*) 449 if T=`mktemp /tmp/_motd.XXXXXX`; then 450 uname -v | sed -e 's,^\([^#]*\) #\(.* [1-2][0-9][0-9][0-9]\).*/\([^\]*\) $,\1 (\3) #\2,' > ${T} 451 awk '{if (NR == 1) {if ($1 == "FreeBSD") {next} else {print "\n"$0}} else {print}}' < /etc/motd >> ${T} 452 cmp -s ${T} /etc/motd || { 453 cp ${T} /etc/motd 454 chmod 644 /etc/motd 455 } 456 rm -f ${T} 457 fi 458 ;; 459esac 460 461# Configure implementation specific stuff 462# 463arch=`uname -m` 464if [ -r /etc/rc.${arch} ]; then 465 . /etc/rc.${arch} 466fi 467 468# Run rc.devfs if readable to customize devfs 469# 470if [ -r /etc/rc.devfs ]; then 471 sh /etc/rc.devfs 472fi 473 474# Do traditional (but rather obsolete) rc.local file if it exists. If you 475# use this file and want to make it programmatic, source /etc/defaults/rc.conf 476# in /etc/rc.local and add your custom variables to /etc/rc.conf, as 477# shown below. Please do not put local extensions into /etc/rc itself. 478# Use /etc/rc.local 479# 480# ---- rc.local ---- 481# if [ -r /etc/defaults/rc.conf ]; then 482# . /etc/defaults/rc.conf 483# fi 484# 485# ... additional startup conditionals ... 486# ---- rc.local ---- 487# 488if [ -r /etc/rc.local ]; then 489 echo -n 'starting local daemons:' 490 sh /etc/rc.local 491 echo '.' 492fi 493 494# For each valid dir in $local_startup, search for init scripts matching *.sh 495# 496case ${local_startup} in 497[Nn][Oo] | '') 498 ;; 499*) 500 echo -n 'Local package initialization:' 501 for dir in ${local_startup}; do 502 if [ -d "${dir}" ]; then 503 for script in ${dir}/*.sh; do 504 if [ -x "${script}" ]; then 505 (set -T 506 trap 'exit 1' 2 507 ${script} start) 508 fi 509 done 510 fi 511 done 512 echo . 513 ;; 514esac 515 516if [ -n "${network_pass3_done}" ]; then 517 network_pass4 518fi 519 520# Raise kernel security level. This should be done only after `fsck' has 521# repaired local file systems if you want the securelevel to be greater than 1. 522# 523case ${kern_securelevel_enable} in 524[Yy][Ee][Ss]) 525 if [ "${kern_securelevel}" -ge 0 ]; then 526 echo 'Raising kernel security level' 527 sysctl -w kern.securelevel=${kern_securelevel} 528 fi 529 ;; 530esac 531 532date 533exit 0 534