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