rc revision 1.93
11.93Sdrochner# $NetBSD: rc,v 1.93 1997/09/12 10:36:04 drochner 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.63Smrgfi 1321.63Smrg 1331.84Sveego# /var/crash should be a directory or a symbolic link 1341.84Sveego# to the crash directory if core dumps are to be saved. 1351.89Scjsif checkyesno savecore; then 1361.89Scjs if [ -d /var/crash ]; then 1371.89Scjs echo checking for core dump... 1381.89Scjs savecore $savecore_flags /var/crash 1391.89Scjs else 1401.89Scjs logger -s "WARNING: no /var/crash directory; savecore not run." 1411.84Sveego fi 1421.84Sveegofi 1431.84Sveego 1441.89Scjsif checkyesno named; then 1451.89Scjs echo 'starting name server'; named $named_flags 1461.89Scjsfi 1471.89Scjs 1481.89Scjs# set time, if requested 1491.89Scjsif checkyesno ntpdate; then 1501.91Smikel if [ -z "$ntpdate_hosts" ]; then 1511.89Scjs ntpdate_hosts=`awk '/^server/ {print $2}' </etc/ntp.conf` 1521.89Scjs fi 1531.89Scjs if [ -n "$ntpdate_hosts" ]; then 1541.89Scjs echo 'Setting date via ntp.' 1551.89Scjs ntpdate -b $ntpdate_hosts 1561.67Smycroft fi 1571.63Smrgfi 1581.63Smrg 1591.84Sveego# now start the rpc servers, for YP server/client. 1601.63Smrgecho -n 'starting rpc daemons:' 1611.63Smrg 1621.63Smrg# note that portmap is generally required for all other rpc services. 1631.89Scjsif checkyesno portmap; then 1641.63Smrg echo -n ' portmap'; portmap 1651.63Smrgfi 1661.63Smrg 1671.89Scjsif checkyesno ypserv; then 1681.63Smrg echo -n ' ypserv'; ypserv $ypserv_flags 1691.63Smrgfi 1701.63Smrg 1711.89Scjsif checkyesno ypbind; then 1721.63Smrg echo -n ' ypbind'; ypbind $ypbind_flags 1731.63Smrgfi 1741.63Smrg 1751.89Scjsif checkyesno yppasswdd; then 1761.63Smrg echo -n ' rpc.yppasswdd'; rpc.yppasswdd $yppasswdd_flags 1771.63Smrgfi 1781.63Smrg 1791.89Scjsif checkyesno bootparamd; then 1801.89Scjs if [ -r /etc/bootparams ]; then 1811.89Scjs echo -n ' rpc.bootparamd'; rpc.bootparamd $bootparamd_flags 1821.89Scjs else 1831.89Scjs echo 1841.89Scjs logger -s "WARNING: /etc/bootparams not found. " \ 1851.89Scjs "bootparamd not started." 1861.67Smycroft fi 1871.63Smrgfi 1881.63Smrg 1891.84Sveegoecho '.' 1901.84Sveego 1911.84Sveego# load kernel modules specified in /etc/lkm.conf 1921.89Scjsif checkyesno lkm; then 1931.89Scjs if [ -r /etc/rc.lkm ]; then 1941.89Scjs lkmstage=BEFOREMOUNT 1951.89Scjs . /etc/rc.lkm 1961.89Scjs else 1971.89Scjs logger -s "WARNING: /etc/rc.lkm not found; LKMs not loaded." 1981.89Scjs fi 1991.84Sveegofi 2001.84Sveego 2011.84Sveegomount -a 2021.84Sveego 2031.84Sveego# now start the rpc servers, for NFS server/client. 2041.90Sveegoecho -n 'starting nfs daemons:' 2051.84Sveego 2061.67Smycroftnfs_locking=NO 2071.67Smycroft 2081.89Scjsif checkyesno nfs_server; then 2091.89Scjs if [ -r /etc/exports ]; then 2101.89Scjs rm -f /var/db/mountdtab 2111.89Scjs echo -n > /var/db/mountdtab 2121.89Scjs echo -n ' mountd'; mountd $mountd_flags 2131.89Scjs echo -n ' nfsd'; nfsd $nfsd_flags 2141.89Scjs nfs_locking=MAYBE 2151.89Scjs else 2161.89Scjs echo 2171.89Scjs logger -s "WARNING: /etc/exports not readable; " \ 2181.89Scjs "NFS server not started." 2191.69Smycroft fi 2201.1Scgdfi 2211.63Smrg 2221.89Scjsif checkyesno nfs_client; then 2231.63Smrg echo -n ' nfsiod'; nfsiod $nfsiod_flags 2241.67Smycroft nfs_locking=MAYBE 2251.66Sscottrfi 2261.66Sscottr 2271.67Smycroftif [ "$nfs_locking" != NO ]; then 2281.89Scjs if checkyesno statd; then 2291.71Smycroft echo -n ' rpc.statd'; rpc.statd $statd_flags 2301.66Sscottr fi 2311.89Scjs if checkyesno lockd; then 2321.71Smycroft echo -n ' rpc.lockd'; rpc.lockd $lockd_flags 2331.66Sscottr fi 2341.63Smrgfi 2351.63Smrg 2361.89Scjsif checkyesno amd; then 2371.89Scjs if [ -d "$amd_dir" ]; then 2381.89Scjs if [ -r "$amd_master" ]; then 2391.89Scjs echo -n ' amd' 2401.89Scjs amd $amd_flags -p -a $amd_dir `cat $amd_master` \ 2411.89Scjs > /var/run/amd.pid 2421.89Scjs else 2431.89Scjs echo 2441.89Scjs logger -s "WARNING: \$amd_master ($amd_master)not " \ 2451.89Scjs "readable; amd not started." 2461.89Scjs fi 2471.89Scjs else 2481.89Scjs echo 2491.89Scjs logger -s "WARNING: \$amd_dir ($amd_dir) not a directory; " \ 2501.89Scjs "amd not started." 2511.67Smycroft fi 2521.63Smrgfi 2531.63Smrg 2541.1Scgdecho '.' 2551.83Sdrochner 2561.63Smrgif [ -f /sbin/ldconfig ]; then 2571.63Smrg echo 'creating runtime link editor directory cache.' 2581.88Sthorpej ldconfig 2591.63Smrgfi 2601.83Sdrochner 2611.83Sdrochner# load kernel modules specified in /etc/lkm.conf 2621.89Scjsif checkyesno lkm && [ -f /etc/rc.lkm ]; then 2631.83Sdrochner lkmstage=AFTERMOUNT 2641.83Sdrochner . /etc/rc.lkm 2651.1Scgdfi 2661.1Scgd 2671.89Scjsecho -n 'checking quotas:'; quotacheck -a; echo ' done.' 2681.47Sderaadtquotaon -a 2691.1Scgd 2701.1Scgd# build ps databases 2711.2Scgdecho 'building databases...' 2721.11Scgdkvm_mkdb /netbsd 2731.1Scgddev_mkdb 2741.1Scgd 2751.1Scgdchmod 666 /dev/tty[pqrs]* 2761.1Scgd 2771.1Scgd# check the password temp/lock file 2781.1Scgdif [ -f /etc/ptmp ] 2791.1Scgdthen 2801.1Scgd logger -s -p auth.err \ 2811.1Scgd 'password file may be incorrect -- /etc/ptmp exists' 2821.1Scgdfi 2831.1Scgd 2841.85Sperryvirecovery=`echo /var/tmp/vi.recover/recover.*` 2851.32Smycroftif [ "$virecovery" != "/var/tmp/vi.recover/recover.*" ]; then 2861.32Smycroft echo preserving editor files 2871.32Smycroft for i in $virecovery; do 2881.32Smycroft sendmail -t < $i 2891.32Smycroft done 2901.32Smycroftfi 2911.1Scgd 2921.1Scgdecho clearing /tmp 2931.1Scgd 2941.65Smikel# Prune quickly with one rm, then use find to clean up /tmp/[lq]* (this 2951.65Smikel# is not needed with mfs /tmp, but doesn't hurt anything). 2961.1Scgd(cd /tmp && rm -rf [a-km-pr-zA-Z]* && 2971.46Sderaadt find . ! -name . ! -name lost+found ! -name quota.user \ 2981.46Sderaadt ! -name quota.group -exec rm -rf -- {} \; -type d -prune) 2991.1Scgd 3001.74Sperry# Update kernel info in /etc/motd 3011.74Sperry# Must be done *before* interactive logins are possible to prevent 3021.74Sperry# possible race conditions. 3031.89Scjsif checkyesno update_motd; then 3041.74Sperry echo 'updating motd.' 3051.74Sperry if [ ! -f /etc/motd ]; then 3061.74Sperry install -c -o root -g wheel -m 664 /dev/null /etc/motd 3071.74Sperry fi 3081.74Sperry T=/tmp/_motd 3091.74Sperry rm -f $T 3101.74Sperry sysctl -n kern.version | sed 1q > $T 3111.74Sperry echo "" >> $T 3121.74Sperry sed '1,/^$/d' < /etc/motd >> $T 3131.74Sperry cmp -s $T /etc/motd || cp $T /etc/motd 3141.74Sperry rm -f $T 3151.74Sperryfi 3161.74Sperry 3171.34Scgdif [ -f /var/account/acct ]; then 3181.34Scgd echo 'turning on accounting'; accton /var/account/acct 3191.34Scgdfi 3201.1Scgd 3211.1Scgdecho -n standard daemons: 3221.89Scjsif checkyesno update; then 3231.70Smycroft echo -n ' update'; update $update_flags 3241.70Smycroftfi 3251.31Sjtcecho -n ' cron'; cron 3261.1Scgdecho '.' 3271.1Scgd 3281.63Smrg# now start all the other daemons 3291.1Scgdecho -n starting network daemons: 3301.1Scgd 3311.89Scjsif checkyesno gated && checkyesno routed; then 3321.89Scjs echo 3331.89Scjs logger -s "WARNING: gated and routed both requested to be run: " \ 3341.89Scjs "running only gated." 3351.89Scjs routed=NO 3361.89Scjsfi 3371.89Scjs 3381.89Scjsif checkyesno gated; then 3391.89Scjs if [ -r /etc/gated.conf ]; then 3401.89Scjs echo -n ' gated'; gated $gated_flags 3411.89Scjs else 3421.89Scjs logger -s "WARNING: no /etc/gated.conf; gated not started." 3431.67Smycroft fi 3441.89Scjsfi 3451.89Scjs 3461.89Scjsif checkyesno routed; then 3471.48Smycroft echo -n ' routed'; routed $routed_flags 3481.1Scgdfi 3491.1Scgd 3501.89Scjsif checkyesno mrouted; then 3511.55Sthorpej echo -n ' mrouted'; mrouted $mrouted_flags 3521.55Sthorpejfi 3531.55Sthorpej 3541.89Scjsif checkyesno timed; then 3551.67Smycroft echo -n ' timed'; timed $timed_flags 3561.63Smrgfi 3571.63Smrg 3581.89Scjsif checkyesno xntpd; then 3591.67Smycroft echo -n ' xntpd'; xntpd $xntpd_flags 3601.61Smrgfi 3611.61Smrg 3621.89Scjsif checkyesno dhcpd; then 3631.89Scjs if [ -r /etc/dhcpd.conf ]; then 3641.89Scjs echo -n ' dhcpd'; dhcpd $dhcpd_flags 3651.89Scjs else 3661.89Scjs echo 3671.89Scjs logger -s "WARNING: /etc/dhcpd.conf not readable; " \ 3681.89Scjs "dhcpd not started." 3691.67Smycroft fi 3701.29Smycroftfi 3711.29Smycroft 3721.89Scjsif checkyesno rwhod; then 3731.48Smycroft echo -n ' rwhod'; rwhod 3741.1Scgdfi 3751.1Scgd 3761.89Scjsif checkyesno lpd; then 3771.89Scjs echo -n ' lpd'; lpd $lpd_flags 3781.60Stlsfi 3791.60Stls 3801.63Smrg# We call sendmail with a full path so that SIGHUP works. 3811.89Scjsif checkyesno sendmail; then 3821.89Scjs if [ -r /etc/sendmail.cf ]; then 3831.89Scjs echo -n ' sendmail'; /usr/sbin/sendmail $sendmail_flags 3841.89Scjs else 3851.89Scjs echo 3861.89Scjs logger -s "WARNING: /etc/sendmail.cf not readable; " \ 3871.89Scjs "sendmail not started." 3881.67Smycroft fi 3891.60Stlsfi 3901.60Stls 3911.89Scjsif checkyesno rarpd; then 3921.89Scjs if [ -r /etc/ethers ]; then 3931.89Scjs echo -n ' rarpd'; rarpd $rarpd_flags 3941.89Scjs else 3951.89Scjs echo 3961.89Scjs logger -s "WARNING: /etc/ethers not readable; " \ 3971.89Scjs "rarpd not started." 3981.67Smycroft fi 3991.60Stlsfi 4001.60Stls 4011.89Scjsif checkyesno rbootd; then 4021.89Scjs if [ -r /etc/rbootd.conf ]; then 4031.89Scjs echo -n ' rbootd'; rbootd $rbootd_flags 4041.89Scjs else 4051.89Scjs echo 4061.89Scjs logger -s "WARNING: /etc/rbootd.conf not readable; " \ 4071.89Scjs "rarpd not started." 4081.67Smycroft fi 4091.72Scjsfi 4101.72Scjs 4111.89Scjsif checkyesno mopd; then 4121.72Scjs echo -n ' mopd'; mopd $mopd_flags 4131.86Sperryfi 4141.86Sperry 4151.89Scjsif checkyesno apmd; then 4161.86Sperry echo -n ' apmd'; apmd $apmd_flags 4171.52Sthorpejfi 4181.52Sthorpej 4191.89Scjsif checkyesno inetd; then 4201.89Scjs if [ -r /etc/inetd.conf ]; then 4211.89Scjs echo -n ' inetd'; inetd $inetd_flags 4221.89Scjs else 4231.89Scjs echo 4241.89Scjs logger -s "WARNING: /etc/inetd.conf not readable; " \ 4251.89Scjs "inetd not started." 4261.67Smycroft fi 4271.30Smycroftfi 4281.30Smycroft 4291.1Scgdecho '.' 4301.73Sperry 4311.73Sperry# Kerberos runs ONLY on the Kerberos server machine 4321.89Scjsif checkyesno kerberos; then 4331.73Sperry echo -n 'starting kerberos daemons:' 4341.73Sperry echo -n ' kerberos'; kerberos >> /var/log/kerberos.log & 4351.73Sperry echo -n ' kadmind'; kadmind -n >> /var/log/kadmind.log & 4361.73Sperry echo '.' 4371.73Sperryfi 4381.1Scgd 4391.25Smycroft. /etc/rc.local 4401.1Scgd 4411.1Scgddate 4421.1Scgdexit 0 443