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