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