rc revision 1.95
11.95Sdrochner# $NetBSD: rc,v 1.95 1997/10/10 09:37:54 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.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.79Sthorpej 1211.79Sthorpej# "Critical" file systems are now mounted. Go ahead and swap 1221.79Sthorpej# to files now, since they will be residing in the critical file 1231.79Sthorpej# systems (or, at least, better). 1241.79Sthorpejswapctl -A -t noblk 1251.26Sderaadt 1261.41Sjtc# clean up left-over files 1271.41Sjtcrm -f /etc/nologin 1281.41Sjtcrm -f /var/spool/lock/LCK.* 1291.41Sjtcrm -f /var/spool/uucp/STST/* 1301.45Scgd(cd /var/run && { rm -rf -- *; install -c -m 664 -g utmp /dev/null utmp; }) 1311.41Sjtc 1321.84Sveego# start the system logger first, so that all messages from daemons 1331.84Sveego# are logged, then start savecore to get a dump on low memory systems 1341.84Sveego# and then start the name server. 1351.63Smrg 1361.89Scjsif checkyesno syslogd; then 1371.63Smrg echo 'starting system logger' 1381.63Smrg rm -f /dev/log 1391.63Smrg syslogd $syslogd_flags 1401.94Slukemfi 1411.94Slukem 1421.94Slukem# Enable ipmon (only useful if ipfilter is running) 1431.94Slukem# NOTE: requires the IPFILTER_LOG kernel option. 1441.94Slukemif checkyesno ipmon; then 1451.94Slukem echo 'starting ipmon' 1461.94Slukem ipmon $ipmon_flags & 1471.63Smrgfi 1481.63Smrg 1491.84Sveego# /var/crash should be a directory or a symbolic link 1501.84Sveego# to the crash directory if core dumps are to be saved. 1511.89Scjsif checkyesno savecore; then 1521.89Scjs if [ -d /var/crash ]; then 1531.89Scjs echo checking for core dump... 1541.89Scjs savecore $savecore_flags /var/crash 1551.89Scjs else 1561.89Scjs logger -s "WARNING: no /var/crash directory; savecore not run." 1571.84Sveego fi 1581.84Sveegofi 1591.84Sveego 1601.89Scjsif checkyesno named; then 1611.89Scjs echo 'starting name server'; named $named_flags 1621.89Scjsfi 1631.89Scjs 1641.89Scjs# set time, if requested 1651.89Scjsif checkyesno ntpdate; then 1661.91Smikel if [ -z "$ntpdate_hosts" ]; then 1671.89Scjs ntpdate_hosts=`awk '/^server/ {print $2}' </etc/ntp.conf` 1681.89Scjs fi 1691.89Scjs if [ -n "$ntpdate_hosts" ]; then 1701.89Scjs echo 'Setting date via ntp.' 1711.89Scjs ntpdate -b $ntpdate_hosts 1721.67Smycroft fi 1731.63Smrgfi 1741.63Smrg 1751.84Sveego# now start the rpc servers, for YP server/client. 1761.63Smrgecho -n 'starting rpc daemons:' 1771.63Smrg 1781.63Smrg# note that portmap is generally required for all other rpc services. 1791.89Scjsif checkyesno portmap; then 1801.63Smrg echo -n ' portmap'; portmap 1811.63Smrgfi 1821.63Smrg 1831.89Scjsif checkyesno ypserv; then 1841.63Smrg echo -n ' ypserv'; ypserv $ypserv_flags 1851.63Smrgfi 1861.63Smrg 1871.89Scjsif checkyesno ypbind; then 1881.63Smrg echo -n ' ypbind'; ypbind $ypbind_flags 1891.63Smrgfi 1901.63Smrg 1911.89Scjsif checkyesno yppasswdd; then 1921.63Smrg echo -n ' rpc.yppasswdd'; rpc.yppasswdd $yppasswdd_flags 1931.63Smrgfi 1941.63Smrg 1951.89Scjsif checkyesno bootparamd; then 1961.89Scjs if [ -r /etc/bootparams ]; then 1971.89Scjs echo -n ' rpc.bootparamd'; rpc.bootparamd $bootparamd_flags 1981.89Scjs else 1991.89Scjs echo 2001.89Scjs logger -s "WARNING: /etc/bootparams not found. " \ 2011.89Scjs "bootparamd not started." 2021.67Smycroft fi 2031.63Smrgfi 2041.63Smrg 2051.84Sveegoecho '.' 2061.84Sveego 2071.84Sveego# load kernel modules specified in /etc/lkm.conf 2081.89Scjsif checkyesno lkm; then 2091.89Scjs if [ -r /etc/rc.lkm ]; then 2101.89Scjs lkmstage=BEFOREMOUNT 2111.89Scjs . /etc/rc.lkm 2121.89Scjs else 2131.89Scjs logger -s "WARNING: /etc/rc.lkm not found; LKMs not loaded." 2141.89Scjs fi 2151.84Sveegofi 2161.84Sveego 2171.84Sveegomount -a 2181.84Sveego 2191.84Sveego# now start the rpc servers, for NFS server/client. 2201.90Sveegoecho -n 'starting nfs daemons:' 2211.84Sveego 2221.67Smycroftnfs_locking=NO 2231.67Smycroft 2241.89Scjsif checkyesno nfs_server; then 2251.89Scjs if [ -r /etc/exports ]; then 2261.89Scjs rm -f /var/db/mountdtab 2271.89Scjs echo -n > /var/db/mountdtab 2281.89Scjs echo -n ' mountd'; mountd $mountd_flags 2291.89Scjs echo -n ' nfsd'; nfsd $nfsd_flags 2301.89Scjs nfs_locking=MAYBE 2311.89Scjs else 2321.89Scjs echo 2331.89Scjs logger -s "WARNING: /etc/exports not readable; " \ 2341.89Scjs "NFS server not started." 2351.69Smycroft fi 2361.1Scgdfi 2371.63Smrg 2381.89Scjsif checkyesno nfs_client; then 2391.63Smrg echo -n ' nfsiod'; nfsiod $nfsiod_flags 2401.67Smycroft nfs_locking=MAYBE 2411.66Sscottrfi 2421.66Sscottr 2431.67Smycroftif [ "$nfs_locking" != NO ]; then 2441.89Scjs if checkyesno statd; then 2451.71Smycroft echo -n ' rpc.statd'; rpc.statd $statd_flags 2461.66Sscottr fi 2471.89Scjs if checkyesno lockd; then 2481.71Smycroft echo -n ' rpc.lockd'; rpc.lockd $lockd_flags 2491.66Sscottr fi 2501.63Smrgfi 2511.63Smrg 2521.89Scjsif checkyesno amd; then 2531.89Scjs if [ -d "$amd_dir" ]; then 2541.89Scjs if [ -r "$amd_master" ]; then 2551.89Scjs echo -n ' amd' 2561.89Scjs amd $amd_flags -p -a $amd_dir `cat $amd_master` \ 2571.89Scjs > /var/run/amd.pid 2581.89Scjs else 2591.89Scjs echo 2601.89Scjs logger -s "WARNING: \$amd_master ($amd_master)not " \ 2611.89Scjs "readable; amd not started." 2621.89Scjs fi 2631.89Scjs else 2641.89Scjs echo 2651.89Scjs logger -s "WARNING: \$amd_dir ($amd_dir) not a directory; " \ 2661.89Scjs "amd not started." 2671.67Smycroft fi 2681.63Smrgfi 2691.63Smrg 2701.1Scgdecho '.' 2711.83Sdrochner 2721.63Smrgif [ -f /sbin/ldconfig ]; then 2731.63Smrg echo 'creating runtime link editor directory cache.' 2741.88Sthorpej ldconfig 2751.63Smrgfi 2761.83Sdrochner 2771.83Sdrochner# load kernel modules specified in /etc/lkm.conf 2781.89Scjsif checkyesno lkm && [ -f /etc/rc.lkm ]; then 2791.83Sdrochner lkmstage=AFTERMOUNT 2801.83Sdrochner . /etc/rc.lkm 2811.1Scgdfi 2821.1Scgd 2831.89Scjsecho -n 'checking quotas:'; quotacheck -a; echo ' done.' 2841.47Sderaadtquotaon -a 2851.1Scgd 2861.1Scgd# build ps databases 2871.2Scgdecho 'building databases...' 2881.11Scgdkvm_mkdb /netbsd 2891.1Scgddev_mkdb 2901.1Scgd 2911.1Scgdchmod 666 /dev/tty[pqrs]* 2921.1Scgd 2931.1Scgd# check the password temp/lock file 2941.1Scgdif [ -f /etc/ptmp ] 2951.1Scgdthen 2961.1Scgd logger -s -p auth.err \ 2971.1Scgd 'password file may be incorrect -- /etc/ptmp exists' 2981.1Scgdfi 2991.1Scgd 3001.85Sperryvirecovery=`echo /var/tmp/vi.recover/recover.*` 3011.32Smycroftif [ "$virecovery" != "/var/tmp/vi.recover/recover.*" ]; then 3021.32Smycroft echo preserving editor files 3031.32Smycroft for i in $virecovery; do 3041.32Smycroft sendmail -t < $i 3051.32Smycroft done 3061.32Smycroftfi 3071.1Scgd 3081.1Scgdecho clearing /tmp 3091.1Scgd 3101.65Smikel# Prune quickly with one rm, then use find to clean up /tmp/[lq]* (this 3111.65Smikel# is not needed with mfs /tmp, but doesn't hurt anything). 3121.1Scgd(cd /tmp && rm -rf [a-km-pr-zA-Z]* && 3131.46Sderaadt find . ! -name . ! -name lost+found ! -name quota.user \ 3141.46Sderaadt ! -name quota.group -exec rm -rf -- {} \; -type d -prune) 3151.1Scgd 3161.74Sperry# Update kernel info in /etc/motd 3171.74Sperry# Must be done *before* interactive logins are possible to prevent 3181.74Sperry# possible race conditions. 3191.89Scjsif checkyesno update_motd; then 3201.74Sperry echo 'updating motd.' 3211.74Sperry if [ ! -f /etc/motd ]; then 3221.74Sperry install -c -o root -g wheel -m 664 /dev/null /etc/motd 3231.74Sperry fi 3241.74Sperry T=/tmp/_motd 3251.74Sperry rm -f $T 3261.74Sperry sysctl -n kern.version | sed 1q > $T 3271.74Sperry echo "" >> $T 3281.74Sperry sed '1,/^$/d' < /etc/motd >> $T 3291.74Sperry cmp -s $T /etc/motd || cp $T /etc/motd 3301.74Sperry rm -f $T 3311.74Sperryfi 3321.74Sperry 3331.34Scgdif [ -f /var/account/acct ]; then 3341.34Scgd echo 'turning on accounting'; accton /var/account/acct 3351.34Scgdfi 3361.1Scgd 3371.1Scgdecho -n standard daemons: 3381.89Scjsif checkyesno update; then 3391.70Smycroft echo -n ' update'; update $update_flags 3401.70Smycroftfi 3411.31Sjtcecho -n ' cron'; cron 3421.1Scgdecho '.' 3431.1Scgd 3441.63Smrg# now start all the other daemons 3451.1Scgdecho -n starting network daemons: 3461.1Scgd 3471.89Scjsif checkyesno gated && checkyesno routed; then 3481.89Scjs echo 3491.89Scjs logger -s "WARNING: gated and routed both requested to be run: " \ 3501.89Scjs "running only gated." 3511.89Scjs routed=NO 3521.89Scjsfi 3531.89Scjs 3541.89Scjsif checkyesno gated; then 3551.89Scjs if [ -r /etc/gated.conf ]; then 3561.89Scjs echo -n ' gated'; gated $gated_flags 3571.89Scjs else 3581.89Scjs logger -s "WARNING: no /etc/gated.conf; gated not started." 3591.67Smycroft fi 3601.89Scjsfi 3611.89Scjs 3621.89Scjsif checkyesno routed; then 3631.48Smycroft echo -n ' routed'; routed $routed_flags 3641.1Scgdfi 3651.1Scgd 3661.89Scjsif checkyesno mrouted; then 3671.55Sthorpej echo -n ' mrouted'; mrouted $mrouted_flags 3681.55Sthorpejfi 3691.55Sthorpej 3701.89Scjsif checkyesno timed; then 3711.67Smycroft echo -n ' timed'; timed $timed_flags 3721.63Smrgfi 3731.63Smrg 3741.89Scjsif checkyesno xntpd; then 3751.67Smycroft echo -n ' xntpd'; xntpd $xntpd_flags 3761.61Smrgfi 3771.61Smrg 3781.89Scjsif checkyesno dhcpd; then 3791.89Scjs if [ -r /etc/dhcpd.conf ]; then 3801.89Scjs echo -n ' dhcpd'; dhcpd $dhcpd_flags 3811.89Scjs else 3821.89Scjs echo 3831.89Scjs logger -s "WARNING: /etc/dhcpd.conf not readable; " \ 3841.89Scjs "dhcpd not started." 3851.67Smycroft fi 3861.29Smycroftfi 3871.29Smycroft 3881.89Scjsif checkyesno rwhod; then 3891.48Smycroft echo -n ' rwhod'; rwhod 3901.1Scgdfi 3911.1Scgd 3921.89Scjsif checkyesno lpd; then 3931.89Scjs echo -n ' lpd'; lpd $lpd_flags 3941.60Stlsfi 3951.60Stls 3961.63Smrg# We call sendmail with a full path so that SIGHUP works. 3971.89Scjsif checkyesno sendmail; then 3981.89Scjs if [ -r /etc/sendmail.cf ]; then 3991.89Scjs echo -n ' sendmail'; /usr/sbin/sendmail $sendmail_flags 4001.89Scjs else 4011.89Scjs echo 4021.89Scjs logger -s "WARNING: /etc/sendmail.cf not readable; " \ 4031.89Scjs "sendmail not started." 4041.67Smycroft fi 4051.60Stlsfi 4061.60Stls 4071.89Scjsif checkyesno rarpd; then 4081.89Scjs if [ -r /etc/ethers ]; then 4091.89Scjs echo -n ' rarpd'; rarpd $rarpd_flags 4101.89Scjs else 4111.89Scjs echo 4121.89Scjs logger -s "WARNING: /etc/ethers not readable; " \ 4131.89Scjs "rarpd not started." 4141.67Smycroft fi 4151.60Stlsfi 4161.60Stls 4171.89Scjsif checkyesno rbootd; then 4181.89Scjs if [ -r /etc/rbootd.conf ]; then 4191.89Scjs echo -n ' rbootd'; rbootd $rbootd_flags 4201.89Scjs else 4211.89Scjs echo 4221.89Scjs logger -s "WARNING: /etc/rbootd.conf not readable; " \ 4231.89Scjs "rarpd not started." 4241.67Smycroft fi 4251.72Scjsfi 4261.72Scjs 4271.89Scjsif checkyesno mopd; then 4281.72Scjs echo -n ' mopd'; mopd $mopd_flags 4291.86Sperryfi 4301.86Sperry 4311.89Scjsif checkyesno apmd; then 4321.86Sperry echo -n ' apmd'; apmd $apmd_flags 4331.52Sthorpejfi 4341.52Sthorpej 4351.89Scjsif checkyesno inetd; then 4361.89Scjs if [ -r /etc/inetd.conf ]; then 4371.89Scjs echo -n ' inetd'; inetd $inetd_flags 4381.89Scjs else 4391.89Scjs echo 4401.89Scjs logger -s "WARNING: /etc/inetd.conf not readable; " \ 4411.89Scjs "inetd not started." 4421.67Smycroft fi 4431.30Smycroftfi 4441.30Smycroft 4451.1Scgdecho '.' 4461.73Sperry 4471.73Sperry# Kerberos runs ONLY on the Kerberos server machine 4481.89Scjsif checkyesno kerberos; then 4491.73Sperry echo -n 'starting kerberos daemons:' 4501.73Sperry echo -n ' kerberos'; kerberos >> /var/log/kerberos.log & 4511.73Sperry echo -n ' kadmind'; kadmind -n >> /var/log/kadmind.log & 4521.73Sperry echo '.' 4531.73Sperryfi 4541.1Scgd 4551.25Smycroft. /etc/rc.local 4561.1Scgd 4571.1Scgddate 4581.1Scgdexit 0 459