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