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