rc revision 1.99
1# $NetBSD: rc,v 1.99 1998/01/24 19:12:55 veego 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 [ "$ipnat" != NO ] && [ -f /etc/ipnat.conf ]; then 123 echo 'installing NAT rules ... ' 124 if [ "$ipfilter" = NO ] || [ ! -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 [ "$no_swap" != YES ]; 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 '/^server/ {print $2}' </etc/ntp.conf` 183 fi 184 if [ -n "$ntpdate_hosts" ]; then 185 echo 'Setting date via ntp.' 186 ntpdate -b $ntpdate_hosts 187 fi 188fi 189 190# now start the rpc servers, for YP server/client. 191echo -n 'starting rpc daemons:' 192 193# note that portmap is generally required for all other rpc services. 194if checkyesno portmap; then 195 echo -n ' portmap'; portmap 196fi 197 198if checkyesno ypserv; then 199 echo -n ' ypserv'; ypserv $ypserv_flags 200fi 201 202if checkyesno ypbind; then 203 echo -n ' ypbind'; ypbind $ypbind_flags 204fi 205 206if checkyesno yppasswdd; then 207 echo -n ' rpc.yppasswdd'; rpc.yppasswdd $yppasswdd_flags 208fi 209 210if checkyesno bootparamd; then 211 if [ -r /etc/bootparams ]; then 212 echo -n ' rpc.bootparamd'; rpc.bootparamd $bootparamd_flags 213 else 214 echo 215 logger -s "WARNING: /etc/bootparams not found. " \ 216 "bootparamd not started." 217 fi 218fi 219 220echo '.' 221 222# load kernel modules specified in /etc/lkm.conf 223if checkyesno lkm; then 224 if [ -r /etc/rc.lkm ]; then 225 lkmstage=BEFOREMOUNT 226 . /etc/rc.lkm 227 else 228 logger -s "WARNING: /etc/rc.lkm not found; LKMs not loaded." 229 fi 230fi 231 232mount -a 233 234# now start the rpc servers, for NFS server/client. 235echo -n 'starting nfs daemons:' 236 237nfs_locking=NO 238 239if checkyesno nfs_server; then 240 if [ -r /etc/exports ]; then 241 rm -f /var/db/mountdtab 242 echo -n > /var/db/mountdtab 243 echo -n ' mountd'; mountd $mountd_flags 244 echo -n ' nfsd'; nfsd $nfsd_flags 245 nfs_locking=MAYBE 246 else 247 echo 248 logger -s "WARNING: /etc/exports not readable; " \ 249 "NFS server not started." 250 fi 251fi 252 253if checkyesno nfs_client; then 254 echo -n ' nfsiod'; nfsiod $nfsiod_flags 255 nfs_locking=MAYBE 256fi 257 258if [ "$nfs_locking" != NO ]; then 259 if checkyesno statd; then 260 echo -n ' rpc.statd'; rpc.statd $statd_flags 261 fi 262 if checkyesno lockd; then 263 echo -n ' rpc.lockd'; rpc.lockd $lockd_flags 264 fi 265fi 266 267if checkyesno amd; then 268 if [ -d "$amd_dir" ]; then 269 if [ -r "$amd_master" ]; then 270 echo -n ' amd' 271 amd $amd_flags -p -a $amd_dir `cat $amd_master` \ 272 > /var/run/amd.pid 273 else 274 echo 275 logger -s "WARNING: \$amd_master ($amd_master)not " \ 276 "readable; amd not started." 277 fi 278 else 279 echo 280 logger -s "WARNING: \$amd_dir ($amd_dir) not a directory; " \ 281 "amd not started." 282 fi 283fi 284 285echo '.' 286 287if [ -f /sbin/ldconfig ]; then 288 echo 'creating runtime link editor directory cache.' 289 ldconfig 290fi 291 292# load kernel modules specified in /etc/lkm.conf 293if checkyesno lkm && [ -f /etc/rc.lkm ]; then 294 lkmstage=AFTERMOUNT 295 . /etc/rc.lkm 296fi 297 298echo -n 'checking quotas:'; quotacheck -a; echo ' done.' 299quotaon -a 300 301# build ps databases 302echo 'building databases...' 303kvm_mkdb /netbsd 304dev_mkdb 305 306chmod 666 /dev/tty[pqrs]* 307 308# check the password temp/lock file 309if [ -f /etc/ptmp ] 310then 311 logger -s -p auth.err \ 312 'password file may be incorrect -- /etc/ptmp exists' 313fi 314 315virecovery=`echo /var/tmp/vi.recover/recover.*` 316if [ "$virecovery" != "/var/tmp/vi.recover/recover.*" ]; then 317 echo preserving editor files 318 for i in $virecovery; do 319 sendmail -t < $i 320 done 321fi 322 323echo clearing /tmp 324 325# Prune quickly with one rm, then use find to clean up /tmp/[lq]* (this 326# is not needed with mfs /tmp, but doesn't hurt anything). 327(cd /tmp && rm -rf [a-km-pr-zA-Z]* && 328 find . ! -name . ! -name lost+found ! -name quota.user \ 329 ! -name quota.group -exec rm -rf -- {} \; -type d -prune) 330 331# Update kernel info in /etc/motd 332# Must be done *before* interactive logins are possible to prevent 333# possible race conditions. 334if checkyesno update_motd; then 335 echo 'updating motd.' 336 if [ ! -f /etc/motd ]; then 337 install -c -o root -g wheel -m 664 /dev/null /etc/motd 338 fi 339 T=/tmp/_motd 340 rm -f $T 341 sysctl -n kern.version | sed 1q > $T 342 echo "" >> $T 343 sed '1,/^$/d' < /etc/motd >> $T 344 cmp -s $T /etc/motd || cp $T /etc/motd 345 rm -f $T 346fi 347 348if [ -f /var/account/acct ]; then 349 echo 'turning on accounting'; accton /var/account/acct 350fi 351 352echo -n standard daemons: 353if checkyesno update; then 354 echo -n ' update'; update $update_flags 355fi 356echo -n ' cron'; cron 357echo '.' 358 359# now start all the other daemons 360echo -n starting network daemons: 361 362if checkyesno gated && checkyesno routed; then 363 echo 364 logger -s "WARNING: gated and routed both requested to be run: " \ 365 "running only gated." 366 routed=NO 367fi 368 369if checkyesno gated; then 370 if [ -r /etc/gated.conf ]; then 371 echo -n ' gated'; gated $gated_flags 372 else 373 logger -s "WARNING: no /etc/gated.conf; gated not started." 374 fi 375fi 376 377if checkyesno routed; then 378 echo -n ' routed'; routed $routed_flags 379fi 380 381if checkyesno mrouted; then 382 echo -n ' mrouted'; mrouted $mrouted_flags 383fi 384 385if checkyesno timed; then 386 echo -n ' timed'; timed $timed_flags 387fi 388 389if checkyesno xntpd; then 390 echo -n ' xntpd'; xntpd $xntpd_flags 391fi 392 393if checkyesno dhcpd; then 394 if [ -r /etc/dhcpd.conf ]; then 395 echo -n ' dhcpd'; dhcpd $dhcpd_flags 396 else 397 echo 398 logger -s "WARNING: /etc/dhcpd.conf not readable; " \ 399 "dhcpd not started." 400 fi 401fi 402 403if checkyesno rwhod; then 404 echo -n ' rwhod'; rwhod 405fi 406 407if checkyesno lpd; then 408 echo -n ' lpd'; lpd $lpd_flags 409fi 410 411# We call sendmail with a full path so that SIGHUP works. 412if checkyesno sendmail; then 413 if [ -r /etc/sendmail.cf ]; then 414 echo -n ' sendmail'; /usr/sbin/sendmail $sendmail_flags 415 else 416 echo 417 logger -s "WARNING: /etc/sendmail.cf not readable; " \ 418 "sendmail not started." 419 fi 420fi 421 422# Start xfs before boot daemons, so its ready before client xterminals. 423if checkyesno xfs; then 424 echo -n ' xfs'; xfs $xfs_flags & 425 sleep 2 426fi 427 428if checkyesno rarpd; then 429 if [ -r /etc/ethers ]; then 430 echo -n ' rarpd'; rarpd $rarpd_flags 431 else 432 echo 433 logger -s "WARNING: /etc/ethers not readable; " \ 434 "rarpd not started." 435 fi 436fi 437 438if checkyesno rbootd; then 439 if [ -r /etc/rbootd.conf ]; then 440 echo -n ' rbootd'; rbootd $rbootd_flags 441 else 442 echo 443 logger -s "WARNING: /etc/rbootd.conf not readable; " \ 444 "rarpd not started." 445 fi 446fi 447 448if checkyesno mopd; then 449 echo -n ' mopd'; mopd $mopd_flags 450fi 451 452if checkyesno apmd; then 453 echo -n ' apmd'; apmd $apmd_flags 454fi 455 456if checkyesno inetd; then 457 if [ -r /etc/inetd.conf ]; then 458 echo -n ' inetd'; inetd $inetd_flags 459 else 460 echo 461 logger -s "WARNING: /etc/inetd.conf not readable; " \ 462 "inetd not started." 463 fi 464fi 465 466if checkyesno xdm; then 467 echo -n ' xdm'; xdm $xdm_flags 468fi 469 470echo '.' 471 472# Kerberos runs ONLY on the Kerberos server machine 473if checkyesno kerberos; then 474 echo -n 'starting kerberos daemons:' 475 echo -n ' kerberos'; kerberos >> /var/log/kerberos.log & 476 echo -n ' kadmind'; kadmind -n >> /var/log/kadmind.log & 477 echo '.' 478fi 479 480. /etc/rc.local 481 482date 483exit 0 484