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