rc revision 1.112
1# $NetBSD: rc,v 1.112 1999/01/31 08:46:58 mrg 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 raidctl -r raid$dev 29 fi 30done 31 32# Add all block-type swap devices; these might be necessary 33# during disk checks. 34swapctl -A -t blk 35 36if [ -e /fastboot ]; then 37 echo "Fast boot: skipping disk checks." 38elif [ "$1" = autoboot ]; then 39 echo "Automatic boot in progress: starting file system checks." 40 fsck -p 41 case $? in 42 0) 43 ;; 44 2) 45 exit 1 46 ;; 47 4) 48 echo "Rebooting..." 49 reboot 50 echo "Reboot failed; help!" 51 exit 1 52 ;; 53 8) 54 echo "Automatic file system check failed; help!" 55 exit 1 56 ;; 57 12) 58 echo "Boot interrupted." 59 exit 1 60 ;; 61 130) 62 # interrupt before catcher installed 63 exit 1 64 ;; 65 *) 66 echo "Unknown error; help!" 67 exit 1 68 ;; 69 esac 70fi 71 72trap "echo 'Boot interrupted.'; exit 1" 3 73 74umount -a >/dev/null 2>&1 75mount / 76rm -f /fastboot # XXX (root now writeable) 77 78if [ -f /etc/rc.subr ]; then 79 . /etc/rc.subr 80else 81 echo "Can't read /etc/rc.subr; aborting." 82 exit 1; 83fi 84 85if [ -f /etc/rc.conf ]; then 86 . /etc/rc.conf 87fi 88 89if [ "$rc_configured" != YES ]; then 90 echo "/etc/rc.conf is not configured. Multiuser boot aborted." 91 exit 1 92fi 93 94# set flags on ttys. (do early, in case they use tty for SLIP in netstart) 95echo 'setting tty flags' 96ttyflags -a 97 98# load kernel modules specified in /etc/lkm.conf if the /usr filesystem 99# is already present with "/" or can be mounted now 100if checkyesno lkm && [ -f /etc/rc.lkm ]; then 101 mount /usr >/dev/null 2>&1 102 if [ -x /usr/bin/ld ]; then 103 lkmstage=BEFORENET 104 . /etc/rc.lkm 105 fi 106fi 107 108# set hostname, turn on network 109echo 'starting network' 110sh /etc/netstart 111if [ $? -ne 0 ]; then 112 exit 1 113fi 114 115for fs in /usr /var $critical_filesystems; do 116 mount | ( 117 ismounted=no 118 while read what _on on _type type; do 119 if [ $on = $fs ]; then 120 ismounted=yes 121 fi 122 done 123 if [ $ismounted = no ]; then 124 mount $fs >/dev/null 2>&1 125 fi 126 ) 127done 128 129# Network Address Translation... 130if checkyesno ipnat && [ -f /etc/ipnat.conf ]; then 131 echo 'installing NAT rules ... ' 132 if ! checkyesno ipfilter || [ ! -f /etc/ipf.conf ]; then 133 ipf -E -Fa 134 fi 135 ipnat -F -f /etc/ipnat.conf 136fi 137 138# "Critical" file systems are now mounted. Go ahead and swap 139# to files now, since they will be residing in the critical file 140# systems (or, at least, better). 141swapctl -A -t noblk 142 143# Check for no swap, and warn about it unless that is desired. 144if ! checkyesno no_swap; then 145 swapctl -s | grep 'no swap devices configured' > /dev/null && \ 146 echo "WARNING: no swap space configured!" 147fi 148 149# clean up left-over files 150rm -f /etc/nologin 151rm -f /var/spool/lock/LCK.* 152rm -f /var/spool/uucp/STST/* 153(cd /var/run && { rm -rf -- *; install -c -m 664 -g utmp /dev/null utmp; }) 154 155# get the system dmesg output, hopefully containing the boot messages 156# $dmesg_flags is imported from /etc/rc.conf 157if checkyesno dmesg; then 158 dmesg $dmesg_flags > /var/run/dmesg.boot 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 rm -f /dev/log 168 syslogd $syslogd_flags 169fi 170 171# Enable ipmon (only useful if ipfilter is running) 172# NOTE: requires the IPFILTER_LOG kernel option. 173if checkyesno ipmon; then 174 echo 'starting ipmon' 175 ipmon $ipmon_flags & 176fi 177 178# /var/crash should be a directory or a symbolic link 179# to the crash directory if core dumps are to be saved. 180if checkyesno savecore; then 181 if [ -d /var/crash/. ]; then 182 echo checking for core dump... 183 savecore $savecore_flags /var/crash 184 else 185 logger -s "WARNING: no /var/crash directory; savecore not run." 186 fi 187fi 188 189if checkyesno named; then 190 echo 'starting name server'; named $named_flags 191fi 192 193# set time, if requested 194if checkyesno ntpdate; then 195 if [ -z "$ntpdate_hosts" ]; then 196 ntpdate_hosts=`awk ' 197 /^server[ \t]*127.127/ {next} 198 /^server/ {print $2} 199 ' </etc/ntp.conf` 200 fi 201 if [ -n "$ntpdate_hosts" ]; then 202 echo 'Setting date via ntp.' 203 ntpdate -b -s $ntpdate_hosts 204 fi 205fi 206 207# now start the rpc servers, for YP server/client. 208echo -n 'starting rpc daemons:' 209 210# note that portmap is generally required for all other rpc services. 211if checkyesno portmap; then 212 echo -n ' portmap'; portmap $portmap_flags 213fi 214 215if checkyesno ypserv; then 216 echo -n ' ypserv'; ypserv $ypserv_flags 217fi 218 219if checkyesno ypbind; then 220 echo -n ' ypbind'; ypbind $ypbind_flags 221fi 222 223if checkyesno yppasswdd; then 224 echo -n ' rpc.yppasswdd'; rpc.yppasswdd $yppasswdd_flags 225fi 226 227if checkyesno bootparamd; then 228 if [ -r /etc/bootparams ]; then 229 echo -n ' rpc.bootparamd'; rpc.bootparamd $bootparamd_flags 230 else 231 echo 232 logger -s "WARNING: /etc/bootparams not found. " \ 233 "bootparamd not started." 234 fi 235fi 236 237echo '.' 238 239# load kernel modules specified in /etc/lkm.conf 240if checkyesno lkm; then 241 if [ -r /etc/rc.lkm ]; then 242 lkmstage=BEFOREMOUNT 243 . /etc/rc.lkm 244 else 245 logger -s "WARNING: /etc/rc.lkm not found; LKMs not loaded." 246 fi 247fi 248 249mount -a 250 251# now start the rpc servers, for NFS server/client. 252echo -n 'starting nfs daemons:' 253 254nfs_locking=NO 255 256if checkyesno nfs_server; then 257 if [ -r /etc/exports ]; then 258 rm -f /var/db/mountdtab 259 echo -n > /var/db/mountdtab 260 echo -n ' mountd'; mountd $mountd_flags 261 echo -n ' nfsd'; nfsd $nfsd_flags 262 nfs_locking=YES 263 else 264 echo 265 logger -s "WARNING: /etc/exports not readable; " \ 266 "NFS server not started." 267 fi 268fi 269 270if checkyesno nfs_client; then 271 echo -n ' nfsiod'; nfsiod $nfsiod_flags 272 nfs_locking=YES 273fi 274 275if checkyesno nfs_locking; then 276 if checkyesno statd; then 277 echo -n ' rpc.statd'; rpc.statd $statd_flags 278 fi 279 if checkyesno lockd; then 280 echo -n ' rpc.lockd'; rpc.lockd $lockd_flags 281 fi 282fi 283 284if checkyesno amd; then 285 if [ -d "$amd_dir" ]; then 286 if [ -r "$amd_master" ]; then 287 echo -n ' amd' 288 amd $amd_flags -p -a $amd_dir \ 289 `sed s/#.*$// <$amd_master` >/var/run/amd.pid 290 else 291 echo 292 logger -s "WARNING: \$amd_master ($amd_master)not " \ 293 "readable; amd not started." 294 fi 295 else 296 echo 297 logger -s "WARNING: \$amd_dir ($amd_dir) not a directory; " \ 298 "amd not started." 299 fi 300fi 301 302echo '.' 303 304if [ -f /sbin/ldconfig ]; then 305 echo 'creating runtime link editor directory cache.' 306 ldconfig 307fi 308 309# load kernel modules specified in /etc/lkm.conf 310if checkyesno lkm && [ -f /etc/rc.lkm ]; then 311 lkmstage=AFTERMOUNT 312 . /etc/rc.lkm 313fi 314 315# if $securelevel is set, change it here, else if it is 0, change 316# it to 1 here, before we start login services. 317if [ -z "$securelevel" ]; then 318 echo -n 'setting securelevel: ' 319 sysctl -w kern.securelevel=$securelevel 320else 321 securelevel=`sysctl kern.securelevel | awk { print $3 }` 322 if [ x"$securelevel" = x0 ]; then 323 echo -n 'setting securelevel: ' 324 sysctl -w kern.securelevel=1 325 fi 326fi 327 328echo -n 'checking quotas:'; quotacheck -a; echo ' done.' 329quotaon -a 330 331# build ps databases 332echo 'building databases...' 333kvm_mkdb /netbsd 334dev_mkdb 335 336chmod 666 /dev/tty[pqrs]* 337 338# check the password temp/lock file 339if [ -f /etc/ptmp ] 340then 341 logger -s -p auth.err \ 342 'password file may be incorrect -- /etc/ptmp exists' 343fi 344 345# XXX replace me with a script that works! 346virecovery=`echo /var/tmp/vi.recover/recover.*` 347if [ "$virecovery" != "/var/tmp/vi.recover/recover.*" ]; then 348 echo preserving editor files 349 for i in $virecovery; do 350 sendmail -t < $i 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=/tmp/_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 timed; then 419 echo -n ' timed'; timed $timed_flags 420fi 421 422if checkyesno xntpd; then 423 echo -n ' xntpd'; xntpd $xntpd_flags 424fi 425 426if checkyesno dhcpd; then 427 if [ -r /etc/dhcpd.conf ]; then 428 echo -n ' dhcpd'; dhcpd $dhcpd_flags 429 else 430 echo 431 logger -s "WARNING: /etc/dhcpd.conf not readable; " \ 432 "dhcpd not started." 433 fi 434fi 435 436if checkyesno rwhod; then 437 echo -n ' rwhod'; rwhod 438fi 439 440if checkyesno lpd; then 441 echo -n ' lpd'; lpd $lpd_flags 442fi 443 444# We call sendmail with a full path so that SIGHUP works. 445if checkyesno sendmail; then 446 if [ -r /etc/sendmail.cf ]; then 447 echo -n ' sendmail'; /usr/sbin/sendmail $sendmail_flags 448 else 449 echo 450 logger -s "WARNING: /etc/sendmail.cf not readable; " \ 451 "sendmail not started." 452 fi 453fi 454 455# Start xfs before boot daemons, so its ready before client xterminals. 456if checkyesno xfs; then 457 echo -n ' xfs'; xfs $xfs_flags & 458 sleep 2 459fi 460 461if checkyesno rarpd; then 462 if [ -r /etc/ethers ]; then 463 echo -n ' rarpd'; rarpd $rarpd_flags 464 else 465 echo 466 logger -s "WARNING: /etc/ethers not readable; " \ 467 "rarpd not started." 468 fi 469fi 470 471if checkyesno rbootd; then 472 if [ -r /etc/rbootd.conf ]; then 473 echo -n ' rbootd'; rbootd $rbootd_flags 474 else 475 echo 476 logger -s "WARNING: /etc/rbootd.conf not readable; " \ 477 "rbootd not started." 478 fi 479fi 480 481if checkyesno mopd; then 482 echo -n ' mopd'; mopd $mopd_flags 483fi 484 485if checkyesno apmd; then 486 echo -n ' apmd'; apmd $apmd_flags 487fi 488 489if checkyesno screenblank; then 490 echo -n ' screenblank'; screenblank $screenblank_flags 491fi 492 493if checkyesno inetd; then 494 if [ -r /etc/inetd.conf ]; then 495 echo -n ' inetd'; inetd $inetd_flags 496 else 497 echo 498 logger -s "WARNING: /etc/inetd.conf not readable; " \ 499 "inetd not started." 500 fi 501fi 502 503if checkyesno usbd; then 504 echo -n ' usbd'; usbd $usbd_flags 505fi 506 507if checkyesno xdm; then 508 echo -n ' xdm'; xdm $xdm_flags 509fi 510 511echo '.' 512 513# Kerberos runs ONLY on the Kerberos server machine 514if checkyesno kerberos; then 515 echo -n 'starting kerberos daemons:' 516 echo -n ' kerberos'; kerberos >> /var/log/kerberos.log & 517 echo -n ' kadmind'; kadmind -n >> /var/log/kadmind.log & 518 echo '.' 519fi 520 521. /etc/rc.local 522 523date 524exit 0 525