rc revision 1.103
1# $NetBSD: rc,v 1.103 1998/04/07 04:47:33 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# Add all block-type swap devices; these might be necessary 25# during disk checks. 26swapctl -A -t blk 27 28if [ -e /fastboot ]; then 29 echo "Fast boot: skipping disk checks." 30elif [ "$1" = autoboot ]; then 31 echo "Automatic boot in progress: starting file system checks." 32 fsck -p 33 case $? in 34 0) 35 ;; 36 2) 37 exit 1 38 ;; 39 4) 40 echo "Rebooting..." 41 reboot 42 echo "Reboot failed; help!" 43 exit 1 44 ;; 45 8) 46 echo "Automatic file system check failed; help!" 47 exit 1 48 ;; 49 12) 50 echo "Boot interrupted." 51 exit 1 52 ;; 53 130) 54 # interrupt before catcher installed 55 exit 1 56 ;; 57 *) 58 echo "Unknown error; help!" 59 exit 1 60 ;; 61 esac 62fi 63 64trap "echo 'Boot interrupted.'; exit 1" 3 65 66umount -a >/dev/null 2>&1 67mount / 68rm -f /fastboot # XXX (root now writeable) 69 70if [ -f /etc/rc.subr ]; then 71 . /etc/rc.subr 72else 73 echo "Can't read /etc/rc.subr; aborting." 74 exit 1; 75fi 76 77if [ -f /etc/rc.conf ]; then 78 . /etc/rc.conf 79fi 80 81if [ "$rc_configured" != YES ]; then 82 echo "/etc/rc.conf is not configured. Multiuser boot aborted." 83 exit 1 84fi 85 86# set flags on ttys. (do early, in case they use tty for SLIP in netstart) 87echo 'setting tty flags' 88ttyflags -a 89 90# load kernel modules specified in /etc/lkm.conf if the /usr filesystem 91# is already present with "/" or can be mounted now 92if checkyesno lkm && [ -f /etc/rc.lkm ]; then 93 mount /usr >/dev/null 2>&1 94 if [ -x /usr/bin/ld ]; then 95 lkmstage=BEFORENET 96 . /etc/rc.lkm 97 fi 98fi 99 100# set hostname, turn on network 101echo 'starting network' 102sh /etc/netstart 103if [ $? -ne 0 ]; then 104 exit 1 105fi 106 107for fs in /usr /var $critical_filesystems; do 108 mount | ( 109 ismounted=no 110 while read what _on on _type type; do 111 if [ $on = $fs ]; then 112 ismounted=yes 113 fi 114 done 115 if [ $ismounted = no ]; then 116 mount $fs >/dev/null 2>&1 117 fi 118 ) 119done 120 121# Network Address Translation... 122if checkyesno ipnat && [ -f /etc/ipnat.conf ]; then 123 echo 'installing NAT rules ... ' 124 if ! checkyesno ipfilter || [ ! -f /etc/ipf.conf ]; then 125 ipf -E -Fa 126 fi 127 ipnat -F -f /etc/ipnat.conf 128fi 129 130# "Critical" file systems are now mounted. Go ahead and swap 131# to files now, since they will be residing in the critical file 132# systems (or, at least, better). 133swapctl -A -t noblk 134 135# Check for no swap, and warn about it unless that is desired. 136if ! checkyesno no_swap; then 137 swapctl -s | grep 'no swap devices configured' > /dev/null && \ 138 echo "WARNING: no swap space configured!" 139fi 140 141# clean up left-over files 142rm -f /etc/nologin 143rm -f /var/spool/lock/LCK.* 144rm -f /var/spool/uucp/STST/* 145(cd /var/run && { rm -rf -- *; install -c -m 664 -g utmp /dev/null utmp; }) 146 147# start the system logger first, so that all messages from daemons 148# are logged, then start savecore to get a dump on low memory systems 149# and then start the name server. 150 151if checkyesno syslogd; then 152 echo 'starting system logger' 153 rm -f /dev/log 154 syslogd $syslogd_flags 155fi 156 157# Enable ipmon (only useful if ipfilter is running) 158# NOTE: requires the IPFILTER_LOG kernel option. 159if checkyesno ipmon; then 160 echo 'starting ipmon' 161 ipmon $ipmon_flags & 162fi 163 164# /var/crash should be a directory or a symbolic link 165# to the crash directory if core dumps are to be saved. 166if checkyesno savecore; then 167 if [ -d /var/crash ]; then 168 echo checking for core dump... 169 savecore $savecore_flags /var/crash 170 else 171 logger -s "WARNING: no /var/crash directory; savecore not run." 172 fi 173fi 174 175if checkyesno named; then 176 echo 'starting name server'; named $named_flags 177fi 178 179# set time, if requested 180if checkyesno ntpdate; then 181 if [ -z "$ntpdate_hosts" ]; then 182 ntpdate_hosts=`awk ' 183 /^server[ \t]*127.127/ {next} 184 /^server/ {print $2} 185 ' </etc/ntp.conf` 186 fi 187 if [ -n "$ntpdate_hosts" ]; then 188 echo 'Setting date via ntp.' 189 ntpdate -b -s $ntpdate_hosts 190 fi 191fi 192 193# now start the rpc servers, for YP server/client. 194echo -n 'starting rpc daemons:' 195 196# note that portmap is generally required for all other rpc services. 197if checkyesno portmap; then 198 echo -n ' portmap'; portmap 199fi 200 201if checkyesno ypserv; then 202 echo -n ' ypserv'; ypserv $ypserv_flags 203fi 204 205if checkyesno ypbind; then 206 echo -n ' ypbind'; ypbind $ypbind_flags 207fi 208 209if checkyesno yppasswdd; then 210 echo -n ' rpc.yppasswdd'; rpc.yppasswdd $yppasswdd_flags 211fi 212 213if checkyesno bootparamd; then 214 if [ -r /etc/bootparams ]; then 215 echo -n ' rpc.bootparamd'; rpc.bootparamd $bootparamd_flags 216 else 217 echo 218 logger -s "WARNING: /etc/bootparams not found. " \ 219 "bootparamd not started." 220 fi 221fi 222 223echo '.' 224 225# load kernel modules specified in /etc/lkm.conf 226if checkyesno lkm; then 227 if [ -r /etc/rc.lkm ]; then 228 lkmstage=BEFOREMOUNT 229 . /etc/rc.lkm 230 else 231 logger -s "WARNING: /etc/rc.lkm not found; LKMs not loaded." 232 fi 233fi 234 235mount -a 236 237# now start the rpc servers, for NFS server/client. 238echo -n 'starting nfs daemons:' 239 240nfs_locking=NO 241 242if checkyesno nfs_server; then 243 if [ -r /etc/exports ]; then 244 rm -f /var/db/mountdtab 245 echo -n > /var/db/mountdtab 246 echo -n ' mountd'; mountd $mountd_flags 247 echo -n ' nfsd'; nfsd $nfsd_flags 248 nfs_locking=YES 249 else 250 echo 251 logger -s "WARNING: /etc/exports not readable; " \ 252 "NFS server not started." 253 fi 254fi 255 256if checkyesno nfs_client; then 257 echo -n ' nfsiod'; nfsiod $nfsiod_flags 258 nfs_locking=YES 259fi 260 261if checkyesno nfs_locking; then 262 if checkyesno statd; then 263 echo -n ' rpc.statd'; rpc.statd $statd_flags 264 fi 265 if checkyesno lockd; then 266 echo -n ' rpc.lockd'; rpc.lockd $lockd_flags 267 fi 268fi 269 270if checkyesno amd; then 271 if [ -d "$amd_dir" ]; then 272 if [ -r "$amd_master" ]; then 273 echo -n ' amd' 274 amd $amd_flags -p -a $amd_dir `cat $amd_master` \ 275 > /var/run/amd.pid 276 else 277 echo 278 logger -s "WARNING: \$amd_master ($amd_master)not " \ 279 "readable; amd not started." 280 fi 281 else 282 echo 283 logger -s "WARNING: \$amd_dir ($amd_dir) not a directory; " \ 284 "amd not started." 285 fi 286fi 287 288echo '.' 289 290if [ -f /sbin/ldconfig ]; then 291 echo 'creating runtime link editor directory cache.' 292 ldconfig 293fi 294 295# load kernel modules specified in /etc/lkm.conf 296if checkyesno lkm && [ -f /etc/rc.lkm ]; then 297 lkmstage=AFTERMOUNT 298 . /etc/rc.lkm 299fi 300 301echo -n 'checking quotas:'; quotacheck -a; echo ' done.' 302quotaon -a 303 304# build ps databases 305echo 'building databases...' 306kvm_mkdb /netbsd 307dev_mkdb 308 309chmod 666 /dev/tty[pqrs]* 310 311# check the password temp/lock file 312if [ -f /etc/ptmp ] 313then 314 logger -s -p auth.err \ 315 'password file may be incorrect -- /etc/ptmp exists' 316fi 317 318virecovery=`echo /var/tmp/vi.recover/recover.*` 319if [ "$virecovery" != "/var/tmp/vi.recover/recover.*" ]; then 320 echo preserving editor files 321 for i in $virecovery; do 322 sendmail -t < $i 323 done 324fi 325 326echo clearing /tmp 327 328# Prune quickly with one rm, then use find to clean up /tmp/[lq]* (this 329# is not needed with mfs /tmp, but doesn't hurt anything). 330(cd /tmp && rm -rf [a-km-pr-zA-Z]* && 331 find . ! -name . ! -name lost+found ! -name quota.user \ 332 ! -name quota.group -exec rm -rf -- {} \; -type d -prune) 333 334# Update kernel info in /etc/motd 335# Must be done *before* interactive logins are possible to prevent 336# possible race conditions. 337if checkyesno update_motd; then 338 echo 'updating motd.' 339 if [ ! -f /etc/motd ]; then 340 install -c -o root -g wheel -m 664 /dev/null /etc/motd 341 fi 342 T=/tmp/_motd 343 rm -f $T 344 sysctl -n kern.version | sed 1q > $T 345 echo "" >> $T 346 sed '1,/^$/d' < /etc/motd >> $T 347 cmp -s $T /etc/motd || cp $T /etc/motd 348 rm -f $T 349fi 350 351if [ -f /var/account/acct ]; then 352 echo 'turning on accounting'; accton /var/account/acct 353fi 354 355echo -n standard daemons: 356if checkyesno update; then 357 echo -n ' update'; update $update_flags 358fi 359echo -n ' cron'; cron 360echo '.' 361 362# now start all the other daemons 363echo -n starting network daemons: 364 365if checkyesno gated && checkyesno routed; then 366 echo 367 logger -s "WARNING: gated and routed both requested to be run: " \ 368 "running only gated." 369 routed=NO 370fi 371 372if checkyesno gated; then 373 if [ -r /etc/gated.conf ]; then 374 echo -n ' gated'; gated $gated_flags 375 else 376 logger -s "WARNING: no /etc/gated.conf; gated not started." 377 fi 378fi 379 380if checkyesno routed; then 381 echo -n ' routed'; routed $routed_flags 382fi 383 384if checkyesno mrouted; then 385 echo -n ' mrouted'; mrouted $mrouted_flags 386fi 387 388if checkyesno timed; then 389 echo -n ' timed'; timed $timed_flags 390fi 391 392if checkyesno xntpd; then 393 echo -n ' xntpd'; xntpd $xntpd_flags 394fi 395 396if checkyesno dhcpd; then 397 if [ -r /etc/dhcpd.conf ]; then 398 echo -n ' dhcpd'; dhcpd $dhcpd_flags 399 else 400 echo 401 logger -s "WARNING: /etc/dhcpd.conf not readable; " \ 402 "dhcpd not started." 403 fi 404fi 405 406if checkyesno rwhod; then 407 echo -n ' rwhod'; rwhod 408fi 409 410if checkyesno lpd; then 411 echo -n ' lpd'; lpd $lpd_flags 412fi 413 414# We call sendmail with a full path so that SIGHUP works. 415if checkyesno sendmail; then 416 if [ -r /etc/sendmail.cf ]; then 417 echo -n ' sendmail'; /usr/sbin/sendmail $sendmail_flags 418 else 419 echo 420 logger -s "WARNING: /etc/sendmail.cf not readable; " \ 421 "sendmail not started." 422 fi 423fi 424 425# Start xfs before boot daemons, so its ready before client xterminals. 426if checkyesno xfs; then 427 echo -n ' xfs'; xfs $xfs_flags & 428 sleep 2 429fi 430 431if checkyesno rarpd; then 432 if [ -r /etc/ethers ]; then 433 echo -n ' rarpd'; rarpd $rarpd_flags 434 else 435 echo 436 logger -s "WARNING: /etc/ethers not readable; " \ 437 "rarpd not started." 438 fi 439fi 440 441if checkyesno rbootd; then 442 if [ -r /etc/rbootd.conf ]; then 443 echo -n ' rbootd'; rbootd $rbootd_flags 444 else 445 echo 446 logger -s "WARNING: /etc/rbootd.conf not readable; " \ 447 "rarpd not started." 448 fi 449fi 450 451if checkyesno mopd; then 452 echo -n ' mopd'; mopd $mopd_flags 453fi 454 455if checkyesno apmd; then 456 echo -n ' apmd'; apmd $apmd_flags 457fi 458 459if checkyesno screenblank; then 460 echo -n ' screenblank'; screenblank $screenblank_flags 461fi 462 463if checkyesno inetd; then 464 if [ -r /etc/inetd.conf ]; then 465 echo -n ' inetd'; inetd $inetd_flags 466 else 467 echo 468 logger -s "WARNING: /etc/inetd.conf not readable; " \ 469 "inetd not started." 470 fi 471fi 472 473if checkyesno xdm; then 474 echo -n ' xdm'; xdm $xdm_flags 475fi 476 477echo '.' 478 479# Kerberos runs ONLY on the Kerberos server machine 480if checkyesno kerberos; then 481 echo -n 'starting kerberos daemons:' 482 echo -n ' kerberos'; kerberos >> /var/log/kerberos.log & 483 echo -n ' kadmind'; kadmind -n >> /var/log/kadmind.log & 484 echo '.' 485fi 486 487. /etc/rc.local 488 489date 490exit 0 491