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