rc revision 1.131
1# $NetBSD: rc,v 1.131 1999/09/16 11:00:44 darrenr 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 [ "$rc_configured" != YES ]; 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 109# set hostname, turn on network 110echo 'starting network' 111sh /etc/netstart 112if [ $? -ne 0 ]; then 113 exit 1 114fi 115 116mount_critical_filesystems network 117 118# Network Address Translation... 119if checkyesno ipnat && [ -f /etc/ipnat.conf ]; then 120 echo 'installing NAT rules ... ' 121 if ! checkyesno ipfilter || [ ! -f /etc/ipf.conf ]; then 122 ipf -E -Fa 123 fi 124 ipnat -F -f /etc/ipnat.conf 125fi 126 127# "Critical" file systems are now mounted. Go ahead and swap 128# to files now, since they will be residing in the critical file 129# systems (or, at least, better). 130swapctl -A -t noblk 131 132# Check for no swap, and warn about it unless that is desired. 133if ! checkyesno no_swap; then 134 swapctl -s | grep 'no swap devices configured' > /dev/null && \ 135 echo "WARNING: no swap space configured!" 136fi 137 138# clean up left-over files 139rm -f /etc/nologin 140rm -f /var/spool/lock/LCK.* 141rm -f /var/spool/uucp/STST/* 142(cd /var/run && { rm -rf -- *; install -c -m 664 -g utmp /dev/null utmp; }) 143 144# if this kernel supports machdep.booted_kernel, use that to build the KVM 145# db so dmesg will run work when we boot /netbsd.new, etc. 146sysctl machdep | grep -q booted_kernel 147if [ $? -eq 0 ] ; then 148 kvm_mkdb `sysctl -n machdep.booted_kernel` 149fi 150# get the system dmesg output, hopefully containing the boot messages 151# $dmesg_flags is imported from /etc/rc.conf 152if checkyesno dmesg; then 153 dmesg $dmesg_flags > /var/run/dmesg.boot 154fi 155 156if checkyesno wscons && [ -f /etc/rc.wscons ]; then 157 echo 'configuring wscons' 158 /bin/sh /etc/rc.wscons $wscons_flags 159fi 160 161# start the system logger first, so that all messages from daemons 162# are logged, then start savecore to get a dump on low memory systems 163# and then start the name server. 164 165if checkyesno syslogd; then 166 echo 'starting system logger' 167 # Transitional symlink for old binaries 168 if [ ! -h /dev/log ] ; then 169 ln -sf /var/run/log /dev/log 170 fi 171 rm -f /var/run/log 172 syslogd $syslogd_flags 173fi 174 175# Enable ipmon (only useful if ipfilter is running) 176# NOTE: requires the IPFILTER_LOG kernel option. 177if checkyesno ipmon; then 178 echo 'starting ipmon' 179 ipmon $ipmon_flags & 180fi 181 182# /var/crash should be a directory or a symbolic link 183# to the crash directory if core dumps are to be saved. 184if checkyesno savecore; then 185 if [ -d /var/crash/. ]; then 186 echo checking for core dump... 187 savecore $savecore_flags /var/crash 188 else 189 logger -s "WARNING: no /var/crash directory; savecore not run." 190 fi 191fi 192 193if checkyesno named; then 194 echo 'starting name server'; named $named_flags 195fi 196 197# set time, if requested 198if checkyesno ntpdate; then 199 if [ -z "$ntpdate_hosts" ]; then 200 ntpdate_hosts=`awk ' 201 /^server[ \t]*127.127/ {next} 202 /^(server|peer)/ {print $2} 203 ' </etc/ntp.conf` 204 fi 205 if [ -n "$ntpdate_hosts" ]; then 206 echo 'Setting date via ntp.' 207 ntpdate -b -s $ntpdate_hosts 208 fi 209fi 210 211# now start the rpc servers, for YP server/client. 212echo -n 'starting rpc daemons:' 213 214# note that portmap is generally required for all other rpc services. 215if checkyesno portmap; then 216 echo -n ' portmap'; portmap $portmap_flags 217fi 218 219if checkyesno ypserv; then 220 echo -n ' ypserv'; ypserv $ypserv_flags 221fi 222 223if checkyesno ypbind; then 224 echo -n ' ypbind'; ypbind $ypbind_flags 225fi 226 227if checkyesno yppasswdd; then 228 echo -n ' rpc.yppasswdd'; rpc.yppasswdd $yppasswdd_flags 229fi 230 231if checkyesno bootparamd; then 232 if [ -r /etc/bootparams ]; then 233 echo -n ' rpc.bootparamd'; rpc.bootparamd $bootparamd_flags 234 else 235 echo 236 logger -s "WARNING: /etc/bootparams not found. " \ 237 "bootparamd not started." 238 fi 239fi 240 241echo '.' 242 243# load kernel modules specified in /etc/lkm.conf 244if checkyesno lkm; then 245 if [ -r /etc/rc.lkm ]; then 246 lkmstage=BEFOREMOUNT 247 . /etc/rc.lkm 248 else 249 logger -s "WARNING: /etc/rc.lkm not found; LKMs not loaded." 250 fi 251fi 252 253mount -a 254 255# now start the rpc servers, for NFS server/client. 256echo -n 'starting nfs daemons:' 257 258nfs_locking=NO 259 260if checkyesno nfs_server; then 261 if [ -r /etc/exports ]; then 262 rm -f /var/db/mountdtab 263 echo -n > /var/db/mountdtab 264 echo -n ' mountd'; mountd $mountd_flags 265 echo -n ' nfsd'; nfsd $nfsd_flags 266 nfs_locking=YES 267 else 268 echo 269 logger -s "WARNING: /etc/exports not readable; " \ 270 "NFS server not started." 271 fi 272fi 273 274if checkyesno nfs_client; then 275 echo -n ' nfsiod'; nfsiod $nfsiod_flags 276 nfs_locking=YES 277fi 278 279if checkyesno nfs_locking; then 280 if checkyesno statd; then 281 echo -n ' rpc.statd'; rpc.statd $statd_flags 282 fi 283 if checkyesno lockd; then 284 echo -n ' rpc.lockd'; rpc.lockd $lockd_flags 285 fi 286fi 287 288if checkyesno amd; then 289 if [ -d "$amd_dir" ]; then 290 if [ -r "$amd_master" ]; then 291 echo -n ' amd' 292 amd $amd_flags -p -a $amd_dir \ 293 `sed s/#.*$// <$amd_master` >/var/run/amd.pid 294 else 295 echo 296 logger -s "WARNING: \$amd_master ($amd_master)not " \ 297 "readable; amd not started." 298 fi 299 else 300 echo 301 logger -s "WARNING: \$amd_dir ($amd_dir) not a directory; " \ 302 "amd not started." 303 fi 304fi 305 306echo '.' 307 308if [ -f /sbin/ldconfig ]; then 309 echo 'creating runtime link editor directory cache.' 310 ldconfig 311fi 312 313# load kernel modules specified in /etc/lkm.conf 314if checkyesno lkm && [ -f /etc/rc.lkm ]; then 315 lkmstage=AFTERMOUNT 316 . /etc/rc.lkm 317fi 318 319# if $securelevel is set, change it here, else if it is 0, change 320# it to 1 here, before we start login services. 321if [ -n "$securelevel" ]; then 322 echo -n 'setting securelevel: ' 323 sysctl -w kern.securelevel=$securelevel 324else 325 securelevel=`sysctl -n kern.securelevel` 326 if [ x"$securelevel" = x0 ]; then 327 echo -n 'setting securelevel: ' 328 sysctl -w kern.securelevel=1 329 fi 330fi 331 332echo -n 'checking quotas:'; quotacheck -a; echo ' done.' 333quotaon -a 334 335# build ps databases 336echo 'building databases...' 337kvm_mkdb /netbsd 338dev_mkdb 339 340chmod 666 /dev/tty[pqrs]* 341 342# check the password temp/lock file 343if [ -f /etc/ptmp ] 344then 345 logger -s -p auth.err \ 346 'password file may be incorrect -- /etc/ptmp exists' 347fi 348 349# XXX replace me with a script that works! 350virecovery=`echo /var/tmp/vi.recover/recover.*` 351if [ "$virecovery" != "/var/tmp/vi.recover/recover.*" ]; then 352 echo preserving editor files 353 for i in $virecovery; do 354 if [ -f $i ]; then 355 sendmail -t < $i 356 fi 357 done 358fi 359 360echo clearing /tmp 361 362# Prune quickly with one rm, then use find to clean up /tmp/[lq]* (this 363# is not needed with mfs /tmp, but doesn't hurt anything). 364(cd /tmp && rm -rf [a-km-pr-zA-Z]* && 365 find . ! -name . ! -name lost+found ! -name quota.user \ 366 ! -name quota.group -exec rm -rf -- {} \; -type d -prune) 367 368# Update kernel info in /etc/motd 369# Must be done *before* interactive logins are possible to prevent 370# possible race conditions. 371if checkyesno update_motd; then 372 echo 'updating motd.' 373 if [ ! -f /etc/motd ]; then 374 install -c -o root -g wheel -m 664 /dev/null /etc/motd 375 fi 376 T=/etc/_motd 377 rm -f $T 378 sysctl -n kern.version | sed 1q > $T 379 echo "" >> $T 380 sed '1,/^$/d' < /etc/motd >> $T 381 cmp -s $T /etc/motd || cp $T /etc/motd 382 rm -f $T 383fi 384 385if [ -f /var/account/acct ]; then 386 echo 'turning on accounting'; accton /var/account/acct 387fi 388 389echo -n standard daemons: 390if checkyesno update; then 391 echo -n ' update'; update $update_flags 392fi 393if checkyesno cron; then 394 echo -n ' cron'; cron 395fi 396echo '.' 397 398# now start all the other daemons 399echo -n starting network daemons: 400 401if checkyesno gated && checkyesno routed; then 402 echo 403 logger -s "WARNING: gated and routed both requested to be run: " \ 404 "running only gated." 405 routed=NO 406fi 407 408if checkyesno gated; then 409 if [ -r /etc/gated.conf ]; then 410 echo -n ' gated'; gated $gated_flags 411 else 412 logger -s "WARNING: no /etc/gated.conf; gated not started." 413 fi 414fi 415 416if checkyesno routed; then 417 echo -n ' routed'; routed $routed_flags 418fi 419 420if checkyesno mrouted; then 421 echo -n ' mrouted'; mrouted $mrouted_flags 422fi 423 424if checkyesno route6d; then 425 echo -n ' route6d'; route6d $route6d_flags 426fi 427 428if checkyesno rtsold; then 429 if checkyesno ip6forwarding; then 430 logger -s "WARNING: rtsold cannot be used on IPv6 router." 431 else 432 echo -n ' rtsold'; rtsold $rtsold_flags 433 fi 434fi 435 436if checkyesno rtadvd; then 437 if checkyesno ip6forwarding; then 438 echo -n ' rtadvd'; rtadvd $rtadvd_flags 439 else 440 logger -s "WARNING: rtadvd cannot be used on IPv6 host." 441 fi 442fi 443 444if checkyesno timed; then 445 echo -n ' timed'; timed $timed_flags 446fi 447 448if checkyesno xntpd; then 449 echo -n ' xntpd'; xntpd $xntpd_flags 450fi 451 452if checkyesno dhcpd; then 453 if [ -r /etc/dhcpd.conf ]; then 454 echo -n ' dhcpd'; dhcpd $dhcpd_flags 455 else 456 echo 457 logger -s "WARNING: /etc/dhcpd.conf not readable; " \ 458 "dhcpd not started." 459 fi 460elif checkyesno dhcrelay; then 461 echo -n ' dhcrelay'; dhcrelay $dhcrelay_flags 462fi 463 464if checkyesno rwhod; then 465 echo -n ' rwhod'; rwhod 466fi 467 468if checkyesno lpd; then 469 echo -n ' lpd'; lpd $lpd_flags 470fi 471 472# We call sendmail with a full path so that SIGHUP works. 473if checkyesno sendmail; then 474 if [ -r /etc/sendmail.cf ]; then 475 echo -n ' sendmail'; /usr/sbin/sendmail $sendmail_flags 476 else 477 echo 478 logger -s "WARNING: /etc/sendmail.cf not readable; " \ 479 "sendmail not started." 480 fi 481fi 482 483# Start xfs before boot daemons, so its ready before client xterminals. 484if checkyesno xfs; then 485 echo -n ' xfs'; xfs $xfs_flags & 486 sleep 2 487fi 488 489if checkyesno rarpd; then 490 if [ -r /etc/ethers ]; then 491 echo -n ' rarpd'; rarpd $rarpd_flags 492 else 493 echo 494 logger -s "WARNING: /etc/ethers not readable; " \ 495 "rarpd not started." 496 fi 497fi 498 499if checkyesno rbootd; then 500 if [ -r /etc/rbootd.conf ]; then 501 echo -n ' rbootd'; rbootd $rbootd_flags 502 else 503 echo 504 logger -s "WARNING: /etc/rbootd.conf not readable; " \ 505 "rbootd not started." 506 fi 507fi 508 509if checkyesno mopd; then 510 echo -n ' mopd'; mopd $mopd_flags 511fi 512 513if checkyesno apmd; then 514 echo -n ' apmd'; apmd $apmd_flags 515fi 516 517if checkyesno screenblank; then 518 echo -n ' screenblank'; screenblank $screenblank_flags 519fi 520 521if checkyesno inetd; then 522 if [ -r /etc/inetd.conf ]; then 523 echo -n ' inetd'; inetd $inetd_flags 524 else 525 echo 526 logger -s "WARNING: /etc/inetd.conf not readable; " \ 527 "inetd not started." 528 fi 529fi 530 531echo '.' 532 533# Kerberos runs ONLY on the Kerberos server machine 534if checkyesno kerberos; then 535 echo -n 'starting kerberos daemons:' 536 echo -n ' kerberos'; kerberos >> /var/log/kerberos.log & 537 echo -n ' kadmind'; kadmind -n >> /var/log/kadmind.log & 538 echo '.' 539fi 540 541# xdm after wscons - need a virtual screen for X 542if checkyesno xdm; then 543 echo 'starting xdm' 544 xdm $xdm_flags 545fi 546 547. /etc/rc.local 548 549date 550exit 0 551