rc revision 1.136
1# $NetBSD: rc,v 1.136 1999/11/15 20:04:50 fvdl Exp $ 2# originally from: @(#)rc 8.2 (Berkeley) 3/17/94 3 4# System startup script run by init on autoboot 5# or after single-user. 6# Output and error are redirected to console by init, 7# and the console is the controlling terminal. 8 9stty status '^T' 10 11# Set shell to ignore SIGINT (2), but not children; 12# shell catches SIGQUIT (3) and returns to single user after fsck. 13trap : 2 14trap : 3 # shouldn't be needed 15 16export HOME=/ 17export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin 18 19# Configure ccd devices. 20if [ -f /etc/ccd.conf ]; then 21 ccdconfig -C 22fi 23 24# Configure raid devices. 25for dev in 0 1 2 3; do 26 if [ -f /etc/raid$dev.conf ]; then 27 raidctl -c /etc/raid$dev.conf raid$dev 28 fi 29done 30 31# Add all block-type swap devices; these might be necessary 32# during disk checks. 33swapctl -A -t blk 34 35if [ -e /fastboot ]; then 36 echo "Fast boot: skipping disk checks." 37elif [ "$1" = autoboot ]; then 38 echo "Automatic boot in progress: starting file system checks." 39 fsck -p 40 case $? in 41 0) 42 ;; 43 2) 44 exit 1 45 ;; 46 4) 47 echo "Rebooting..." 48 reboot 49 echo "Reboot failed; help!" 50 exit 1 51 ;; 52 8) 53 echo "Automatic file system check failed; help!" 54 exit 1 55 ;; 56 12) 57 echo "Boot interrupted." 58 exit 1 59 ;; 60 130) 61 # interrupt before catcher installed 62 exit 1 63 ;; 64 *) 65 echo "Unknown error; help!" 66 exit 1 67 ;; 68 esac 69fi 70 71trap "echo 'Boot interrupted.'; exit 1" 3 72 73umount -a >/dev/null 2>&1 74mount / 75rm -f /fastboot # XXX (root now writeable) 76 77if [ -f /etc/rc.subr ]; then 78 . /etc/rc.subr 79else 80 echo "Can't read /etc/rc.subr; aborting." 81 exit 1; 82fi 83 84if [ -f /etc/rc.conf ]; then 85 . /etc/rc.conf 86fi 87 88if ! checkyesno rc_configured; then 89 echo "/etc/rc.conf is not configured. Multiuser boot aborted." 90 exit 1 91fi 92 93# set flags on ttys. (do early, in case they use tty for SLIP in netstart) 94echo 'setting tty flags' 95ttyflags -a 96 97# load kernel modules specified in /etc/lkm.conf if the /usr filesystem 98# is already present with "/" or can be mounted now 99if checkyesno lkm && [ -f /etc/rc.lkm ]; then 100 mount /usr >/dev/null 2>&1 101 if [ -x /usr/bin/ld ]; then 102 lkmstage=BEFORENET 103 . /etc/rc.lkm 104 fi 105fi 106 107mount_critical_filesystems local 108 109if [ -e /etc/etc.current ] ; then 110 if [ -h /etc/etc.default ] ; then 111 def=`ls -ld /etc/etc.default 2>&1` 112 default=`expr "$def" : '.*-> etc\.\(.*\)' 2>&1` 113 else 114 default=current 115 fi 116 spc="" 117 conflist=`cd /etc; ls -1d etc.* 2>&1 | egrep -v 'current|default'` 118 for i in $conflist; do 119 name=`expr $i : 'etc\.\(.*\)' 2>&1` 120 if [ $name = $default ] ; then 121 echo -n "${spc}[${name}]" 122 else 123 echo -n "${spc}${name}" 124 fi 125 spc=" " 126 done 127 echo 128 master=$$ 129 conf=/etc/passwd 130 while [ ! -d /etc/etc.$conf ] ; do 131 trap 'conf=$default; echo; echo Using default of $conf' 14 132 echo -n "Which configuration [$default] ? " 133 (sleep 30 && kill -ALRM $master) >/dev/null 2>&1 & 134 read conf 135 trap "" 14 136 if [ -z $conf ] ; then 137 conf=$default 138 fi 139 if [ ! -d /etc/etc.$conf -a ! -h /etc/etc.$conf ] ; then 140 conf=/etc/passwd 141 fi 142 done 143 rm -f /etc/etc.current 144 ln -s /etc/etc.$conf /etc/etc.current 145 if [ -f /etc/rc.conf ] ; then 146 . /etc/rc.conf 147 fi 148fi 149 150# set hostname, turn on network 151echo 'starting network' 152sh /etc/netstart 153if [ $? -ne 0 ]; then 154 exit 1 155fi 156 157mount_critical_filesystems network 158 159# Network Address Translation... 160if checkyesno ipnat && [ -f /etc/ipnat.conf ]; then 161 echo 'installing NAT rules ... ' 162 if ! checkyesno ipfilter || [ ! -f /etc/ipf.conf ]; then 163 ipf -E -Fa 164 fi 165 ipnat -F -f /etc/ipnat.conf 166fi 167 168# "Critical" file systems are now mounted. Go ahead and swap 169# to files now, since they will be residing in the critical file 170# systems (or, at least, better). 171swapctl -A -t noblk 172 173# Check for no swap, and warn about it unless that is desired. 174if ! checkyesno no_swap; then 175 swapctl -s | grep 'no swap devices configured' > /dev/null && \ 176 echo "WARNING: no swap space configured!" 177fi 178 179# clean up left-over files 180rm -f /etc/nologin 181rm -f /var/spool/lock/LCK.* 182rm -f /var/spool/uucp/STST/* 183(cd /var/run && { rm -rf -- *; install -c -m 664 -g utmp /dev/null utmp; }) 184 185# build ps databases 186echo 'building databases...' 187# if this kernel supports machdep.booted_kernel, use that to build the KVM 188# db so dmesg will run work when we boot /netbsd.new, etc. 189sysctl machdep 2>/dev/null | grep -q booted_kernel 190if [ $? -eq 0 ] ; then 191 kvm_mkdb `sysctl -n machdep.booted_kernel` 192 if [ $? -ne 0 ] ; then 193 kvm_mkdb /netbsd 194 fi 195else 196 kvm_mkdb /netbsd 197fi 198dev_mkdb 199 200# get the system dmesg output, hopefully containing the boot messages 201# $dmesg_flags is imported from /etc/rc.conf 202if checkyesno dmesg; then 203 dmesg $dmesg_flags > /var/run/dmesg.boot 204fi 205 206if checkyesno wscons && [ -f /etc/rc.wscons ]; then 207 echo 'configuring wscons' 208 /bin/sh /etc/rc.wscons $wscons_flags 209fi 210 211# start the system logger first, so that all messages from daemons 212# are logged, then start savecore to get a dump on low memory systems 213# and then start the name server. 214 215if checkyesno syslogd; then 216 echo 'starting system logger' 217 # Transitional symlink for old binaries 218 if [ ! -h /dev/log ] ; then 219 ln -sf /var/run/log /dev/log 220 fi 221 rm -f /var/run/log 222 syslogd $syslogd_flags 223fi 224 225# Enable ipmon (only useful if ipfilter is running) 226# NOTE: requires the IPFILTER_LOG kernel option. 227if checkyesno ipmon; then 228 echo 'starting ipmon' 229 ipmon $ipmon_flags & 230fi 231 232# /var/crash should be a directory or a symbolic link 233# to the crash directory if core dumps are to be saved. 234if checkyesno savecore; then 235 if [ -d /var/crash/. ]; then 236 echo checking for core dump... 237 savecore $savecore_flags /var/crash 238 else 239 logger -s "WARNING: no /var/crash directory; savecore not run." 240 fi 241fi 242 243if checkyesno named; then 244 echo 'starting name server'; named $named_flags 245fi 246 247# set time, if requested 248if checkyesno ntpdate; then 249 if [ -z "$ntpdate_hosts" ]; then 250 ntpdate_hosts=`awk ' 251 /^server[ \t]*127.127/ {next} 252 /^(server|peer)/ {print $2} 253 ' </etc/ntp.conf` 254 fi 255 if [ -n "$ntpdate_hosts" ]; then 256 echo 'Setting date via ntp.' 257 ntpdate -b -s $ntpdate_hosts 258 fi 259fi 260 261# now start the rpc servers, for YP server/client. 262echo -n 'starting rpc daemons:' 263 264# note that portmap is generally required for all other rpc services. 265if checkyesno portmap; then 266 echo -n ' portmap'; portmap $portmap_flags 267fi 268 269if checkyesno ypserv; then 270 echo -n ' ypserv'; ypserv $ypserv_flags 271fi 272 273if checkyesno ypbind; then 274 echo -n ' ypbind'; ypbind $ypbind_flags 275fi 276 277if checkyesno yppasswdd; then 278 echo -n ' rpc.yppasswdd'; rpc.yppasswdd $yppasswdd_flags 279fi 280 281if checkyesno bootparamd; then 282 if [ -r /etc/bootparams ]; then 283 echo -n ' rpc.bootparamd'; rpc.bootparamd $bootparamd_flags 284 else 285 echo 286 logger -s "WARNING: /etc/bootparams not found. " \ 287 "bootparamd not started." 288 fi 289fi 290 291echo '.' 292 293# load kernel modules specified in /etc/lkm.conf 294if checkyesno lkm; then 295 if [ -r /etc/rc.lkm ]; then 296 lkmstage=BEFOREMOUNT 297 . /etc/rc.lkm 298 else 299 logger -s "WARNING: /etc/rc.lkm not found; LKMs not loaded." 300 fi 301fi 302 303mount -a 304 305# now start the rpc servers, for NFS server/client. 306if checkyesno nfs_client || checkyesno nfs_server; then 307 echo -n 'starting nfs daemons:' 308 309 nfs_locking=NO 310 311 if checkyesno nfs_server; then 312 if [ -r /etc/exports ]; then 313 rm -f /var/db/mountdtab 314 echo -n > /var/db/mountdtab 315 echo -n ' mountd'; mountd $mountd_flags 316 echo -n ' nfsd'; nfsd $nfsd_flags 317 nfs_locking=YES 318 else 319 echo 320 logger -s "WARNING: /etc/exports not readable; " \ 321 "NFS server not started." 322 fi 323 fi 324 325 if checkyesno nfs_client; then 326 echo -n ' nfsiod'; nfsiod $nfsiod_flags 327 nfs_locking=YES 328 fi 329 330 if checkyesno nfs_locking; then 331 if checkyesno statd; then 332 echo -n ' rpc.statd'; rpc.statd $statd_flags 333 fi 334 if checkyesno lockd; then 335 echo -n ' rpc.lockd'; rpc.lockd $lockd_flags 336 fi 337 fi 338 339 if checkyesno amd; then 340 if [ -d "$amd_dir" ]; then 341 if [ -r "$amd_master" ]; then 342 echo -n ' amd' 343 amd $amd_flags -p -a $amd_dir \ 344 `sed s/#.*$// <$amd_master` >/var/run/amd.pid 345 else 346 echo 347 logger -s "WARNING: \$amd_master ($amd_master)not " \ 348 "readable; amd not started." 349 fi 350 else 351 echo 352 logger -s "WARNING: \$amd_dir ($amd_dir) not a directory; " \ 353 "amd not started." 354 fi 355 fi 356 echo '.' 357fi 358 359 360if [ -f /sbin/ldconfig ]; then 361 echo 'creating runtime link editor directory cache.' 362 ldconfig 363fi 364 365# load kernel modules specified in /etc/lkm.conf 366if checkyesno lkm && [ -f /etc/rc.lkm ]; then 367 lkmstage=AFTERMOUNT 368 . /etc/rc.lkm 369fi 370 371# if $defcorename is set, change it here. 372if [ -n "$defcorename" ]; then 373 echo -n 'setting default core name template: ' 374 sysctl -w kern.defcorename=$defcorename 375fi 376 377# if $securelevel is set, change it here, else if it is 0, change 378# it to 1 here, before we start login services. 379if [ -n "$securelevel" ]; then 380 echo -n 'setting securelevel: ' 381 sysctl -w kern.securelevel=$securelevel 382else 383 securelevel=`sysctl -n kern.securelevel` 384 if [ x"$securelevel" = x0 ]; then 385 echo -n 'setting securelevel: ' 386 sysctl -w kern.securelevel=1 387 fi 388fi 389 390echo -n 'checking quotas:'; quotacheck -a; echo ' done.' 391quotaon -a 392 393chmod 666 /dev/tty[pqrs]* 394 395# check the password temp/lock file 396if [ -f /etc/ptmp ] 397then 398 logger -s -p auth.err \ 399 'password file may be incorrect -- /etc/ptmp exists' 400fi 401 402# XXX replace me with a script that works! 403virecovery=`echo /var/tmp/vi.recover/recover.*` 404if [ "$virecovery" != "/var/tmp/vi.recover/recover.*" ]; then 405 echo preserving editor files 406 for i in $virecovery; do 407 if [ -f $i ]; then 408 sendmail -t < $i 409 fi 410 done 411fi 412 413echo clearing /tmp 414 415# Prune quickly with one rm, then use find to clean up /tmp/[lq]* (this 416# is not needed with mfs /tmp, but doesn't hurt anything). 417(cd /tmp && rm -rf [a-km-pr-zA-Z]* && 418 find . ! -name . ! -name lost+found ! -name quota.user \ 419 ! -name quota.group -exec rm -rf -- {} \; -type d -prune) 420 421# Update kernel info in /etc/motd 422# Must be done *before* interactive logins are possible to prevent 423# possible race conditions. 424if checkyesno update_motd; then 425 echo 'updating motd.' 426 if [ ! -f /etc/motd ]; then 427 install -c -o root -g wheel -m 664 /dev/null /etc/motd 428 fi 429 T=/etc/_motd 430 rm -f $T 431 sysctl -n kern.version | sed 1q > $T 432 echo "" >> $T 433 sed '1,/^$/d' < /etc/motd >> $T 434 cmp -s $T /etc/motd || cp $T /etc/motd 435 rm -f $T 436fi 437 438if [ -f /var/account/acct ]; then 439 echo 'turning on accounting'; accton /var/account/acct 440fi 441 442echo -n standard daemons: 443if checkyesno cron; then 444 echo -n ' cron'; cron 445fi 446echo '.' 447 448# now start all the other daemons 449echo -n starting network daemons: 450 451if checkyesno gated && checkyesno routed; then 452 echo 453 logger -s "WARNING: gated and routed both requested to be run: " \ 454 "running only gated." 455 routed=NO 456fi 457 458if checkyesno gated; then 459 if [ -r /etc/gated.conf ]; then 460 echo -n ' gated'; gated $gated_flags 461 else 462 logger -s "WARNING: no /etc/gated.conf; gated not started." 463 fi 464fi 465 466if checkyesno routed; then 467 echo -n ' routed'; routed $routed_flags 468fi 469 470if checkyesno mrouted; then 471 echo -n ' mrouted'; mrouted $mrouted_flags 472fi 473 474if checkyesno route6d; then 475 echo -n ' route6d'; route6d $route6d_flags 476fi 477 478if checkyesno rtsold; then 479 if checkyesno ip6forwarding; then 480 logger -s "WARNING: rtsold cannot be used on IPv6 router." 481 else 482 echo -n ' rtsold'; rtsold $rtsold_flags 483 fi 484fi 485 486if checkyesno rtadvd; then 487 if checkyesno ip6forwarding; then 488 echo -n ' rtadvd'; rtadvd $rtadvd_flags 489 else 490 logger -s "WARNING: rtadvd cannot be used on IPv6 host." 491 fi 492fi 493 494if checkyesno timed; then 495 echo -n ' timed'; timed $timed_flags 496fi 497 498if checkyesno xntpd; then 499 echo -n ' xntpd'; xntpd $xntpd_flags 500fi 501 502if checkyesno dhcpd; then 503 if [ -r /etc/dhcpd.conf ]; then 504 echo -n ' dhcpd'; dhcpd $dhcpd_flags 505 else 506 echo 507 logger -s "WARNING: /etc/dhcpd.conf not readable; " \ 508 "dhcpd not started." 509 fi 510elif checkyesno dhcrelay; then 511 echo -n ' dhcrelay'; dhcrelay $dhcrelay_flags 512fi 513 514if checkyesno rwhod; then 515 echo -n ' rwhod'; rwhod 516fi 517 518if checkyesno lpd; then 519 echo -n ' lpd'; lpd $lpd_flags 520fi 521 522# We call sendmail with a full path so that SIGHUP works. 523if checkyesno sendmail; then 524 if [ -r /etc/sendmail.cf ]; then 525 echo -n ' sendmail'; /usr/sbin/sendmail $sendmail_flags 526 else 527 echo 528 logger -s "WARNING: /etc/sendmail.cf not readable; " \ 529 "sendmail not started." 530 fi 531fi 532 533# Start xfs before boot daemons, so its ready before client xterminals. 534if checkyesno xfs; then 535 echo -n ' xfs'; xfs $xfs_flags & 536 sleep 2 537fi 538 539if checkyesno rarpd; then 540 if [ -r /etc/ethers ]; then 541 echo -n ' rarpd'; rarpd $rarpd_flags 542 else 543 echo 544 logger -s "WARNING: /etc/ethers not readable; " \ 545 "rarpd not started." 546 fi 547fi 548 549if checkyesno rbootd; then 550 if [ -r /etc/rbootd.conf ]; then 551 echo -n ' rbootd'; rbootd $rbootd_flags 552 else 553 echo 554 logger -s "WARNING: /etc/rbootd.conf not readable; " \ 555 "rbootd not started." 556 fi 557fi 558 559if checkyesno mopd; then 560 echo -n ' mopd'; mopd $mopd_flags 561fi 562 563if checkyesno apmd; then 564 echo -n ' apmd'; apmd $apmd_flags 565fi 566 567if checkyesno screenblank; then 568 echo -n ' screenblank'; screenblank $screenblank_flags 569fi 570 571if checkyesno inetd; then 572 if [ -r /etc/inetd.conf ]; then 573 echo -n ' inetd'; inetd $inetd_flags 574 else 575 echo 576 logger -s "WARNING: /etc/inetd.conf not readable; " \ 577 "inetd not started." 578 fi 579fi 580 581echo '.' 582 583# Kerberos runs ONLY on the Kerberos server machine 584if checkyesno kerberos; then 585 echo -n 'starting kerberos daemons:' 586 echo -n ' kerberos'; kerberos >> /var/log/kerberos.log & 587 echo -n ' kadmind'; kadmind -n >> /var/log/kadmind.log & 588 echo '.' 589fi 590 591# xdm after wscons - need a virtual screen for X 592if checkyesno xdm; then 593 echo 'starting xdm' 594 xdm $xdm_flags 595fi 596 597. /etc/rc.local 598 599date 600exit 0 601