rc revision 1.85
11.85Sperry# $NetBSD: rc,v 1.85 1997/07/31 03:35:39 perry 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.68Smycroftexport PATH=/sbin:/bin:/usr/sbin:/usr/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.71Smycroftif [ -f /etc/rc.conf ]; then 711.63Smrg . /etc/rc.conf 721.63Smrgfi 731.63Smrg 741.40Scgd# set flags on ttys. (do early, in case they use tty for SLIP in netstart) 751.40Scgdecho 'setting tty flags' 761.40Scgdttyflags -a 771.1Scgd 781.83Sdrochner# load kernel modules specified in /etc/lkm.conf if the /usr filesystem 791.83Sdrochner# is already present with "/" or can be mounted now 801.67Smycroftif [ "$lkm_init" != NO ] && [ -f /etc/rc.lkm ]; then 811.83Sdrochner mount /usr >/dev/null 2>&1 821.83Sdrochner if [ -x /usr/bin/ld ]; then 831.83Sdrochner lkmstage=BEFORENET 841.83Sdrochner . /etc/rc.lkm 851.83Sdrochner fi 861.63Smrgfi 871.63Smrg 881.1Scgd# set hostname, turn on network 891.1Scgdecho 'starting network' 901.76Sscottrsh /etc/netstart 911.76Sscottrif [ $? -ne 0 ]; then 921.76Sscottr exit 1 931.76Sscottrfi 941.1Scgd 951.82Sveegomount /usr >/dev/null 2>&1 961.42Smycroftmount /var >/dev/null 2>&1 971.79Sthorpej 981.79Sthorpej# "Critical" file systems are now mounted. Go ahead and swap 991.79Sthorpej# to files now, since they will be residing in the critical file 1001.79Sthorpej# systems (or, at least, better). 1011.79Sthorpejswapctl -A -t noblk 1021.26Sderaadt 1031.41Sjtc# clean up left-over files 1041.41Sjtcrm -f /etc/nologin 1051.41Sjtcrm -f /var/spool/lock/LCK.* 1061.41Sjtcrm -f /var/spool/uucp/STST/* 1071.45Scgd(cd /var/run && { rm -rf -- *; install -c -m 664 -g utmp /dev/null utmp; }) 1081.41Sjtc 1091.84Sveego# start the system logger first, so that all messages from daemons 1101.84Sveego# are logged, then start savecore to get a dump on low memory systems 1111.84Sveego# and then start the name server. 1121.63Smrg 1131.67Smycroftif [ "$syslogd_flags" != NO ]; then 1141.67Smycroft if [ "$syslogd_flags" = DEFAULT ]; then 1151.67Smycroft syslogd_flags="" 1161.67Smycroft fi 1171.63Smrg echo 'starting system logger' 1181.63Smrg rm -f /dev/log 1191.63Smrg syslogd $syslogd_flags 1201.63Smrgfi 1211.63Smrg 1221.84Sveego# /var/crash should be a directory or a symbolic link 1231.84Sveego# to the crash directory if core dumps are to be saved. 1241.84Sveegoif [ "$savecore_flags" != NO ] && [ -d /var/crash ]; then 1251.84Sveego if [ "$savecore_flags" = DEFAULT ]; then 1261.84Sveego savecore_flags="" 1271.84Sveego fi 1281.84Sveego echo checking for core dump... 1291.84Sveego savecore $savecore_flags /var/crash 1301.84Sveegofi 1311.84Sveego 1321.67Smycroftif [ "$named_flags" != NO ]; then 1331.67Smycroft if [ "$named_flags" = DEFAULT ]; then 1341.67Smycroft named_flags="" 1351.67Smycroft fi 1361.63Smrg echo 'starting name server'; named $named_flags 1371.63Smrgfi 1381.63Smrg 1391.84Sveego# now start the rpc servers, for YP server/client. 1401.63Smrgecho -n 'starting rpc daemons:' 1411.63Smrg 1421.63Smrg# note that portmap is generally required for all other rpc services. 1431.67Smycroftif [ "$portmap" != NO ]; then 1441.63Smrg echo -n ' portmap'; portmap 1451.63Smrgfi 1461.63Smrg 1471.67Smycroftif [ "$ypserv_flags" != NO ]; then 1481.67Smycroft if [ "$ypserv_flags" = DEFAULT ]; then 1491.67Smycroft ypserv_flags="-d" 1501.67Smycroft fi 1511.63Smrg echo -n ' ypserv'; ypserv $ypserv_flags 1521.63Smrgfi 1531.63Smrg 1541.67Smycroftif [ "$ypbind_flags" != NO ]; then 1551.67Smycroft if [ "$ypbind_flags" = DEFAULT ]; then 1561.67Smycroft ypbind_flags="" 1571.67Smycroft fi 1581.63Smrg echo -n ' ypbind'; ypbind $ypbind_flags 1591.63Smrgfi 1601.63Smrg 1611.67Smycroftif [ "$yppasswdd_flags" != NO ]; then 1621.67Smycroft if [ "$yppasswdd_flags" = DEFAULT ]; then 1631.67Smycroft yppasswdd_flags="" 1641.67Smycroft fi 1651.63Smrg echo -n ' rpc.yppasswdd'; rpc.yppasswdd $yppasswdd_flags 1661.63Smrgfi 1671.63Smrg 1681.67Smycroftif [ "$bootparamd_flags" != NO ] && [ -r /etc/bootparams ]; then 1691.67Smycroft if [ "$bootparamd_flags" = DEFAULT ]; then 1701.67Smycroft bootparamd_flags="" 1711.67Smycroft fi 1721.63Smrg echo -n ' rpc.bootparamd'; rpc.bootparamd $bootparamd_flags 1731.63Smrgfi 1741.63Smrg 1751.84Sveegoecho '.' 1761.84Sveego 1771.84Sveego# load kernel modules specified in /etc/lkm.conf 1781.84Sveegoif [ "$lkm_init" != NO ] && [ -f /etc/rc.lkm ]; then 1791.84Sveego lkmstage=BEFOREMOUNT 1801.84Sveego . /etc/rc.lkm 1811.84Sveegofi 1821.84Sveego 1831.84Sveegomount -a 1841.84Sveego 1851.84Sveego# now start the rpc servers, for NFS server/client. 1861.84Sveegoecho -n 'starting nfs-rpc daemons:' 1871.84Sveego 1881.67Smycroftnfs_locking=NO 1891.67Smycroft 1901.67Smycroftif [ "$nfs_server" = YES ] && [ -r /etc/exports ]; then 1911.69Smycroft if [ "$mountd_flags" = DEFAULT ]; then 1921.69Smycroft mountd_flags="" 1931.63Smrg fi 1941.63Smrg rm -f /var/db/mountdtab 1951.63Smrg echo -n > /var/db/mountdtab 1961.63Smrg echo -n ' mountd'; mountd $mountd_flags 1971.69Smycroft if [ "$nfsd_flags" = DEFAULT ]; then 1981.69Smycroft nfsd_flags="-tun 4" 1991.69Smycroft fi 2001.63Smrg echo -n ' nfsd'; nfsd $nfsd_flags 2011.67Smycroft nfs_locking=MAYBE 2021.1Scgdfi 2031.63Smrg 2041.67Smycroftif [ "$nfs_client" = YES ]; then 2051.67Smycroft if [ "$nfsiod_flags" = DEFAULT ]; then 2061.63Smrg nfsiod_flags="-n 4" 2071.63Smrg fi 2081.63Smrg echo -n ' nfsiod'; nfsiod $nfsiod_flags 2091.67Smycroft nfs_locking=MAYBE 2101.66Sscottrfi 2111.66Sscottr 2121.67Smycroftif [ "$nfs_locking" != NO ]; then 2131.67Smycroft if [ "$statd_flags" != NO ]; then 2141.67Smycroft if [ "$statd_flags" = DEFAULT ]; then 2151.67Smycroft statd_flags="" 2161.67Smycroft fi 2171.71Smycroft echo -n ' rpc.statd'; rpc.statd $statd_flags 2181.66Sscottr fi 2191.66Sscottr 2201.67Smycroft if [ "$lockd_flags" != NO ]; then 2211.67Smycroft if [ "$lockd_flags" = DEFAULT ]; then 2221.67Smycroft lockd_flags="" 2231.67Smycroft fi 2241.71Smycroft echo -n ' rpc.lockd'; rpc.lockd $lockd_flags 2251.66Sscottr fi 2261.63Smrgfi 2271.63Smrg 2281.67Smycroftif [ "$amd_flags" != NO ] && [ -d "$amd_dir" -a -r "$amd_master" ]; then 2291.67Smycroft if [ "$amd_flags" = DEFAULT ]; then 2301.67Smycroft amd_flags="-l syslog -x error,noinfo,nostats" 2311.67Smycroft fi 2321.63Smrg echo -n ' amd' 2331.63Smrg amd $amd_flags -p -a $amd_dir `cat $amd_master` > /var/run/amd.pid 2341.63Smrgfi 2351.63Smrg 2361.1Scgdecho '.' 2371.83Sdrochner 2381.63Smrgif [ -f /sbin/ldconfig ]; then 2391.63Smrg echo 'creating runtime link editor directory cache.' 2401.71Smycroft if [ -f /etc/ld.so.conf ]; then 2411.63Smrg ldconfig `cat /etc/ld.so.conf` 2421.63Smrg else 2431.63Smrg ldconfig 2441.63Smrg fi 2451.63Smrgfi 2461.83Sdrochner 2471.83Sdrochner# load kernel modules specified in /etc/lkm.conf 2481.83Sdrochnerif [ "$lkm_init" != NO ] && [ -f /etc/rc.lkm ]; then 2491.83Sdrochner lkmstage=AFTERMOUNT 2501.83Sdrochner . /etc/rc.lkm 2511.1Scgdfi 2521.1Scgd 2531.47Sderaadt echo -n 'checking quotas:' 2541.47Sderaadtquotacheck -a 2551.47Sderaadt echo ' done.' 2561.47Sderaadtquotaon -a 2571.1Scgd 2581.1Scgd# build ps databases 2591.2Scgdecho 'building databases...' 2601.11Scgdkvm_mkdb /netbsd 2611.1Scgddev_mkdb 2621.1Scgd 2631.1Scgdchmod 666 /dev/tty[pqrs]* 2641.1Scgd 2651.1Scgd# check the password temp/lock file 2661.1Scgdif [ -f /etc/ptmp ] 2671.1Scgdthen 2681.1Scgd logger -s -p auth.err \ 2691.1Scgd 'password file may be incorrect -- /etc/ptmp exists' 2701.1Scgdfi 2711.1Scgd 2721.85Sperryvirecovery=`echo /var/tmp/vi.recover/recover.*` 2731.32Smycroftif [ "$virecovery" != "/var/tmp/vi.recover/recover.*" ]; then 2741.32Smycroft echo preserving editor files 2751.32Smycroft for i in $virecovery; do 2761.32Smycroft sendmail -t < $i 2771.32Smycroft done 2781.32Smycroftfi 2791.1Scgd 2801.1Scgdecho clearing /tmp 2811.1Scgd 2821.65Smikel# Prune quickly with one rm, then use find to clean up /tmp/[lq]* (this 2831.65Smikel# is not needed with mfs /tmp, but doesn't hurt anything). 2841.1Scgd(cd /tmp && rm -rf [a-km-pr-zA-Z]* && 2851.46Sderaadt find . ! -name . ! -name lost+found ! -name quota.user \ 2861.46Sderaadt ! -name quota.group -exec rm -rf -- {} \; -type d -prune) 2871.1Scgd 2881.74Sperry# Update kernel info in /etc/motd 2891.74Sperry# Must be done *before* interactive logins are possible to prevent 2901.74Sperry# possible race conditions. 2911.74Sperryif [ "$update_motd" != NO ]; then 2921.74Sperry echo 'updating motd.' 2931.74Sperry if [ ! -f /etc/motd ]; then 2941.74Sperry install -c -o root -g wheel -m 664 /dev/null /etc/motd 2951.74Sperry fi 2961.74Sperry T=/tmp/_motd 2971.74Sperry rm -f $T 2981.74Sperry sysctl -n kern.version | sed 1q > $T 2991.74Sperry echo "" >> $T 3001.74Sperry sed '1,/^$/d' < /etc/motd >> $T 3011.74Sperry cmp -s $T /etc/motd || cp $T /etc/motd 3021.74Sperry rm -f $T 3031.74Sperryfi 3041.74Sperry 3051.34Scgdif [ -f /var/account/acct ]; then 3061.34Scgd echo 'turning on accounting'; accton /var/account/acct 3071.34Scgdfi 3081.1Scgd 3091.1Scgdecho -n standard daemons: 3101.70Smycroftif [ "$update_flags" != NO ]; then 3111.70Smycroft if [ "$update_flags" = DEFAULT ]; then 3121.70Smycroft update_flags="30" 3131.70Smycroft fi 3141.70Smycroft echo -n ' update'; update $update_flags 3151.70Smycroftfi 3161.31Sjtcecho -n ' cron'; cron 3171.1Scgdecho '.' 3181.1Scgd 3191.63Smrg# now start all the other daemons 3201.1Scgdecho -n starting network daemons: 3211.1Scgd 3221.67Smycroftif [ "$gated_flags" != NO ] && [ -r /etc/gated.conf ]; then 3231.67Smycroft if [ "$gated_flags" = DEFAULT ]; then 3241.67Smycroft gated_flags="" 3251.67Smycroft fi 3261.48Smycroft echo -n ' gated'; gated $gated_flags 3271.67Smycroftelif [ "$routed_flags" != NO ]; then 3281.67Smycroft if [ "$routed_flags" = DEFAULT ]; then 3291.67Smycroft routed_flags="-q" 3301.67Smycroft fi 3311.48Smycroft echo -n ' routed'; routed $routed_flags 3321.1Scgdfi 3331.1Scgd 3341.67Smycroftif [ "$mrouted_flags" != NO ]; then 3351.67Smycroft if [ "$mrouted_flags" = DEFAULT ]; then 3361.67Smycroft mrouted_flags="" 3371.67Smycroft fi 3381.55Sthorpej echo -n ' mrouted'; mrouted $mrouted_flags 3391.55Sthorpejfi 3401.55Sthorpej 3411.67Smycroftif [ "$timed_flags" != NO ]; then 3421.67Smycroft if [ "$timed_flags" = DEFAULT ]; then 3431.67Smycroft timed_flags="" 3441.67Smycroft fi 3451.67Smycroft echo -n ' timed'; timed $timed_flags 3461.75Sperryfi 3471.75Sperry 3481.75Sperryif [ "$ntpdate_hosts" != NO ]; then 3491.75Sperry if [ "$ntpdate_hosts" = DEFAULT ]; then 3501.75Sperry ntpdate_hosts=`awk '/^server/ {print $2}' </etc/ntp.conf` 3511.75Sperry fi 3521.75Sperry 3531.75Sperry if [ -n "$ntpdate_hosts" ]; then 3541.75Sperry echo -n 'ntpdate:' 3551.75Sperry ntpdate -b $ntpdate_hosts 3561.75Sperry fi 3571.63Smrgfi 3581.63Smrg 3591.67Smycroftif [ "$xntpd_flags" != NO ]; then 3601.67Smycroft if [ "$xntpd_flags" = DEFAULT ]; then 3611.77Scjs xntpd_flags="-p /var/run/xntpd.pid" 3621.67Smycroft fi 3631.67Smycroft echo -n ' xntpd'; xntpd $xntpd_flags 3641.61Smrgfi 3651.61Smrg 3661.67Smycroftif [ "$dhcpd_flags" != NO ] && [ -r /etc/dhcpd.conf ]; then 3671.67Smycroft if [ "$dhcpd_flags" = DEFAULT ]; then 3681.67Smycroft dhcpd_flags="" 3691.67Smycroft fi 3701.61Smrg echo -n ' dhcpd'; dhcpd $dhcpd_flags 3711.29Smycroftfi 3721.29Smycroft 3731.67Smycroftif [ "$rwhod" = YES ]; then 3741.48Smycroft echo -n ' rwhod'; rwhod 3751.1Scgdfi 3761.1Scgd 3771.67Smycroftif [ "$lpd_flags" != NO ]; then 3781.67Smycroft if [ "$lpd_flags" = DEFAULT ]; then 3791.67Smycroft lpd_flags="" 3801.67Smycroft fi 3811.63Smrg echo -n ' printer'; lpd $lpd_flags 3821.60Stlsfi 3831.60Stls 3841.63Smrg# We call sendmail with a full path so that SIGHUP works. 3851.67Smycroftif [ "$sendmail_flags" != NO ] && [ -r /etc/sendmail.cf ]; then 3861.67Smycroft if [ "$sendmail_flags" = DEFAULT ]; then 3871.67Smycroft sendmail_flags="-bd -q30m" 3881.67Smycroft fi 3891.63Smrg echo -n ' sendmail'; /usr/sbin/sendmail $sendmail_flags 3901.60Stlsfi 3911.60Stls 3921.67Smycroftif [ "$rarpd_flags" != NO ] && [ -r /etc/ethers ]; then 3931.67Smycroft if [ "$rarpd_flags" = DEFAULT ]; then 3941.67Smycroft rarpd_flags="-a" 3951.67Smycroft fi 3961.63Smrg echo -n ' rarpd'; rarpd $rarpd_flags 3971.60Stlsfi 3981.60Stls 3991.67Smycroftif [ "$rbootd_flags" != NO ] && [ -r /etc/rbootd.conf ]; then 4001.67Smycroft if [ "$rbootd_flags" = DEFAULT ]; then 4011.67Smycroft rbootd_flags="" 4021.67Smycroft fi 4031.63Smrg echo -n ' rbootd'; rbootd $rbootd_flags 4041.72Scjsfi 4051.72Scjs 4061.72Scjsif [ "$mopd_flags" != NO ]; then 4071.72Scjs if [ "$mopd_flags" = DEFAULT ]; then 4081.72Scjs mopd_flags="-a" 4091.72Scjs fi 4101.72Scjs echo -n ' mopd'; mopd $mopd_flags 4111.52Sthorpejfi 4121.52Sthorpej 4131.67Smycroftif [ "$inetd_flags" != NO ] && [ -r /etc/inetd.conf ]; then 4141.67Smycroft if [ "$inetd_flags" = DEFAULT ]; then 4151.67Smycroft inetd_flags="" 4161.67Smycroft fi 4171.63Smrg echo -n ' inetd'; inetd $inetd_flags 4181.30Smycroftfi 4191.30Smycroft 4201.1Scgdecho '.' 4211.73Sperry 4221.73Sperry# Kerberos runs ONLY on the Kerberos server machine 4231.73Sperryif [ "$kerberos_server" = YES ]; then 4241.73Sperry echo -n 'starting kerberos daemons:' 4251.73Sperry echo -n ' kerberos'; kerberos >> /var/log/kerberos.log & 4261.73Sperry echo -n ' kadmind'; kadmind -n >> /var/log/kadmind.log & 4271.73Sperry echo '.' 4281.73Sperryfi 4291.1Scgd 4301.25Smycroft. /etc/rc.local 4311.1Scgd 4321.1Scgddate 4331.1Scgdexit 0 434