rc revision 1.105
11.105Saugustss# $NetBSD: rc,v 1.105 1998/07/12 19:51:55 augustss Exp $ 21.73Sperry# originally from: @(#)rc 8.2 (Berkeley) 3/17/94 31.1Scgd 41.1Scgd# System startup script run by init on autoboot 51.1Scgd# or after single-user. 61.1Scgd# Output and error are redirected to console by init, 71.1Scgd# and the console is the controlling terminal. 81.1Scgd 91.1Scgdstty status '^T' 101.1Scgd 111.1Scgd# Set shell to ignore SIGINT (2), but not children; 121.1Scgd# shell catches SIGQUIT (3) and returns to single user after fsck. 131.1Scgdtrap : 2 141.1Scgdtrap : 3 # shouldn't be needed 151.1Scgd 161.68Smycroftexport HOME=/ 171.96Sjonathanexport PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin 181.50Sthorpej 191.50Sthorpej# Configure ccd devices. 201.63Smrgif [ -f /etc/ccd.conf ]; then 211.50Sthorpej ccdconfig -C 221.50Sthorpejfi 231.1Scgd 241.79Sthorpej# Add all block-type swap devices; these might be necessary 251.79Sthorpej# during disk checks. 261.79Sthorpejswapctl -A -t blk 271.79Sthorpej 281.63Smrgif [ -e /fastboot ]; then 291.38Scgd echo "Fast boot: skipping disk checks." 301.68Smycroftelif [ "$1" = autoboot ]; then 311.38Scgd echo "Automatic boot in progress: starting file system checks." 321.1Scgd fsck -p 331.1Scgd case $? in 341.1Scgd 0) 351.1Scgd ;; 361.1Scgd 2) 371.1Scgd exit 1 381.1Scgd ;; 391.1Scgd 4) 401.35Scgd echo "Rebooting..." 411.1Scgd reboot 421.38Scgd echo "Reboot failed; help!" 431.1Scgd exit 1 441.1Scgd ;; 451.1Scgd 8) 461.38Scgd echo "Automatic file system check failed; help!" 471.1Scgd exit 1 481.1Scgd ;; 491.1Scgd 12) 501.38Scgd echo "Boot interrupted." 511.1Scgd exit 1 521.1Scgd ;; 531.1Scgd 130) 541.1Scgd # interrupt before catcher installed 551.1Scgd exit 1 561.1Scgd ;; 571.1Scgd *) 581.38Scgd echo "Unknown error; help!" 591.1Scgd exit 1 601.1Scgd ;; 611.1Scgd esac 621.1Scgdfi 631.1Scgd 641.38Scgdtrap "echo 'Boot interrupted.'; exit 1" 3 651.1Scgd 661.1Scgdumount -a >/dev/null 2>&1 671.83Sdrochnermount / 681.1Scgdrm -f /fastboot # XXX (root now writeable) 691.40Scgd 701.90Sveegoif [ -f /etc/rc.subr ]; then 711.90Sveego . /etc/rc.subr 721.89Scjselse 731.90Sveego echo "Can't read /etc/rc.subr; aborting." 741.89Scjs exit 1; 751.89Scjsfi 761.89Scjs 771.71Smycroftif [ -f /etc/rc.conf ]; then 781.63Smrg . /etc/rc.conf 791.63Smrgfi 801.63Smrg 811.89Scjsif [ "$rc_configured" != YES ]; then 821.89Scjs echo "/etc/rc.conf is not configured. Multiuser boot aborted." 831.89Scjs exit 1 841.89Scjsfi 851.89Scjs 861.40Scgd# set flags on ttys. (do early, in case they use tty for SLIP in netstart) 871.40Scgdecho 'setting tty flags' 881.40Scgdttyflags -a 891.1Scgd 901.83Sdrochner# load kernel modules specified in /etc/lkm.conf if the /usr filesystem 911.83Sdrochner# is already present with "/" or can be mounted now 921.93Sdrochnerif checkyesno lkm && [ -f /etc/rc.lkm ]; then 931.83Sdrochner mount /usr >/dev/null 2>&1 941.83Sdrochner if [ -x /usr/bin/ld ]; then 951.83Sdrochner lkmstage=BEFORENET 961.83Sdrochner . /etc/rc.lkm 971.83Sdrochner fi 981.63Smrgfi 991.63Smrg 1001.1Scgd# set hostname, turn on network 1011.1Scgdecho 'starting network' 1021.76Sscottrsh /etc/netstart 1031.76Sscottrif [ $? -ne 0 ]; then 1041.76Sscottr exit 1 1051.76Sscottrfi 1061.1Scgd 1071.95Sdrochnerfor fs in /usr /var $critical_filesystems; do 1081.95Sdrochner mount | ( 1091.95Sdrochner ismounted=no 1101.95Sdrochner while read what _on on _type type; do 1111.95Sdrochner if [ $on = $fs ]; then 1121.95Sdrochner ismounted=yes 1131.95Sdrochner fi 1141.95Sdrochner done 1151.95Sdrochner if [ $ismounted = no ]; then 1161.95Sdrochner mount $fs >/dev/null 2>&1 1171.95Sdrochner fi 1181.95Sdrochner ) 1191.95Sdrochnerdone 1201.99Sveego 1211.99Sveego# Network Address Translation... 1221.100Slukemif checkyesno ipnat && [ -f /etc/ipnat.conf ]; then 1231.99Sveego echo 'installing NAT rules ... ' 1241.100Slukem if ! checkyesno ipfilter || [ ! -f /etc/ipf.conf ]; then 1251.99Sveego ipf -E -Fa 1261.99Sveego fi 1271.99Sveego ipnat -F -f /etc/ipnat.conf 1281.99Sveegofi 1291.79Sthorpej 1301.79Sthorpej# "Critical" file systems are now mounted. Go ahead and swap 1311.79Sthorpej# to files now, since they will be residing in the critical file 1321.79Sthorpej# systems (or, at least, better). 1331.79Sthorpejswapctl -A -t noblk 1341.97Smrg 1351.97Smrg# Check for no swap, and warn about it unless that is desired. 1361.100Slukemif ! checkyesno no_swap; then 1371.97Smrg swapctl -s | grep 'no swap devices configured' > /dev/null && \ 1381.97Smrg echo "WARNING: no swap space configured!" 1391.97Smrgfi 1401.26Sderaadt 1411.41Sjtc# clean up left-over files 1421.41Sjtcrm -f /etc/nologin 1431.41Sjtcrm -f /var/spool/lock/LCK.* 1441.41Sjtcrm -f /var/spool/uucp/STST/* 1451.45Scgd(cd /var/run && { rm -rf -- *; install -c -m 664 -g utmp /dev/null utmp; }) 1461.41Sjtc 1471.84Sveego# start the system logger first, so that all messages from daemons 1481.84Sveego# are logged, then start savecore to get a dump on low memory systems 1491.84Sveego# and then start the name server. 1501.63Smrg 1511.89Scjsif checkyesno syslogd; then 1521.63Smrg echo 'starting system logger' 1531.63Smrg rm -f /dev/log 1541.63Smrg syslogd $syslogd_flags 1551.94Slukemfi 1561.94Slukem 1571.94Slukem# Enable ipmon (only useful if ipfilter is running) 1581.94Slukem# NOTE: requires the IPFILTER_LOG kernel option. 1591.94Slukemif checkyesno ipmon; then 1601.94Slukem echo 'starting ipmon' 1611.94Slukem ipmon $ipmon_flags & 1621.63Smrgfi 1631.63Smrg 1641.84Sveego# /var/crash should be a directory or a symbolic link 1651.84Sveego# to the crash directory if core dumps are to be saved. 1661.89Scjsif checkyesno savecore; then 1671.89Scjs if [ -d /var/crash ]; then 1681.89Scjs echo checking for core dump... 1691.89Scjs savecore $savecore_flags /var/crash 1701.89Scjs else 1711.89Scjs logger -s "WARNING: no /var/crash directory; savecore not run." 1721.84Sveego fi 1731.84Sveegofi 1741.84Sveego 1751.89Scjsif checkyesno named; then 1761.89Scjs echo 'starting name server'; named $named_flags 1771.89Scjsfi 1781.89Scjs 1791.89Scjs# set time, if requested 1801.89Scjsif checkyesno ntpdate; then 1811.91Smikel if [ -z "$ntpdate_hosts" ]; then 1821.101Slukem ntpdate_hosts=`awk ' 1831.101Slukem /^server[ \t]*127.127/ {next} 1841.101Slukem /^server/ {print $2} 1851.101Slukem ' </etc/ntp.conf` 1861.89Scjs fi 1871.89Scjs if [ -n "$ntpdate_hosts" ]; then 1881.89Scjs echo 'Setting date via ntp.' 1891.102Slukem ntpdate -b -s $ntpdate_hosts 1901.67Smycroft fi 1911.63Smrgfi 1921.63Smrg 1931.84Sveego# now start the rpc servers, for YP server/client. 1941.63Smrgecho -n 'starting rpc daemons:' 1951.63Smrg 1961.63Smrg# note that portmap is generally required for all other rpc services. 1971.89Scjsif checkyesno portmap; then 1981.63Smrg echo -n ' portmap'; portmap 1991.63Smrgfi 2001.63Smrg 2011.89Scjsif checkyesno ypserv; then 2021.63Smrg echo -n ' ypserv'; ypserv $ypserv_flags 2031.63Smrgfi 2041.63Smrg 2051.89Scjsif checkyesno ypbind; then 2061.63Smrg echo -n ' ypbind'; ypbind $ypbind_flags 2071.63Smrgfi 2081.63Smrg 2091.89Scjsif checkyesno yppasswdd; then 2101.63Smrg echo -n ' rpc.yppasswdd'; rpc.yppasswdd $yppasswdd_flags 2111.63Smrgfi 2121.63Smrg 2131.89Scjsif checkyesno bootparamd; then 2141.89Scjs if [ -r /etc/bootparams ]; then 2151.89Scjs echo -n ' rpc.bootparamd'; rpc.bootparamd $bootparamd_flags 2161.89Scjs else 2171.89Scjs echo 2181.89Scjs logger -s "WARNING: /etc/bootparams not found. " \ 2191.89Scjs "bootparamd not started." 2201.67Smycroft fi 2211.63Smrgfi 2221.63Smrg 2231.84Sveegoecho '.' 2241.84Sveego 2251.84Sveego# load kernel modules specified in /etc/lkm.conf 2261.89Scjsif checkyesno lkm; then 2271.89Scjs if [ -r /etc/rc.lkm ]; then 2281.89Scjs lkmstage=BEFOREMOUNT 2291.89Scjs . /etc/rc.lkm 2301.89Scjs else 2311.89Scjs logger -s "WARNING: /etc/rc.lkm not found; LKMs not loaded." 2321.89Scjs fi 2331.84Sveegofi 2341.84Sveego 2351.84Sveegomount -a 2361.84Sveego 2371.84Sveego# now start the rpc servers, for NFS server/client. 2381.90Sveegoecho -n 'starting nfs daemons:' 2391.84Sveego 2401.67Smycroftnfs_locking=NO 2411.67Smycroft 2421.89Scjsif checkyesno nfs_server; then 2431.89Scjs if [ -r /etc/exports ]; then 2441.89Scjs rm -f /var/db/mountdtab 2451.89Scjs echo -n > /var/db/mountdtab 2461.89Scjs echo -n ' mountd'; mountd $mountd_flags 2471.89Scjs echo -n ' nfsd'; nfsd $nfsd_flags 2481.100Slukem nfs_locking=YES 2491.89Scjs else 2501.89Scjs echo 2511.89Scjs logger -s "WARNING: /etc/exports not readable; " \ 2521.89Scjs "NFS server not started." 2531.69Smycroft fi 2541.1Scgdfi 2551.63Smrg 2561.89Scjsif checkyesno nfs_client; then 2571.63Smrg echo -n ' nfsiod'; nfsiod $nfsiod_flags 2581.100Slukem nfs_locking=YES 2591.66Sscottrfi 2601.66Sscottr 2611.100Slukemif checkyesno nfs_locking; then 2621.89Scjs if checkyesno statd; then 2631.71Smycroft echo -n ' rpc.statd'; rpc.statd $statd_flags 2641.66Sscottr fi 2651.89Scjs if checkyesno lockd; then 2661.71Smycroft echo -n ' rpc.lockd'; rpc.lockd $lockd_flags 2671.66Sscottr fi 2681.63Smrgfi 2691.63Smrg 2701.89Scjsif checkyesno amd; then 2711.89Scjs if [ -d "$amd_dir" ]; then 2721.89Scjs if [ -r "$amd_master" ]; then 2731.89Scjs echo -n ' amd' 2741.104Stron amd $amd_flags -p -a $amd_dir \ 2751.104Stron `sed s/#.*$// <$amd_master` >/var/run/amd.pid 2761.89Scjs else 2771.89Scjs echo 2781.89Scjs logger -s "WARNING: \$amd_master ($amd_master)not " \ 2791.89Scjs "readable; amd not started." 2801.89Scjs fi 2811.89Scjs else 2821.89Scjs echo 2831.89Scjs logger -s "WARNING: \$amd_dir ($amd_dir) not a directory; " \ 2841.89Scjs "amd not started." 2851.67Smycroft fi 2861.63Smrgfi 2871.63Smrg 2881.1Scgdecho '.' 2891.83Sdrochner 2901.63Smrgif [ -f /sbin/ldconfig ]; then 2911.63Smrg echo 'creating runtime link editor directory cache.' 2921.88Sthorpej ldconfig 2931.63Smrgfi 2941.83Sdrochner 2951.83Sdrochner# load kernel modules specified in /etc/lkm.conf 2961.89Scjsif checkyesno lkm && [ -f /etc/rc.lkm ]; then 2971.83Sdrochner lkmstage=AFTERMOUNT 2981.83Sdrochner . /etc/rc.lkm 2991.1Scgdfi 3001.1Scgd 3011.89Scjsecho -n 'checking quotas:'; quotacheck -a; echo ' done.' 3021.47Sderaadtquotaon -a 3031.1Scgd 3041.1Scgd# build ps databases 3051.2Scgdecho 'building databases...' 3061.11Scgdkvm_mkdb /netbsd 3071.1Scgddev_mkdb 3081.1Scgd 3091.1Scgdchmod 666 /dev/tty[pqrs]* 3101.1Scgd 3111.1Scgd# check the password temp/lock file 3121.1Scgdif [ -f /etc/ptmp ] 3131.1Scgdthen 3141.1Scgd logger -s -p auth.err \ 3151.1Scgd 'password file may be incorrect -- /etc/ptmp exists' 3161.1Scgdfi 3171.1Scgd 3181.85Sperryvirecovery=`echo /var/tmp/vi.recover/recover.*` 3191.32Smycroftif [ "$virecovery" != "/var/tmp/vi.recover/recover.*" ]; then 3201.32Smycroft echo preserving editor files 3211.32Smycroft for i in $virecovery; do 3221.32Smycroft sendmail -t < $i 3231.32Smycroft done 3241.32Smycroftfi 3251.1Scgd 3261.1Scgdecho clearing /tmp 3271.1Scgd 3281.65Smikel# Prune quickly with one rm, then use find to clean up /tmp/[lq]* (this 3291.65Smikel# is not needed with mfs /tmp, but doesn't hurt anything). 3301.1Scgd(cd /tmp && rm -rf [a-km-pr-zA-Z]* && 3311.46Sderaadt find . ! -name . ! -name lost+found ! -name quota.user \ 3321.46Sderaadt ! -name quota.group -exec rm -rf -- {} \; -type d -prune) 3331.1Scgd 3341.74Sperry# Update kernel info in /etc/motd 3351.74Sperry# Must be done *before* interactive logins are possible to prevent 3361.74Sperry# possible race conditions. 3371.89Scjsif checkyesno update_motd; then 3381.74Sperry echo 'updating motd.' 3391.74Sperry if [ ! -f /etc/motd ]; then 3401.74Sperry install -c -o root -g wheel -m 664 /dev/null /etc/motd 3411.74Sperry fi 3421.74Sperry T=/tmp/_motd 3431.74Sperry rm -f $T 3441.74Sperry sysctl -n kern.version | sed 1q > $T 3451.74Sperry echo "" >> $T 3461.74Sperry sed '1,/^$/d' < /etc/motd >> $T 3471.74Sperry cmp -s $T /etc/motd || cp $T /etc/motd 3481.74Sperry rm -f $T 3491.74Sperryfi 3501.74Sperry 3511.34Scgdif [ -f /var/account/acct ]; then 3521.34Scgd echo 'turning on accounting'; accton /var/account/acct 3531.34Scgdfi 3541.1Scgd 3551.1Scgdecho -n standard daemons: 3561.89Scjsif checkyesno update; then 3571.70Smycroft echo -n ' update'; update $update_flags 3581.70Smycroftfi 3591.31Sjtcecho -n ' cron'; cron 3601.1Scgdecho '.' 3611.1Scgd 3621.63Smrg# now start all the other daemons 3631.1Scgdecho -n starting network daemons: 3641.1Scgd 3651.89Scjsif checkyesno gated && checkyesno routed; then 3661.89Scjs echo 3671.89Scjs logger -s "WARNING: gated and routed both requested to be run: " \ 3681.89Scjs "running only gated." 3691.89Scjs routed=NO 3701.89Scjsfi 3711.89Scjs 3721.89Scjsif checkyesno gated; then 3731.89Scjs if [ -r /etc/gated.conf ]; then 3741.89Scjs echo -n ' gated'; gated $gated_flags 3751.89Scjs else 3761.89Scjs logger -s "WARNING: no /etc/gated.conf; gated not started." 3771.67Smycroft fi 3781.89Scjsfi 3791.89Scjs 3801.89Scjsif checkyesno routed; then 3811.48Smycroft echo -n ' routed'; routed $routed_flags 3821.1Scgdfi 3831.1Scgd 3841.89Scjsif checkyesno mrouted; then 3851.55Sthorpej echo -n ' mrouted'; mrouted $mrouted_flags 3861.55Sthorpejfi 3871.55Sthorpej 3881.89Scjsif checkyesno timed; then 3891.67Smycroft echo -n ' timed'; timed $timed_flags 3901.63Smrgfi 3911.63Smrg 3921.89Scjsif checkyesno xntpd; then 3931.67Smycroft echo -n ' xntpd'; xntpd $xntpd_flags 3941.61Smrgfi 3951.61Smrg 3961.89Scjsif checkyesno dhcpd; then 3971.89Scjs if [ -r /etc/dhcpd.conf ]; then 3981.89Scjs echo -n ' dhcpd'; dhcpd $dhcpd_flags 3991.89Scjs else 4001.89Scjs echo 4011.89Scjs logger -s "WARNING: /etc/dhcpd.conf not readable; " \ 4021.89Scjs "dhcpd not started." 4031.67Smycroft fi 4041.29Smycroftfi 4051.29Smycroft 4061.89Scjsif checkyesno rwhod; then 4071.48Smycroft echo -n ' rwhod'; rwhod 4081.1Scgdfi 4091.1Scgd 4101.89Scjsif checkyesno lpd; then 4111.89Scjs echo -n ' lpd'; lpd $lpd_flags 4121.60Stlsfi 4131.60Stls 4141.63Smrg# We call sendmail with a full path so that SIGHUP works. 4151.89Scjsif checkyesno sendmail; then 4161.89Scjs if [ -r /etc/sendmail.cf ]; then 4171.89Scjs echo -n ' sendmail'; /usr/sbin/sendmail $sendmail_flags 4181.89Scjs else 4191.89Scjs echo 4201.89Scjs logger -s "WARNING: /etc/sendmail.cf not readable; " \ 4211.89Scjs "sendmail not started." 4221.67Smycroft fi 4231.60Stlsfi 4241.60Stls 4251.96Sjonathan# Start xfs before boot daemons, so its ready before client xterminals. 4261.96Sjonathanif checkyesno xfs; then 4271.96Sjonathan echo -n ' xfs'; xfs $xfs_flags & 4281.98Sperry sleep 2 4291.96Sjonathanfi 4301.96Sjonathan 4311.89Scjsif checkyesno rarpd; then 4321.89Scjs if [ -r /etc/ethers ]; then 4331.89Scjs echo -n ' rarpd'; rarpd $rarpd_flags 4341.89Scjs else 4351.89Scjs echo 4361.89Scjs logger -s "WARNING: /etc/ethers not readable; " \ 4371.89Scjs "rarpd not started." 4381.67Smycroft fi 4391.60Stlsfi 4401.60Stls 4411.89Scjsif checkyesno rbootd; then 4421.89Scjs if [ -r /etc/rbootd.conf ]; then 4431.89Scjs echo -n ' rbootd'; rbootd $rbootd_flags 4441.89Scjs else 4451.89Scjs echo 4461.89Scjs logger -s "WARNING: /etc/rbootd.conf not readable; " \ 4471.89Scjs "rarpd not started." 4481.67Smycroft fi 4491.72Scjsfi 4501.72Scjs 4511.89Scjsif checkyesno mopd; then 4521.72Scjs echo -n ' mopd'; mopd $mopd_flags 4531.86Sperryfi 4541.86Sperry 4551.89Scjsif checkyesno apmd; then 4561.86Sperry echo -n ' apmd'; apmd $apmd_flags 4571.103Smrgfi 4581.103Smrg 4591.103Smrgif checkyesno screenblank; then 4601.103Smrg echo -n ' screenblank'; screenblank $screenblank_flags 4611.52Sthorpejfi 4621.52Sthorpej 4631.89Scjsif checkyesno inetd; then 4641.89Scjs if [ -r /etc/inetd.conf ]; then 4651.89Scjs echo -n ' inetd'; inetd $inetd_flags 4661.89Scjs else 4671.89Scjs echo 4681.89Scjs logger -s "WARNING: /etc/inetd.conf not readable; " \ 4691.89Scjs "inetd not started." 4701.67Smycroft fi 4711.105Saugustssfi 4721.105Saugustss 4731.105Saugustssif checkyesno usbd; then 4741.105Saugustss echo -n ' usbd'; usbd $usbd_flags 4751.96Sjonathanfi 4761.96Sjonathan 4771.96Sjonathanif checkyesno xdm; then 4781.96Sjonathan echo -n ' xdm'; xdm $xdm_flags 4791.30Smycroftfi 4801.30Smycroft 4811.1Scgdecho '.' 4821.73Sperry 4831.73Sperry# Kerberos runs ONLY on the Kerberos server machine 4841.89Scjsif checkyesno kerberos; then 4851.73Sperry echo -n 'starting kerberos daemons:' 4861.73Sperry echo -n ' kerberos'; kerberos >> /var/log/kerberos.log & 4871.73Sperry echo -n ' kadmind'; kadmind -n >> /var/log/kadmind.log & 4881.73Sperry echo '.' 4891.73Sperryfi 4901.1Scgd 4911.25Smycroft. /etc/rc.local 4921.1Scgd 4931.1Scgddate 4941.1Scgdexit 0 495