rc revision 1.94
11.94Slukem# $NetBSD: rc,v 1.94 1997/10/07 12:11:48 lukem 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.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.92Sdrochnerif [ ! -d /usr/bin ]; then 1081.92Sdrochner mount /usr >/dev/null 2>&1 1091.92Sdrochnerfi 1101.42Smycroftmount /var >/dev/null 2>&1 1111.79Sthorpej 1121.79Sthorpej# "Critical" file systems are now mounted. Go ahead and swap 1131.79Sthorpej# to files now, since they will be residing in the critical file 1141.79Sthorpej# systems (or, at least, better). 1151.79Sthorpejswapctl -A -t noblk 1161.26Sderaadt 1171.41Sjtc# clean up left-over files 1181.41Sjtcrm -f /etc/nologin 1191.41Sjtcrm -f /var/spool/lock/LCK.* 1201.41Sjtcrm -f /var/spool/uucp/STST/* 1211.45Scgd(cd /var/run && { rm -rf -- *; install -c -m 664 -g utmp /dev/null utmp; }) 1221.41Sjtc 1231.84Sveego# start the system logger first, so that all messages from daemons 1241.84Sveego# are logged, then start savecore to get a dump on low memory systems 1251.84Sveego# and then start the name server. 1261.63Smrg 1271.89Scjsif checkyesno syslogd; then 1281.63Smrg echo 'starting system logger' 1291.63Smrg rm -f /dev/log 1301.63Smrg syslogd $syslogd_flags 1311.94Slukemfi 1321.94Slukem 1331.94Slukem# Enable ipmon (only useful if ipfilter is running) 1341.94Slukem# NOTE: requires the IPFILTER_LOG kernel option. 1351.94Slukemif checkyesno ipmon; then 1361.94Slukem echo 'starting ipmon' 1371.94Slukem ipmon $ipmon_flags & 1381.63Smrgfi 1391.63Smrg 1401.84Sveego# /var/crash should be a directory or a symbolic link 1411.84Sveego# to the crash directory if core dumps are to be saved. 1421.89Scjsif checkyesno savecore; then 1431.89Scjs if [ -d /var/crash ]; then 1441.89Scjs echo checking for core dump... 1451.89Scjs savecore $savecore_flags /var/crash 1461.89Scjs else 1471.89Scjs logger -s "WARNING: no /var/crash directory; savecore not run." 1481.84Sveego fi 1491.84Sveegofi 1501.84Sveego 1511.89Scjsif checkyesno named; then 1521.89Scjs echo 'starting name server'; named $named_flags 1531.89Scjsfi 1541.89Scjs 1551.89Scjs# set time, if requested 1561.89Scjsif checkyesno ntpdate; then 1571.91Smikel if [ -z "$ntpdate_hosts" ]; then 1581.89Scjs ntpdate_hosts=`awk '/^server/ {print $2}' </etc/ntp.conf` 1591.89Scjs fi 1601.89Scjs if [ -n "$ntpdate_hosts" ]; then 1611.89Scjs echo 'Setting date via ntp.' 1621.89Scjs ntpdate -b $ntpdate_hosts 1631.67Smycroft fi 1641.63Smrgfi 1651.63Smrg 1661.84Sveego# now start the rpc servers, for YP server/client. 1671.63Smrgecho -n 'starting rpc daemons:' 1681.63Smrg 1691.63Smrg# note that portmap is generally required for all other rpc services. 1701.89Scjsif checkyesno portmap; then 1711.63Smrg echo -n ' portmap'; portmap 1721.63Smrgfi 1731.63Smrg 1741.89Scjsif checkyesno ypserv; then 1751.63Smrg echo -n ' ypserv'; ypserv $ypserv_flags 1761.63Smrgfi 1771.63Smrg 1781.89Scjsif checkyesno ypbind; then 1791.63Smrg echo -n ' ypbind'; ypbind $ypbind_flags 1801.63Smrgfi 1811.63Smrg 1821.89Scjsif checkyesno yppasswdd; then 1831.63Smrg echo -n ' rpc.yppasswdd'; rpc.yppasswdd $yppasswdd_flags 1841.63Smrgfi 1851.63Smrg 1861.89Scjsif checkyesno bootparamd; then 1871.89Scjs if [ -r /etc/bootparams ]; then 1881.89Scjs echo -n ' rpc.bootparamd'; rpc.bootparamd $bootparamd_flags 1891.89Scjs else 1901.89Scjs echo 1911.89Scjs logger -s "WARNING: /etc/bootparams not found. " \ 1921.89Scjs "bootparamd not started." 1931.67Smycroft fi 1941.63Smrgfi 1951.63Smrg 1961.84Sveegoecho '.' 1971.84Sveego 1981.84Sveego# load kernel modules specified in /etc/lkm.conf 1991.89Scjsif checkyesno lkm; then 2001.89Scjs if [ -r /etc/rc.lkm ]; then 2011.89Scjs lkmstage=BEFOREMOUNT 2021.89Scjs . /etc/rc.lkm 2031.89Scjs else 2041.89Scjs logger -s "WARNING: /etc/rc.lkm not found; LKMs not loaded." 2051.89Scjs fi 2061.84Sveegofi 2071.84Sveego 2081.84Sveegomount -a 2091.84Sveego 2101.84Sveego# now start the rpc servers, for NFS server/client. 2111.90Sveegoecho -n 'starting nfs daemons:' 2121.84Sveego 2131.67Smycroftnfs_locking=NO 2141.67Smycroft 2151.89Scjsif checkyesno nfs_server; then 2161.89Scjs if [ -r /etc/exports ]; then 2171.89Scjs rm -f /var/db/mountdtab 2181.89Scjs echo -n > /var/db/mountdtab 2191.89Scjs echo -n ' mountd'; mountd $mountd_flags 2201.89Scjs echo -n ' nfsd'; nfsd $nfsd_flags 2211.89Scjs nfs_locking=MAYBE 2221.89Scjs else 2231.89Scjs echo 2241.89Scjs logger -s "WARNING: /etc/exports not readable; " \ 2251.89Scjs "NFS server not started." 2261.69Smycroft fi 2271.1Scgdfi 2281.63Smrg 2291.89Scjsif checkyesno nfs_client; then 2301.63Smrg echo -n ' nfsiod'; nfsiod $nfsiod_flags 2311.67Smycroft nfs_locking=MAYBE 2321.66Sscottrfi 2331.66Sscottr 2341.67Smycroftif [ "$nfs_locking" != NO ]; then 2351.89Scjs if checkyesno statd; then 2361.71Smycroft echo -n ' rpc.statd'; rpc.statd $statd_flags 2371.66Sscottr fi 2381.89Scjs if checkyesno lockd; then 2391.71Smycroft echo -n ' rpc.lockd'; rpc.lockd $lockd_flags 2401.66Sscottr fi 2411.63Smrgfi 2421.63Smrg 2431.89Scjsif checkyesno amd; then 2441.89Scjs if [ -d "$amd_dir" ]; then 2451.89Scjs if [ -r "$amd_master" ]; then 2461.89Scjs echo -n ' amd' 2471.89Scjs amd $amd_flags -p -a $amd_dir `cat $amd_master` \ 2481.89Scjs > /var/run/amd.pid 2491.89Scjs else 2501.89Scjs echo 2511.89Scjs logger -s "WARNING: \$amd_master ($amd_master)not " \ 2521.89Scjs "readable; amd not started." 2531.89Scjs fi 2541.89Scjs else 2551.89Scjs echo 2561.89Scjs logger -s "WARNING: \$amd_dir ($amd_dir) not a directory; " \ 2571.89Scjs "amd not started." 2581.67Smycroft fi 2591.63Smrgfi 2601.63Smrg 2611.1Scgdecho '.' 2621.83Sdrochner 2631.63Smrgif [ -f /sbin/ldconfig ]; then 2641.63Smrg echo 'creating runtime link editor directory cache.' 2651.88Sthorpej ldconfig 2661.63Smrgfi 2671.83Sdrochner 2681.83Sdrochner# load kernel modules specified in /etc/lkm.conf 2691.89Scjsif checkyesno lkm && [ -f /etc/rc.lkm ]; then 2701.83Sdrochner lkmstage=AFTERMOUNT 2711.83Sdrochner . /etc/rc.lkm 2721.1Scgdfi 2731.1Scgd 2741.89Scjsecho -n 'checking quotas:'; quotacheck -a; echo ' done.' 2751.47Sderaadtquotaon -a 2761.1Scgd 2771.1Scgd# build ps databases 2781.2Scgdecho 'building databases...' 2791.11Scgdkvm_mkdb /netbsd 2801.1Scgddev_mkdb 2811.1Scgd 2821.1Scgdchmod 666 /dev/tty[pqrs]* 2831.1Scgd 2841.1Scgd# check the password temp/lock file 2851.1Scgdif [ -f /etc/ptmp ] 2861.1Scgdthen 2871.1Scgd logger -s -p auth.err \ 2881.1Scgd 'password file may be incorrect -- /etc/ptmp exists' 2891.1Scgdfi 2901.1Scgd 2911.85Sperryvirecovery=`echo /var/tmp/vi.recover/recover.*` 2921.32Smycroftif [ "$virecovery" != "/var/tmp/vi.recover/recover.*" ]; then 2931.32Smycroft echo preserving editor files 2941.32Smycroft for i in $virecovery; do 2951.32Smycroft sendmail -t < $i 2961.32Smycroft done 2971.32Smycroftfi 2981.1Scgd 2991.1Scgdecho clearing /tmp 3001.1Scgd 3011.65Smikel# Prune quickly with one rm, then use find to clean up /tmp/[lq]* (this 3021.65Smikel# is not needed with mfs /tmp, but doesn't hurt anything). 3031.1Scgd(cd /tmp && rm -rf [a-km-pr-zA-Z]* && 3041.46Sderaadt find . ! -name . ! -name lost+found ! -name quota.user \ 3051.46Sderaadt ! -name quota.group -exec rm -rf -- {} \; -type d -prune) 3061.1Scgd 3071.74Sperry# Update kernel info in /etc/motd 3081.74Sperry# Must be done *before* interactive logins are possible to prevent 3091.74Sperry# possible race conditions. 3101.89Scjsif checkyesno update_motd; then 3111.74Sperry echo 'updating motd.' 3121.74Sperry if [ ! -f /etc/motd ]; then 3131.74Sperry install -c -o root -g wheel -m 664 /dev/null /etc/motd 3141.74Sperry fi 3151.74Sperry T=/tmp/_motd 3161.74Sperry rm -f $T 3171.74Sperry sysctl -n kern.version | sed 1q > $T 3181.74Sperry echo "" >> $T 3191.74Sperry sed '1,/^$/d' < /etc/motd >> $T 3201.74Sperry cmp -s $T /etc/motd || cp $T /etc/motd 3211.74Sperry rm -f $T 3221.74Sperryfi 3231.74Sperry 3241.34Scgdif [ -f /var/account/acct ]; then 3251.34Scgd echo 'turning on accounting'; accton /var/account/acct 3261.34Scgdfi 3271.1Scgd 3281.1Scgdecho -n standard daemons: 3291.89Scjsif checkyesno update; then 3301.70Smycroft echo -n ' update'; update $update_flags 3311.70Smycroftfi 3321.31Sjtcecho -n ' cron'; cron 3331.1Scgdecho '.' 3341.1Scgd 3351.63Smrg# now start all the other daemons 3361.1Scgdecho -n starting network daemons: 3371.1Scgd 3381.89Scjsif checkyesno gated && checkyesno routed; then 3391.89Scjs echo 3401.89Scjs logger -s "WARNING: gated and routed both requested to be run: " \ 3411.89Scjs "running only gated." 3421.89Scjs routed=NO 3431.89Scjsfi 3441.89Scjs 3451.89Scjsif checkyesno gated; then 3461.89Scjs if [ -r /etc/gated.conf ]; then 3471.89Scjs echo -n ' gated'; gated $gated_flags 3481.89Scjs else 3491.89Scjs logger -s "WARNING: no /etc/gated.conf; gated not started." 3501.67Smycroft fi 3511.89Scjsfi 3521.89Scjs 3531.89Scjsif checkyesno routed; then 3541.48Smycroft echo -n ' routed'; routed $routed_flags 3551.1Scgdfi 3561.1Scgd 3571.89Scjsif checkyesno mrouted; then 3581.55Sthorpej echo -n ' mrouted'; mrouted $mrouted_flags 3591.55Sthorpejfi 3601.55Sthorpej 3611.89Scjsif checkyesno timed; then 3621.67Smycroft echo -n ' timed'; timed $timed_flags 3631.63Smrgfi 3641.63Smrg 3651.89Scjsif checkyesno xntpd; then 3661.67Smycroft echo -n ' xntpd'; xntpd $xntpd_flags 3671.61Smrgfi 3681.61Smrg 3691.89Scjsif checkyesno dhcpd; then 3701.89Scjs if [ -r /etc/dhcpd.conf ]; then 3711.89Scjs echo -n ' dhcpd'; dhcpd $dhcpd_flags 3721.89Scjs else 3731.89Scjs echo 3741.89Scjs logger -s "WARNING: /etc/dhcpd.conf not readable; " \ 3751.89Scjs "dhcpd not started." 3761.67Smycroft fi 3771.29Smycroftfi 3781.29Smycroft 3791.89Scjsif checkyesno rwhod; then 3801.48Smycroft echo -n ' rwhod'; rwhod 3811.1Scgdfi 3821.1Scgd 3831.89Scjsif checkyesno lpd; then 3841.89Scjs echo -n ' lpd'; lpd $lpd_flags 3851.60Stlsfi 3861.60Stls 3871.63Smrg# We call sendmail with a full path so that SIGHUP works. 3881.89Scjsif checkyesno sendmail; then 3891.89Scjs if [ -r /etc/sendmail.cf ]; then 3901.89Scjs echo -n ' sendmail'; /usr/sbin/sendmail $sendmail_flags 3911.89Scjs else 3921.89Scjs echo 3931.89Scjs logger -s "WARNING: /etc/sendmail.cf not readable; " \ 3941.89Scjs "sendmail not started." 3951.67Smycroft fi 3961.60Stlsfi 3971.60Stls 3981.89Scjsif checkyesno rarpd; then 3991.89Scjs if [ -r /etc/ethers ]; then 4001.89Scjs echo -n ' rarpd'; rarpd $rarpd_flags 4011.89Scjs else 4021.89Scjs echo 4031.89Scjs logger -s "WARNING: /etc/ethers not readable; " \ 4041.89Scjs "rarpd not started." 4051.67Smycroft fi 4061.60Stlsfi 4071.60Stls 4081.89Scjsif checkyesno rbootd; then 4091.89Scjs if [ -r /etc/rbootd.conf ]; then 4101.89Scjs echo -n ' rbootd'; rbootd $rbootd_flags 4111.89Scjs else 4121.89Scjs echo 4131.89Scjs logger -s "WARNING: /etc/rbootd.conf not readable; " \ 4141.89Scjs "rarpd not started." 4151.67Smycroft fi 4161.72Scjsfi 4171.72Scjs 4181.89Scjsif checkyesno mopd; then 4191.72Scjs echo -n ' mopd'; mopd $mopd_flags 4201.86Sperryfi 4211.86Sperry 4221.89Scjsif checkyesno apmd; then 4231.86Sperry echo -n ' apmd'; apmd $apmd_flags 4241.52Sthorpejfi 4251.52Sthorpej 4261.89Scjsif checkyesno inetd; then 4271.89Scjs if [ -r /etc/inetd.conf ]; then 4281.89Scjs echo -n ' inetd'; inetd $inetd_flags 4291.89Scjs else 4301.89Scjs echo 4311.89Scjs logger -s "WARNING: /etc/inetd.conf not readable; " \ 4321.89Scjs "inetd not started." 4331.67Smycroft fi 4341.30Smycroftfi 4351.30Smycroft 4361.1Scgdecho '.' 4371.73Sperry 4381.73Sperry# Kerberos runs ONLY on the Kerberos server machine 4391.89Scjsif checkyesno kerberos; then 4401.73Sperry echo -n 'starting kerberos daemons:' 4411.73Sperry echo -n ' kerberos'; kerberos >> /var/log/kerberos.log & 4421.73Sperry echo -n ' kadmind'; kadmind -n >> /var/log/kadmind.log & 4431.73Sperry echo '.' 4441.73Sperryfi 4451.1Scgd 4461.25Smycroft. /etc/rc.local 4471.1Scgd 4481.1Scgddate 4491.1Scgdexit 0 450