Home | History | Annotate | Line # | Download | only in etc
rc revision 1.92
      1  1.92  drochner #	$NetBSD: rc,v 1.92 1997/09/12 09:53:08 drochner 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.90     veego if [ -f /etc/rc.subr ]; then
     71  1.90     veego 	. /etc/rc.subr
     72  1.89       cjs else
     73  1.90     veego 	echo "Can't read /etc/rc.subr; aborting."
     74  1.89       cjs 	exit 1;
     75  1.89       cjs fi
     76  1.89       cjs 
     77  1.71   mycroft if [ -f /etc/rc.conf ]; then
     78  1.63       mrg 	. /etc/rc.conf
     79  1.63       mrg fi
     80  1.63       mrg 
     81  1.89       cjs if [ "$rc_configured" != YES ]; then
     82  1.89       cjs 	echo "/etc/rc.conf is not configured. Multiuser boot aborted."
     83  1.89       cjs 	exit 1
     84  1.89       cjs fi
     85  1.89       cjs 
     86  1.40       cgd # set flags on ttys.  (do early, in case they use tty for SLIP in netstart)
     87  1.40       cgd echo 'setting tty flags'
     88  1.40       cgd ttyflags -a
     89   1.1       cgd 
     90  1.83  drochner # load kernel modules specified in /etc/lkm.conf if the /usr filesystem
     91  1.83  drochner # is already present with "/" or can be mounted now
     92  1.67   mycroft if [ "$lkm_init" != NO ] && [ -f /etc/rc.lkm ]; then
     93  1.83  drochner 	mount /usr >/dev/null 2>&1
     94  1.83  drochner 	if [ -x /usr/bin/ld ]; then
     95  1.83  drochner 		lkmstage=BEFORENET
     96  1.83  drochner 		. /etc/rc.lkm
     97  1.83  drochner 	fi
     98  1.63       mrg fi
     99  1.63       mrg 
    100   1.1       cgd # set hostname, turn on network
    101   1.1       cgd echo 'starting network'
    102  1.76    scottr sh /etc/netstart
    103  1.76    scottr if [ $? -ne 0 ]; then
    104  1.76    scottr 	exit 1
    105  1.76    scottr fi
    106   1.1       cgd 
    107  1.92  drochner if [ ! -d /usr/bin ]; then
    108  1.92  drochner 	mount /usr >/dev/null 2>&1
    109  1.92  drochner fi
    110  1.42   mycroft mount /var >/dev/null 2>&1
    111  1.79   thorpej 
    112  1.79   thorpej # "Critical" file systems are now mounted.  Go ahead and swap
    113  1.79   thorpej # to files now, since they will be residing in the critical file
    114  1.79   thorpej # systems (or, at least, better).
    115  1.79   thorpej swapctl -A -t noblk
    116  1.26   deraadt 
    117  1.41       jtc # clean up left-over files
    118  1.41       jtc rm -f /etc/nologin
    119  1.41       jtc rm -f /var/spool/lock/LCK.*
    120  1.41       jtc rm -f /var/spool/uucp/STST/*
    121  1.45       cgd (cd /var/run && { rm -rf -- *; install -c -m 664 -g utmp /dev/null utmp; })
    122  1.41       jtc 
    123  1.84     veego # start the system logger first, so that all messages from daemons
    124  1.84     veego # are logged, then start savecore to get a dump on low memory systems
    125  1.84     veego # and then start the name server.
    126  1.63       mrg 
    127  1.89       cjs if checkyesno syslogd; then
    128  1.63       mrg 	echo 'starting system logger'
    129  1.63       mrg 	rm -f /dev/log
    130  1.63       mrg 	syslogd $syslogd_flags
    131  1.63       mrg fi
    132  1.63       mrg 
    133  1.84     veego # /var/crash should be a directory or a symbolic link
    134  1.84     veego # to the crash directory if core dumps are to be saved.
    135  1.89       cjs if checkyesno savecore; then
    136  1.89       cjs 	if [ -d /var/crash ]; then
    137  1.89       cjs 		echo checking for core dump...
    138  1.89       cjs 		savecore $savecore_flags /var/crash
    139  1.89       cjs 	else
    140  1.89       cjs 		logger -s "WARNING: no /var/crash directory; savecore not run."
    141  1.84     veego 	fi
    142  1.84     veego fi
    143  1.84     veego 
    144  1.89       cjs if checkyesno named; then
    145  1.89       cjs 	echo 'starting name server';	named $named_flags
    146  1.89       cjs fi
    147  1.89       cjs 
    148  1.89       cjs # set time, if requested
    149  1.89       cjs if checkyesno ntpdate; then
    150  1.91     mikel 	if [ -z "$ntpdate_hosts" ]; then
    151  1.89       cjs 		ntpdate_hosts=`awk '/^server/ {print $2}' </etc/ntp.conf`
    152  1.89       cjs 	fi
    153  1.89       cjs 	if [ -n "$ntpdate_hosts"  ]; then
    154  1.89       cjs 		echo 'Setting date via ntp.'
    155  1.89       cjs 		ntpdate -b $ntpdate_hosts
    156  1.67   mycroft 	fi
    157  1.63       mrg fi
    158  1.63       mrg 
    159  1.84     veego # now start the rpc servers, for YP server/client.
    160  1.63       mrg echo -n 'starting rpc daemons:'
    161  1.63       mrg 
    162  1.63       mrg # note that portmap is generally required for all other rpc services.
    163  1.89       cjs if checkyesno portmap; then
    164  1.63       mrg 	echo -n ' portmap';             portmap
    165  1.63       mrg fi
    166  1.63       mrg 
    167  1.89       cjs if checkyesno ypserv; then
    168  1.63       mrg         echo -n ' ypserv';              ypserv $ypserv_flags
    169  1.63       mrg fi
    170  1.63       mrg 
    171  1.89       cjs if checkyesno ypbind; then
    172  1.63       mrg         echo -n ' ypbind';              ypbind $ypbind_flags
    173  1.63       mrg fi
    174  1.63       mrg 
    175  1.89       cjs if checkyesno yppasswdd; then
    176  1.63       mrg         echo -n ' rpc.yppasswdd';       rpc.yppasswdd $yppasswdd_flags
    177  1.63       mrg fi
    178  1.63       mrg 
    179  1.89       cjs if checkyesno bootparamd; then
    180  1.89       cjs 	if [ -r /etc/bootparams ]; then
    181  1.89       cjs 		echo -n ' rpc.bootparamd'; rpc.bootparamd $bootparamd_flags
    182  1.89       cjs 	else
    183  1.89       cjs 		echo
    184  1.89       cjs 		logger -s "WARNING: /etc/bootparams not found. " \
    185  1.89       cjs 		    "bootparamd not started."
    186  1.67   mycroft 	fi
    187  1.63       mrg fi
    188  1.63       mrg 
    189  1.84     veego echo '.'
    190  1.84     veego 
    191  1.84     veego # load kernel modules specified in /etc/lkm.conf
    192  1.89       cjs if checkyesno lkm; then
    193  1.89       cjs 	if [ -r /etc/rc.lkm ]; then
    194  1.89       cjs 		lkmstage=BEFOREMOUNT
    195  1.89       cjs 		. /etc/rc.lkm
    196  1.89       cjs 	else
    197  1.89       cjs 		logger -s "WARNING: /etc/rc.lkm not found; LKMs not loaded."
    198  1.89       cjs 	fi
    199  1.84     veego fi
    200  1.84     veego 
    201  1.84     veego mount -a
    202  1.84     veego 
    203  1.84     veego # now start the rpc servers, for NFS server/client.
    204  1.90     veego echo -n 'starting nfs daemons:'
    205  1.84     veego 
    206  1.67   mycroft nfs_locking=NO
    207  1.67   mycroft 
    208  1.89       cjs if checkyesno nfs_server; then
    209  1.89       cjs 	if [ -r /etc/exports ]; then
    210  1.89       cjs 		rm -f /var/db/mountdtab
    211  1.89       cjs 		echo -n > /var/db/mountdtab
    212  1.89       cjs 		echo -n ' mountd';              mountd $mountd_flags
    213  1.89       cjs 		echo -n ' nfsd';                nfsd $nfsd_flags
    214  1.89       cjs 		nfs_locking=MAYBE
    215  1.89       cjs 	else
    216  1.89       cjs 		echo
    217  1.89       cjs 		logger -s "WARNING: /etc/exports not readable; " \
    218  1.89       cjs 		    "NFS server not started."
    219  1.69   mycroft 	fi
    220   1.1       cgd fi
    221  1.63       mrg 
    222  1.89       cjs if checkyesno nfs_client; then
    223  1.63       mrg         echo -n ' nfsiod';              nfsiod $nfsiod_flags
    224  1.67   mycroft 	nfs_locking=MAYBE
    225  1.66    scottr fi
    226  1.66    scottr 
    227  1.67   mycroft if [ "$nfs_locking" != NO ]; then
    228  1.89       cjs 	if checkyesno statd; then
    229  1.71   mycroft 		echo -n ' rpc.statd';		rpc.statd $statd_flags
    230  1.66    scottr 	fi
    231  1.89       cjs 	if checkyesno lockd; then
    232  1.71   mycroft 		echo -n ' rpc.lockd';		rpc.lockd $lockd_flags
    233  1.66    scottr 	fi
    234  1.63       mrg fi
    235  1.63       mrg 
    236  1.89       cjs if checkyesno amd; then
    237  1.89       cjs 	if [ -d "$amd_dir" ]; then
    238  1.89       cjs 		if [ -r "$amd_master" ]; then
    239  1.89       cjs 			echo -n ' amd'
    240  1.89       cjs 			amd $amd_flags -p -a $amd_dir `cat $amd_master` \
    241  1.89       cjs 			    > /var/run/amd.pid
    242  1.89       cjs 		else
    243  1.89       cjs 			echo
    244  1.89       cjs 			logger -s "WARNING: \$amd_master ($amd_master)not " \
    245  1.89       cjs 			    "readable; amd not started."
    246  1.89       cjs 		fi
    247  1.89       cjs 	else
    248  1.89       cjs 		echo
    249  1.89       cjs 		logger -s "WARNING: \$amd_dir ($amd_dir) not a directory; " \
    250  1.89       cjs 		    "amd not started."
    251  1.67   mycroft 	fi
    252  1.63       mrg fi
    253  1.63       mrg 
    254   1.1       cgd echo '.'
    255  1.83  drochner 
    256  1.63       mrg if [ -f /sbin/ldconfig ]; then
    257  1.63       mrg 	echo 'creating runtime link editor directory cache.'
    258  1.88   thorpej 	ldconfig
    259  1.63       mrg fi 
    260  1.83  drochner 
    261  1.83  drochner # load kernel modules specified in /etc/lkm.conf
    262  1.89       cjs if checkyesno lkm && [ -f /etc/rc.lkm ]; then
    263  1.83  drochner 	lkmstage=AFTERMOUNT
    264  1.83  drochner 	. /etc/rc.lkm
    265   1.1       cgd fi
    266   1.1       cgd 
    267  1.89       cjs echo -n 'checking quotas:'; quotacheck -a; echo ' done.'
    268  1.47   deraadt quotaon -a
    269   1.1       cgd 
    270   1.1       cgd # build ps databases
    271   1.2       cgd echo 'building databases...'
    272  1.11       cgd kvm_mkdb /netbsd
    273   1.1       cgd dev_mkdb
    274   1.1       cgd 
    275   1.1       cgd chmod 666 /dev/tty[pqrs]*
    276   1.1       cgd 
    277   1.1       cgd # check the password temp/lock file
    278   1.1       cgd if [ -f /etc/ptmp ]
    279   1.1       cgd then
    280   1.1       cgd 	logger -s -p auth.err \
    281   1.1       cgd 	'password file may be incorrect -- /etc/ptmp exists'
    282   1.1       cgd fi
    283   1.1       cgd 
    284  1.85     perry virecovery=`echo /var/tmp/vi.recover/recover.*`
    285  1.32   mycroft if [ "$virecovery" != "/var/tmp/vi.recover/recover.*" ]; then
    286  1.32   mycroft 	echo preserving editor files
    287  1.32   mycroft 	for i in $virecovery; do
    288  1.32   mycroft 		sendmail -t < $i
    289  1.32   mycroft 	done
    290  1.32   mycroft fi
    291   1.1       cgd 
    292   1.1       cgd echo clearing /tmp
    293   1.1       cgd 
    294  1.65     mikel # Prune quickly with one rm, then use find to clean up /tmp/[lq]* (this
    295  1.65     mikel # is not needed with mfs /tmp, but doesn't hurt anything).
    296   1.1       cgd (cd /tmp && rm -rf [a-km-pr-zA-Z]* &&
    297  1.46   deraadt     find . ! -name . ! -name lost+found ! -name quota.user \
    298  1.46   deraadt 	! -name quota.group -exec rm -rf -- {} \; -type d -prune)
    299   1.1       cgd 
    300  1.74     perry # Update kernel info in /etc/motd
    301  1.74     perry # Must be done *before* interactive logins are possible to prevent
    302  1.74     perry # possible race conditions.
    303  1.89       cjs if checkyesno update_motd; then
    304  1.74     perry 	echo 'updating motd.'
    305  1.74     perry 	if [ ! -f /etc/motd ]; then
    306  1.74     perry 		install -c -o root -g wheel -m 664 /dev/null /etc/motd
    307  1.74     perry 	fi
    308  1.74     perry 	T=/tmp/_motd
    309  1.74     perry 	rm -f $T
    310  1.74     perry 	sysctl -n kern.version | sed 1q > $T
    311  1.74     perry 	echo "" >> $T
    312  1.74     perry 	sed '1,/^$/d' < /etc/motd >> $T
    313  1.74     perry 	cmp -s $T /etc/motd || cp $T /etc/motd
    314  1.74     perry 	rm -f $T
    315  1.74     perry fi
    316  1.74     perry 
    317  1.34       cgd if [ -f /var/account/acct ]; then
    318  1.34       cgd 	echo 'turning on accounting';	accton /var/account/acct
    319  1.34       cgd fi
    320   1.1       cgd 
    321   1.1       cgd echo -n standard daemons:
    322  1.89       cjs if checkyesno update; then
    323  1.70   mycroft 	echo -n ' update';		update $update_flags
    324  1.70   mycroft fi
    325  1.31       jtc echo -n ' cron';		cron
    326   1.1       cgd echo '.'
    327   1.1       cgd 
    328  1.63       mrg # now start all the other daemons
    329   1.1       cgd echo -n starting network daemons:
    330   1.1       cgd 
    331  1.89       cjs if checkyesno gated && checkyesno routed; then
    332  1.89       cjs 	echo
    333  1.89       cjs 	logger -s "WARNING: gated and routed both requested to be run: " \
    334  1.89       cjs 	    "running only gated."
    335  1.89       cjs 	routed=NO
    336  1.89       cjs fi
    337  1.89       cjs 
    338  1.89       cjs if checkyesno gated; then
    339  1.89       cjs 	if [ -r /etc/gated.conf ]; then
    340  1.89       cjs 		echo -n ' gated';		gated $gated_flags
    341  1.89       cjs 	else
    342  1.89       cjs 		logger -s "WARNING: no /etc/gated.conf; gated not started."
    343  1.67   mycroft 	fi
    344  1.89       cjs fi
    345  1.89       cjs 
    346  1.89       cjs if checkyesno routed; then
    347  1.48   mycroft 	echo -n ' routed';		routed $routed_flags
    348   1.1       cgd fi
    349   1.1       cgd 
    350  1.89       cjs if checkyesno mrouted; then
    351  1.55   thorpej 	echo -n ' mrouted';		mrouted $mrouted_flags
    352  1.55   thorpej fi
    353  1.55   thorpej 
    354  1.89       cjs if checkyesno timed; then
    355  1.67   mycroft 	echo -n ' timed'; 		timed $timed_flags
    356  1.63       mrg fi
    357  1.63       mrg 
    358  1.89       cjs if checkyesno xntpd; then
    359  1.67   mycroft 	echo -n ' xntpd';		xntpd $xntpd_flags
    360  1.61       mrg fi
    361  1.61       mrg 
    362  1.89       cjs if checkyesno dhcpd; then
    363  1.89       cjs 	if [ -r /etc/dhcpd.conf ]; then
    364  1.89       cjs 		echo -n ' dhcpd';		dhcpd $dhcpd_flags
    365  1.89       cjs 	else
    366  1.89       cjs 		echo
    367  1.89       cjs 		logger -s "WARNING: /etc/dhcpd.conf not readable; " \
    368  1.89       cjs 		    "dhcpd not started."
    369  1.67   mycroft 	fi
    370  1.29   mycroft fi
    371  1.29   mycroft 
    372  1.89       cjs if checkyesno rwhod; then
    373  1.48   mycroft 	echo -n ' rwhod';		rwhod
    374   1.1       cgd fi
    375   1.1       cgd 
    376  1.89       cjs if checkyesno lpd; then
    377  1.89       cjs 	echo -n ' lpd';			lpd $lpd_flags
    378  1.60       tls fi
    379  1.60       tls 
    380  1.63       mrg # We call sendmail with a full path so that SIGHUP works.
    381  1.89       cjs if checkyesno sendmail; then
    382  1.89       cjs 	if [ -r /etc/sendmail.cf ]; then
    383  1.89       cjs 		echo -n ' sendmail';	/usr/sbin/sendmail $sendmail_flags
    384  1.89       cjs 	else
    385  1.89       cjs 		echo
    386  1.89       cjs 		logger -s "WARNING: /etc/sendmail.cf not readable; " \
    387  1.89       cjs 		    "sendmail not started."
    388  1.67   mycroft 	fi
    389  1.60       tls fi
    390  1.60       tls 
    391  1.89       cjs if checkyesno rarpd; then
    392  1.89       cjs 	if [ -r /etc/ethers ]; then
    393  1.89       cjs 		echo -n ' rarpd';	rarpd $rarpd_flags
    394  1.89       cjs 	else
    395  1.89       cjs 		echo
    396  1.89       cjs 		logger -s "WARNING: /etc/ethers not readable; " \
    397  1.89       cjs 		    "rarpd not started."
    398  1.67   mycroft 	fi
    399  1.60       tls fi
    400  1.60       tls 
    401  1.89       cjs if checkyesno rbootd; then
    402  1.89       cjs 	if [ -r /etc/rbootd.conf ]; then
    403  1.89       cjs 		echo -n ' rbootd';	rbootd $rbootd_flags
    404  1.89       cjs 	else
    405  1.89       cjs 		echo
    406  1.89       cjs 		logger -s "WARNING: /etc/rbootd.conf not readable; " \
    407  1.89       cjs 		    "rarpd not started."
    408  1.67   mycroft 	fi
    409  1.72       cjs fi
    410  1.72       cjs 
    411  1.89       cjs if checkyesno mopd; then
    412  1.72       cjs 	echo -n ' mopd';		mopd $mopd_flags
    413  1.86     perry fi
    414  1.86     perry 
    415  1.89       cjs if checkyesno apmd; then
    416  1.86     perry 	echo -n ' apmd';		apmd $apmd_flags
    417  1.52   thorpej fi
    418  1.52   thorpej 
    419  1.89       cjs if checkyesno inetd; then
    420  1.89       cjs 	if [ -r /etc/inetd.conf ]; then
    421  1.89       cjs 		echo -n ' inetd';	inetd $inetd_flags
    422  1.89       cjs 	else
    423  1.89       cjs 		echo
    424  1.89       cjs 		logger -s "WARNING: /etc/inetd.conf not readable; " \
    425  1.89       cjs 		    "inetd not started."
    426  1.67   mycroft 	fi
    427  1.30   mycroft fi
    428  1.30   mycroft 
    429   1.1       cgd echo '.'
    430  1.73     perry 
    431  1.73     perry # Kerberos runs ONLY on the Kerberos server machine
    432  1.89       cjs if checkyesno kerberos; then
    433  1.73     perry 	echo -n 'starting kerberos daemons:'
    434  1.73     perry 	echo -n ' kerberos';	kerberos >> /var/log/kerberos.log &
    435  1.73     perry 	echo -n ' kadmind';	kadmind -n >> /var/log/kadmind.log &
    436  1.73     perry 	echo '.'
    437  1.73     perry fi
    438   1.1       cgd 
    439  1.25   mycroft . /etc/rc.local
    440   1.1       cgd 
    441   1.1       cgd date
    442   1.1       cgd exit 0
    443