Home | History | Annotate | Line # | Download | only in etc
rc revision 1.85
      1  1.85     perry #	$NetBSD: rc,v 1.85 1997/07/31 03:35:39 perry Exp $
      2  1.73     perry #	originally from: @(#)rc	8.2 (Berkeley) 3/17/94
      3   1.1       cgd 
      4   1.1       cgd # System startup script run by init on autoboot
      5   1.1       cgd # or after single-user.
      6   1.1       cgd # Output and error are redirected to console by init,
      7   1.1       cgd # and the console is the controlling terminal.
      8   1.1       cgd 
      9   1.1       cgd stty status '^T'
     10   1.1       cgd 
     11   1.1       cgd # Set shell to ignore SIGINT (2), but not children;
     12   1.1       cgd # shell catches SIGQUIT (3) and returns to single user after fsck.
     13   1.1       cgd trap : 2
     14   1.1       cgd trap : 3	# shouldn't be needed
     15   1.1       cgd 
     16  1.68   mycroft export HOME=/
     17  1.68   mycroft export PATH=/sbin:/bin:/usr/sbin:/usr/bin
     18  1.50   thorpej 
     19  1.50   thorpej # Configure ccd devices.
     20  1.63       mrg if [ -f /etc/ccd.conf ]; then
     21  1.50   thorpej 	ccdconfig -C
     22  1.50   thorpej fi
     23   1.1       cgd 
     24  1.79   thorpej # Add all block-type swap devices; these might be necessary
     25  1.79   thorpej # during disk checks.
     26  1.79   thorpej swapctl -A -t blk
     27  1.79   thorpej 
     28  1.63       mrg if [ -e /fastboot ]; then
     29  1.38       cgd 	echo "Fast boot: skipping disk checks."
     30  1.68   mycroft elif [ "$1" = autoboot ]; then
     31  1.38       cgd 	echo "Automatic boot in progress: starting file system checks."
     32   1.1       cgd 	fsck -p
     33   1.1       cgd 	case $? in
     34   1.1       cgd 	0)
     35   1.1       cgd 		;;
     36   1.1       cgd 	2)
     37   1.1       cgd 		exit 1
     38   1.1       cgd 		;;
     39   1.1       cgd 	4)
     40  1.35       cgd 		echo "Rebooting..."
     41   1.1       cgd 		reboot
     42  1.38       cgd 		echo "Reboot failed; help!"
     43   1.1       cgd 		exit 1
     44   1.1       cgd 		;;
     45   1.1       cgd 	8)
     46  1.38       cgd 		echo "Automatic file system check failed; help!"
     47   1.1       cgd 		exit 1
     48   1.1       cgd 		;;
     49   1.1       cgd 	12)
     50  1.38       cgd 		echo "Boot interrupted."
     51   1.1       cgd 		exit 1
     52   1.1       cgd 		;;
     53   1.1       cgd 	130)
     54   1.1       cgd 		# interrupt before catcher installed
     55   1.1       cgd 		exit 1
     56   1.1       cgd 		;;
     57   1.1       cgd 	*)
     58  1.38       cgd 		echo "Unknown error; help!"
     59   1.1       cgd 		exit 1
     60   1.1       cgd 		;;
     61   1.1       cgd 	esac
     62   1.1       cgd fi
     63   1.1       cgd 
     64  1.38       cgd trap "echo 'Boot interrupted.'; exit 1" 3
     65   1.1       cgd 
     66   1.1       cgd umount -a >/dev/null 2>&1
     67  1.83  drochner mount /
     68   1.1       cgd rm -f /fastboot		# XXX (root now writeable)
     69  1.40       cgd 
     70  1.71   mycroft if [ -f /etc/rc.conf ]; then
     71  1.63       mrg 	. /etc/rc.conf
     72  1.63       mrg fi
     73  1.63       mrg 
     74  1.40       cgd # set flags on ttys.  (do early, in case they use tty for SLIP in netstart)
     75  1.40       cgd echo 'setting tty flags'
     76  1.40       cgd ttyflags -a
     77   1.1       cgd 
     78  1.83  drochner # load kernel modules specified in /etc/lkm.conf if the /usr filesystem
     79  1.83  drochner # is already present with "/" or can be mounted now
     80  1.67   mycroft if [ "$lkm_init" != NO ] && [ -f /etc/rc.lkm ]; then
     81  1.83  drochner 	mount /usr >/dev/null 2>&1
     82  1.83  drochner 	if [ -x /usr/bin/ld ]; then
     83  1.83  drochner 		lkmstage=BEFORENET
     84  1.83  drochner 		. /etc/rc.lkm
     85  1.83  drochner 	fi
     86  1.63       mrg fi
     87  1.63       mrg 
     88   1.1       cgd # set hostname, turn on network
     89   1.1       cgd echo 'starting network'
     90  1.76    scottr sh /etc/netstart
     91  1.76    scottr if [ $? -ne 0 ]; then
     92  1.76    scottr 	exit 1
     93  1.76    scottr fi
     94   1.1       cgd 
     95  1.82     veego mount /usr >/dev/null 2>&1
     96  1.42   mycroft mount /var >/dev/null 2>&1
     97  1.79   thorpej 
     98  1.79   thorpej # "Critical" file systems are now mounted.  Go ahead and swap
     99  1.79   thorpej # to files now, since they will be residing in the critical file
    100  1.79   thorpej # systems (or, at least, better).
    101  1.79   thorpej swapctl -A -t noblk
    102  1.26   deraadt 
    103  1.41       jtc # clean up left-over files
    104  1.41       jtc rm -f /etc/nologin
    105  1.41       jtc rm -f /var/spool/lock/LCK.*
    106  1.41       jtc rm -f /var/spool/uucp/STST/*
    107  1.45       cgd (cd /var/run && { rm -rf -- *; install -c -m 664 -g utmp /dev/null utmp; })
    108  1.41       jtc 
    109  1.84     veego # start the system logger first, so that all messages from daemons
    110  1.84     veego # are logged, then start savecore to get a dump on low memory systems
    111  1.84     veego # and then start the name server.
    112  1.63       mrg 
    113  1.67   mycroft if [ "$syslogd_flags" != NO ]; then
    114  1.67   mycroft 	if [ "$syslogd_flags" = DEFAULT ]; then
    115  1.67   mycroft 		syslogd_flags=""
    116  1.67   mycroft 	fi
    117  1.63       mrg 	echo 'starting system logger'
    118  1.63       mrg 	rm -f /dev/log
    119  1.63       mrg 	syslogd $syslogd_flags
    120  1.63       mrg fi
    121  1.63       mrg 
    122  1.84     veego # /var/crash should be a directory or a symbolic link
    123  1.84     veego # to the crash directory if core dumps are to be saved.
    124  1.84     veego if [ "$savecore_flags" != NO ] && [ -d /var/crash ]; then
    125  1.84     veego 	if [ "$savecore_flags" = DEFAULT ]; then
    126  1.84     veego 		savecore_flags=""
    127  1.84     veego 	fi
    128  1.84     veego 	echo checking for core dump...
    129  1.84     veego 	savecore $savecore_flags /var/crash
    130  1.84     veego fi
    131  1.84     veego 
    132  1.67   mycroft if [ "$named_flags" != NO ]; then
    133  1.67   mycroft 	if [ "$named_flags" = DEFAULT ]; then
    134  1.67   mycroft 		named_flags=""
    135  1.67   mycroft 	fi
    136  1.63       mrg 	echo 'starting name server';	named $named_flags
    137  1.63       mrg fi
    138  1.63       mrg 
    139  1.84     veego # now start the rpc servers, for YP server/client.
    140  1.63       mrg echo -n 'starting rpc daemons:'
    141  1.63       mrg 
    142  1.63       mrg # note that portmap is generally required for all other rpc services.
    143  1.67   mycroft if [ "$portmap" != NO ]; then
    144  1.63       mrg 	echo -n ' portmap';             portmap
    145  1.63       mrg fi
    146  1.63       mrg 
    147  1.67   mycroft if [ "$ypserv_flags" != NO ]; then
    148  1.67   mycroft 	if [ "$ypserv_flags" = DEFAULT ]; then
    149  1.67   mycroft 		ypserv_flags="-d"
    150  1.67   mycroft 	fi
    151  1.63       mrg         echo -n ' ypserv';              ypserv $ypserv_flags
    152  1.63       mrg fi
    153  1.63       mrg 
    154  1.67   mycroft if [ "$ypbind_flags" != NO ]; then
    155  1.67   mycroft 	if [ "$ypbind_flags" = DEFAULT ]; then
    156  1.67   mycroft 		ypbind_flags=""
    157  1.67   mycroft 	fi
    158  1.63       mrg         echo -n ' ypbind';              ypbind $ypbind_flags
    159  1.63       mrg fi
    160  1.63       mrg 
    161  1.67   mycroft if [ "$yppasswdd_flags" != NO ]; then
    162  1.67   mycroft 	if [ "$yppasswdd_flags" = DEFAULT ]; then
    163  1.67   mycroft 		yppasswdd_flags=""
    164  1.67   mycroft 	fi
    165  1.63       mrg         echo -n ' rpc.yppasswdd';       rpc.yppasswdd $yppasswdd_flags
    166  1.63       mrg fi
    167  1.63       mrg 
    168  1.67   mycroft if [ "$bootparamd_flags" != NO ] && [ -r /etc/bootparams ]; then
    169  1.67   mycroft 	if [ "$bootparamd_flags" = DEFAULT ]; then
    170  1.67   mycroft 		bootparamd_flags=""
    171  1.67   mycroft 	fi
    172  1.63       mrg         echo -n ' rpc.bootparamd';      rpc.bootparamd $bootparamd_flags
    173  1.63       mrg fi
    174  1.63       mrg 
    175  1.84     veego echo '.'
    176  1.84     veego 
    177  1.84     veego # load kernel modules specified in /etc/lkm.conf
    178  1.84     veego if [ "$lkm_init" != NO ] && [ -f /etc/rc.lkm ]; then
    179  1.84     veego 	lkmstage=BEFOREMOUNT
    180  1.84     veego 	. /etc/rc.lkm
    181  1.84     veego fi
    182  1.84     veego 
    183  1.84     veego mount -a
    184  1.84     veego 
    185  1.84     veego # now start the rpc servers, for NFS server/client.
    186  1.84     veego echo -n 'starting nfs-rpc daemons:'
    187  1.84     veego 
    188  1.67   mycroft nfs_locking=NO
    189  1.67   mycroft 
    190  1.67   mycroft if [ "$nfs_server" = YES ] && [ -r /etc/exports ]; then
    191  1.69   mycroft 	if [ "$mountd_flags" = DEFAULT ]; then
    192  1.69   mycroft 		mountd_flags=""
    193  1.63       mrg 	fi
    194  1.63       mrg         rm -f /var/db/mountdtab
    195  1.63       mrg         echo -n > /var/db/mountdtab
    196  1.63       mrg         echo -n ' mountd';              mountd $mountd_flags
    197  1.69   mycroft 	if [ "$nfsd_flags" = DEFAULT ]; then
    198  1.69   mycroft 		nfsd_flags="-tun 4"
    199  1.69   mycroft 	fi
    200  1.63       mrg         echo -n ' nfsd';                nfsd $nfsd_flags
    201  1.67   mycroft 	nfs_locking=MAYBE
    202   1.1       cgd fi
    203  1.63       mrg 
    204  1.67   mycroft if [ "$nfs_client" = YES ]; then
    205  1.67   mycroft 	if [ "$nfsiod_flags" = DEFAULT ]; then
    206  1.63       mrg 		nfsiod_flags="-n 4"
    207  1.63       mrg 	fi
    208  1.63       mrg         echo -n ' nfsiod';              nfsiod $nfsiod_flags
    209  1.67   mycroft 	nfs_locking=MAYBE
    210  1.66    scottr fi
    211  1.66    scottr 
    212  1.67   mycroft if [ "$nfs_locking" != NO ]; then
    213  1.67   mycroft 	if [ "$statd_flags" != NO ]; then
    214  1.67   mycroft 		if [ "$statd_flags" = DEFAULT ]; then
    215  1.67   mycroft 			statd_flags=""
    216  1.67   mycroft 		fi
    217  1.71   mycroft 		echo -n ' rpc.statd';		rpc.statd $statd_flags
    218  1.66    scottr 	fi
    219  1.66    scottr 
    220  1.67   mycroft 	if [ "$lockd_flags" != NO ]; then
    221  1.67   mycroft 		if [ "$lockd_flags" = DEFAULT ]; then
    222  1.67   mycroft 			lockd_flags=""
    223  1.67   mycroft 		fi
    224  1.71   mycroft 		echo -n ' rpc.lockd';		rpc.lockd $lockd_flags
    225  1.66    scottr 	fi
    226  1.63       mrg fi
    227  1.63       mrg 
    228  1.67   mycroft if [ "$amd_flags" != NO ] && [ -d "$amd_dir" -a -r "$amd_master" ]; then
    229  1.67   mycroft 	if [ "$amd_flags" = DEFAULT ]; then
    230  1.67   mycroft 		amd_flags="-l syslog -x error,noinfo,nostats"
    231  1.67   mycroft 	fi
    232  1.63       mrg         echo -n ' amd'
    233  1.63       mrg         amd $amd_flags -p -a $amd_dir `cat $amd_master` > /var/run/amd.pid
    234  1.63       mrg fi
    235  1.63       mrg 
    236   1.1       cgd echo '.'
    237  1.83  drochner 
    238  1.63       mrg if [ -f /sbin/ldconfig ]; then
    239  1.63       mrg 	echo 'creating runtime link editor directory cache.'
    240  1.71   mycroft 	if [ -f /etc/ld.so.conf ]; then
    241  1.63       mrg 		ldconfig `cat /etc/ld.so.conf`
    242  1.63       mrg 	else
    243  1.63       mrg 		ldconfig
    244  1.63       mrg 	fi
    245  1.63       mrg fi 
    246  1.83  drochner 
    247  1.83  drochner # load kernel modules specified in /etc/lkm.conf
    248  1.83  drochner if [ "$lkm_init" != NO ] && [ -f /etc/rc.lkm ]; then
    249  1.83  drochner 	lkmstage=AFTERMOUNT
    250  1.83  drochner 	. /etc/rc.lkm
    251   1.1       cgd fi
    252   1.1       cgd 
    253  1.47   deraadt 				echo -n 'checking quotas:'
    254  1.47   deraadt quotacheck -a
    255  1.47   deraadt 				echo ' done.'
    256  1.47   deraadt quotaon -a
    257   1.1       cgd 
    258   1.1       cgd # build ps databases
    259   1.2       cgd echo 'building databases...'
    260  1.11       cgd kvm_mkdb /netbsd
    261   1.1       cgd dev_mkdb
    262   1.1       cgd 
    263   1.1       cgd chmod 666 /dev/tty[pqrs]*
    264   1.1       cgd 
    265   1.1       cgd # check the password temp/lock file
    266   1.1       cgd if [ -f /etc/ptmp ]
    267   1.1       cgd then
    268   1.1       cgd 	logger -s -p auth.err \
    269   1.1       cgd 	'password file may be incorrect -- /etc/ptmp exists'
    270   1.1       cgd fi
    271   1.1       cgd 
    272  1.85     perry virecovery=`echo /var/tmp/vi.recover/recover.*`
    273  1.32   mycroft if [ "$virecovery" != "/var/tmp/vi.recover/recover.*" ]; then
    274  1.32   mycroft 	echo preserving editor files
    275  1.32   mycroft 	for i in $virecovery; do
    276  1.32   mycroft 		sendmail -t < $i
    277  1.32   mycroft 	done
    278  1.32   mycroft fi
    279   1.1       cgd 
    280   1.1       cgd echo clearing /tmp
    281   1.1       cgd 
    282  1.65     mikel # Prune quickly with one rm, then use find to clean up /tmp/[lq]* (this
    283  1.65     mikel # is not needed with mfs /tmp, but doesn't hurt anything).
    284   1.1       cgd (cd /tmp && rm -rf [a-km-pr-zA-Z]* &&
    285  1.46   deraadt     find . ! -name . ! -name lost+found ! -name quota.user \
    286  1.46   deraadt 	! -name quota.group -exec rm -rf -- {} \; -type d -prune)
    287   1.1       cgd 
    288  1.74     perry # Update kernel info in /etc/motd
    289  1.74     perry # Must be done *before* interactive logins are possible to prevent
    290  1.74     perry # possible race conditions.
    291  1.74     perry if [ "$update_motd" != NO ]; then
    292  1.74     perry 	echo 'updating motd.'
    293  1.74     perry 	if [ ! -f /etc/motd ]; then
    294  1.74     perry 		install -c -o root -g wheel -m 664 /dev/null /etc/motd
    295  1.74     perry 	fi
    296  1.74     perry 	T=/tmp/_motd
    297  1.74     perry 	rm -f $T
    298  1.74     perry 	sysctl -n kern.version | sed 1q > $T
    299  1.74     perry 	echo "" >> $T
    300  1.74     perry 	sed '1,/^$/d' < /etc/motd >> $T
    301  1.74     perry 	cmp -s $T /etc/motd || cp $T /etc/motd
    302  1.74     perry 	rm -f $T
    303  1.74     perry fi
    304  1.74     perry 
    305  1.34       cgd if [ -f /var/account/acct ]; then
    306  1.34       cgd 	echo 'turning on accounting';	accton /var/account/acct
    307  1.34       cgd fi
    308   1.1       cgd 
    309   1.1       cgd echo -n standard daemons:
    310  1.70   mycroft if [ "$update_flags" != NO ]; then
    311  1.70   mycroft 	if [ "$update_flags" = DEFAULT ]; then
    312  1.70   mycroft 		update_flags="30"
    313  1.70   mycroft 	fi
    314  1.70   mycroft 	echo -n ' update';		update $update_flags
    315  1.70   mycroft fi
    316  1.31       jtc echo -n ' cron';		cron
    317   1.1       cgd echo '.'
    318   1.1       cgd 
    319  1.63       mrg # now start all the other daemons
    320   1.1       cgd echo -n starting network daemons:
    321   1.1       cgd 
    322  1.67   mycroft if [ "$gated_flags" != NO ] && [ -r /etc/gated.conf ]; then
    323  1.67   mycroft 	if [ "$gated_flags" = DEFAULT ]; then
    324  1.67   mycroft 		gated_flags=""
    325  1.67   mycroft 	fi
    326  1.48   mycroft 	echo -n ' gated';		gated $gated_flags
    327  1.67   mycroft elif [ "$routed_flags" != NO ]; then
    328  1.67   mycroft 	if [ "$routed_flags" = DEFAULT ]; then
    329  1.67   mycroft 		routed_flags="-q"
    330  1.67   mycroft 	fi
    331  1.48   mycroft 	echo -n ' routed';		routed $routed_flags
    332   1.1       cgd fi
    333   1.1       cgd 
    334  1.67   mycroft if [ "$mrouted_flags" != NO ]; then
    335  1.67   mycroft 	if [ "$mrouted_flags" = DEFAULT ]; then
    336  1.67   mycroft 		mrouted_flags=""
    337  1.67   mycroft 	fi
    338  1.55   thorpej 	echo -n ' mrouted';		mrouted $mrouted_flags
    339  1.55   thorpej fi
    340  1.55   thorpej 
    341  1.67   mycroft if [ "$timed_flags" != NO ]; then
    342  1.67   mycroft 	if [ "$timed_flags" = DEFAULT ]; then
    343  1.67   mycroft 		timed_flags=""
    344  1.67   mycroft 	fi
    345  1.67   mycroft 	echo -n ' timed'; 		timed $timed_flags
    346  1.75     perry fi
    347  1.75     perry 
    348  1.75     perry if [ "$ntpdate_hosts" != NO ]; then
    349  1.75     perry 	if [ "$ntpdate_hosts" = DEFAULT ]; then
    350  1.75     perry 		ntpdate_hosts=`awk '/^server/ {print $2}' </etc/ntp.conf`
    351  1.75     perry 	fi
    352  1.75     perry 
    353  1.75     perry 	if [ -n "$ntpdate_hosts"  ]; then
    354  1.75     perry 		echo -n 'ntpdate:'
    355  1.75     perry 		ntpdate -b $ntpdate_hosts
    356  1.75     perry 	fi
    357  1.63       mrg fi
    358  1.63       mrg 
    359  1.67   mycroft if [ "$xntpd_flags" != NO ]; then
    360  1.67   mycroft 	if [ "$xntpd_flags" = DEFAULT ]; then
    361  1.77       cjs 		xntpd_flags="-p /var/run/xntpd.pid"
    362  1.67   mycroft 	fi
    363  1.67   mycroft 	echo -n ' xntpd';		xntpd $xntpd_flags
    364  1.61       mrg fi
    365  1.61       mrg 
    366  1.67   mycroft if [ "$dhcpd_flags" != NO ] && [ -r /etc/dhcpd.conf ]; then
    367  1.67   mycroft 	if [ "$dhcpd_flags" = DEFAULT ]; then
    368  1.67   mycroft 		dhcpd_flags=""
    369  1.67   mycroft 	fi
    370  1.61       mrg 	echo -n ' dhcpd';		dhcpd $dhcpd_flags
    371  1.29   mycroft fi
    372  1.29   mycroft 
    373  1.67   mycroft if [ "$rwhod" = YES ]; then
    374  1.48   mycroft 	echo -n ' rwhod';		rwhod
    375   1.1       cgd fi
    376   1.1       cgd 
    377  1.67   mycroft if [ "$lpd_flags" != NO ]; then
    378  1.67   mycroft 	if [ "$lpd_flags" = DEFAULT ]; then
    379  1.67   mycroft 		lpd_flags=""
    380  1.67   mycroft 	fi
    381  1.63       mrg 	echo -n ' printer';		lpd $lpd_flags
    382  1.60       tls fi
    383  1.60       tls 
    384  1.63       mrg # We call sendmail with a full path so that SIGHUP works.
    385  1.67   mycroft if [ "$sendmail_flags" != NO ] && [ -r /etc/sendmail.cf ]; then
    386  1.67   mycroft 	if [ "$sendmail_flags" = DEFAULT ]; then
    387  1.67   mycroft 		sendmail_flags="-bd -q30m"
    388  1.67   mycroft 	fi
    389  1.63       mrg 	echo -n ' sendmail';		/usr/sbin/sendmail $sendmail_flags
    390  1.60       tls fi
    391  1.60       tls 
    392  1.67   mycroft if [ "$rarpd_flags" != NO ] && [ -r /etc/ethers ]; then
    393  1.67   mycroft 	if [ "$rarpd_flags" = DEFAULT ]; then
    394  1.67   mycroft 		rarpd_flags="-a"
    395  1.67   mycroft 	fi
    396  1.63       mrg 	echo -n ' rarpd';		rarpd $rarpd_flags
    397  1.60       tls fi
    398  1.60       tls 
    399  1.67   mycroft if [ "$rbootd_flags" != NO ] && [ -r /etc/rbootd.conf ]; then
    400  1.67   mycroft 	if [ "$rbootd_flags" = DEFAULT ]; then
    401  1.67   mycroft 		rbootd_flags=""
    402  1.67   mycroft 	fi
    403  1.63       mrg 	echo -n ' rbootd';		rbootd $rbootd_flags
    404  1.72       cjs fi
    405  1.72       cjs 
    406  1.72       cjs if [ "$mopd_flags" != NO ]; then
    407  1.72       cjs 	if [ "$mopd_flags" = DEFAULT ]; then
    408  1.72       cjs 		mopd_flags="-a"
    409  1.72       cjs 	fi
    410  1.72       cjs 	echo -n ' mopd';		mopd $mopd_flags
    411  1.52   thorpej fi
    412  1.52   thorpej 
    413  1.67   mycroft if [ "$inetd_flags" != NO ] && [ -r /etc/inetd.conf ]; then
    414  1.67   mycroft 	if [ "$inetd_flags" = DEFAULT ]; then
    415  1.67   mycroft 		inetd_flags=""
    416  1.67   mycroft 	fi
    417  1.63       mrg 	echo -n ' inetd';		inetd $inetd_flags
    418  1.30   mycroft fi
    419  1.30   mycroft 
    420   1.1       cgd echo '.'
    421  1.73     perry 
    422  1.73     perry # Kerberos runs ONLY on the Kerberos server machine
    423  1.73     perry if [ "$kerberos_server" = YES ]; then
    424  1.73     perry 	echo -n 'starting kerberos daemons:'
    425  1.73     perry 	echo -n ' kerberos';	kerberos >> /var/log/kerberos.log &
    426  1.73     perry 	echo -n ' kadmind';	kadmind -n >> /var/log/kadmind.log &
    427  1.73     perry 	echo '.'
    428  1.73     perry fi
    429   1.1       cgd 
    430  1.25   mycroft . /etc/rc.local
    431   1.1       cgd 
    432   1.1       cgd date
    433   1.1       cgd exit 0
    434