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