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