rc revision 19226
1709Swollman#!/bin/sh
219226Sjoerg#	$Id: rc,v 1.102 1996/10/21 20:09:30 wpaul Exp $
3709Swollman#	From: @(#)rc	5.27 (Berkeley) 6/5/91
437Srgrimes
537Srgrimes# System startup script run by init on autoboot
637Srgrimes# or after single-user.
737Srgrimes# Output and error are redirected to console by init,
837Srgrimes# and the console is the controlling terminal.
937Srgrimes
108460Sjkh# Note that almost all the user-configurable behavior is no longer in
118460Sjkh# this file, but rather in /etc/sysconfig.  Please check this file
128460Sjkh# first before contemplating any changes here.
138460Sjkh
1437Srgrimesstty status '^T'
1537Srgrimes
1637Srgrimes# Set shell to ignore SIGINT (2), but not children;
1737Srgrimes# shell catches SIGQUIT (3) and returns to single user after fsck.
1837Srgrimestrap : 2
1937Srgrimestrap : 3	# shouldn't be needed
2037Srgrimes
2137SrgrimesHOME=/; export HOME
2237SrgrimesPATH=/sbin:/bin:/usr/sbin:/usr/bin
2337Srgrimesexport PATH
2437Srgrimes
2515568Sasami# Configure ccd devices.
2615568Sasamiif [ -f /etc/ccd.conf ]
2715568Sasamithen
2815568Sasami	ccdconfig -C
2915568Sasamifi
3015568Sasami
313843Sdgswapon -a
323843Sdg
332164Sdgif [ $1x = autobootx ]
3437Srgrimesthen
3537Srgrimes	echo Automatic reboot in progress...
3637Srgrimes	fsck -p
3737Srgrimes	case $? in
3837Srgrimes	0)
3937Srgrimes		;;
4037Srgrimes	2)
4137Srgrimes		exit 1
4237Srgrimes		;;
4337Srgrimes	4)
4437Srgrimes		reboot
4537Srgrimes		echo "reboot failed... help!"
4637Srgrimes		exit 1
4737Srgrimes		;;
4837Srgrimes	8)
4937Srgrimes		echo "Automatic file system check failed... help!"
5037Srgrimes		exit 1
5137Srgrimes		;;
5237Srgrimes	12)
5337Srgrimes		echo "Reboot interrupted"
5437Srgrimes		exit 1
5537Srgrimes		;;
5637Srgrimes	130)
5737Srgrimes		# interrupt before catcher installed
5837Srgrimes		exit 1
5937Srgrimes		;;
6037Srgrimes	*)
6137Srgrimes		echo "Unknown error in reboot"
6237Srgrimes		exit 1
6337Srgrimes		;;
6437Srgrimes	esac
652164Sdgelse
662164Sdg	echo Skipping disk checks ...
6737Srgrimesfi
6837Srgrimes
6937Srgrimestrap "echo 'Reboot interrupted'; exit 1" 3
7037Srgrimes
713036Sdg# root must be read/write both for NFS diskless and for VFS LKMs before
723036Sdg# proceeding any further.
733036Sdgmount -u -o rw /
748530Sdgif [ $? != 0 ]; then
758530Sdg	echo "Filesystem mount failed, startup aborted"
768530Sdg	exit 1
778530Sdgfi
781692Sphk
7937Srgrimesumount -a >/dev/null 2>&1
808530Sdg
8137Srgrimesmount -a -t nonfs
828530Sdgif [ $? != 0 ]; then
838530Sdg	echo "Filesystem mount failed, startup aborted"
848530Sdg	exit 1
858530Sdgfi
8637Srgrimes
874091Sacheadjkerntz -i
88872Sache
897219Sjkh# If there is a global system configuration file, suck it in.
907219Sjkhif [ -f /etc/sysconfig ]; then
917219Sjkh	. /etc/sysconfig
927219Sjkhfi
937219Sjkh
9417767Sjkh# Add additional swapfile, if configured.
9518460Simpif [ "x$swapfile" != "xNO" -a -w "$swapfile" -a -f /dev/vn0b ]; then
9617767Sjkh	echo "Adding $swapfile as additional swap."
9717767Sjkh	/usr/sbin/vnconfig /dev/vn0b $swapfile && swapon /dev/vn0b
9817767Sjkhfi
9917767Sjkh
1001675Sache# configure serial devices
1017219Sjkhif [ -f /etc/rc.serial ]; then
1027293Sjkh	. /etc/rc.serial
1031675Sachefi
1041675Sache
10514596Snate# start up PC-card configuration
10614624Snateif [ -f /etc/rc.pccard ]; then
10714624Snate	. /etc/rc.pccard
10814596Snatefi
10914596Snate
1107487Srgrimes# start up the network
1117460Sjkhif [ -f /etc/netstart ]; then
1127750Srgrimes	sh /etc/netstart
1137460Sjkhfi
1147460Sjkh
1158540Srgrimesmount -a -t nfs >/dev/null 2>&1
1167487Srgrimes
1177487Srgrimes# Whack the pty perms back into shape.
1187487Srgrimeschmod 666 /dev/tty[pqrs]*
1197487Srgrimes
1207487Srgrimes# clean up left-over files
1217487Srgrimesrm -f /etc/nologin
1227487Srgrimesrm -f /var/spool/lock/*
1237761Sacherm -rf /var/spool/uucp/.Temp/*
12415684Sjkh(cd /var/run && { cp /dev/null utmp; chmod 644 utmp; })
1257487Srgrimes
12616588Sjoerg#
12716588Sjoerg# Clearing /tmp at boot-time is essentially stupid, but seems to have
12816588Sjoerg# a long tradition.  It doesn't help in any way for long-living systems,
12916588Sjoerg# and it might accidentally clobber files you would rather like to have
13016588Sjoerg# preserved after a crash (if not using mfs /tmp anyway).
13116588Sjoerg#
13216588Sjoerg# See also the commented out example of another cleanup policy in
13316588Sjoerg# /etc/daily.
13416588Sjoerg#
1357487Srgrimesecho clearing /tmp
1367487Srgrimes
1377487Srgrimes# prune quickly with one rm, then use find to clean up /tmp/[lq]*
1387487Srgrimes# (not needed with mfs /tmp, but doesn't hurt there...)
1397487Srgrimes(cd /tmp && rm -rf [a-km-pr-zA-Z]* &&
1407487Srgrimes    find -d . ! -name . ! -name lost+found ! -name quotas -exec rm -rf -- {} \;)
1417487Srgrimes
14216588Sjoerg# The above is even more stupid since it prevents you from restarting
14316588Sjoerg# X11 after a system crash.  If you disable the above, make sure to
14416588Sjoerg# uncomment the line below.
14516588Sjoerg#
14616588Sjoerg# clean up leftover X lock files and local connection sockets
14716588Sjoerg#rm -f /tmp/.X*-lock /tmp/.X11-unix/*
14816588Sjoerg
14916588Sjoerg
1509305Sbde# enable dumpdev so that savecore can see it
1519305Sbdeif [ "X${dumpdev}" != X"NO" ]; then
1529305Sbde	dumpon ${dumpdev}
1539305Sbdefi
1549305Sbde
1557487Srgrimes# /var/crash should be a directory or a symbolic link
1567487Srgrimes# to the crash directory if core dumps are to be saved.
1577487Srgrimesif [ "X${savecore}" = X"YES" -a -d /var/crash ]; then
1587487Srgrimes	echo -n checking for core dump...
1597487Srgrimes	savecore /var/crash
1607487Srgrimesfi
1617487Srgrimes
1627487Srgrimes# snapshot any kernel -c changes back to disk
1637487Srgrimesecho 'recording kernel -c changes'
1647487Srgrimes/sbin/dset -q
1657487Srgrimes
1667487Srgrimes# start system logging and name service (named needs to start before syslogd
1677487Srgrimes# if you don't have a /etc/resolv.conf)
1687259Sjkh#
1697487Srgrimesecho -n starting system daemons:
1707487Srgrimes
17119226Sjoerg# Transitional symlink (for the next couple of years :) until all
17219226Sjoerg# binaries had a chance to move towards /var/run/log.
17319226Sjoergif [ ! -h /dev/log ] ; then
17419226Sjoerg	# might complain for r/o root f/s
17519226Sjoerg	ln -sf /var/run/log /dev/log
17619226Sjoergfi
17719226Sjoergrm -f /var/run/log
1787708Srgrimesecho ' syslogd.';			syslogd
1797487Srgrimes
18018812Speterecho -n starting early network daemons:
1817487Srgrimes
1827487Srgrimes# $namedflags is imported from /etc/sysconfig
18317336Sjkhif [ "X${namedflags}" != X"NO" ]; then
1847708Srgrimes	echo -n ' named';		named $namedflags
185857Sdgfi
18637Srgrimes
1877487Srgrimes# $ntpdate and $xntpdflags are imported from /etc/sysconfig.
1887487Srgrimes# If $ntpdate != NO, run ntpdate $ntpdate to set the date correctly.
1897487Srgrimes# If $xntpdflags != NO, start xntpd.
1907487Srgrimesif [ "X${ntpdate}" != X"NO" -o "X${xntpdflags}" != X"NO" ]; then
1917487Srgrimes	if [ "X${tickadjflags}" != X"NO" ]; then
1927487Srgrimes		echo -n ' tickadj';	tickadj ${tickadjflags--Aq}
1937487Srgrimes	fi
194958Sache
1957487Srgrimes	if [ "X${ntpdate}" != X"NO" ]; then
1967487Srgrimes		echo -n ' ntpdate';	ntpdate ${ntpdate} >/dev/null 2>&1
1977487Srgrimes	fi
1987487Srgrimes
1997487Srgrimes	if [ "X${xntpdflags}" != X"NO" ]; then
2007487Srgrimes		echo -n ' xntpd';	xntpd ${xntpdflags}
2017487Srgrimes	fi
2021186Srgrimesfi
2031186Srgrimes
2047487Srgrimes# $timedflags is imported from /etc/sysconfig;
2057487Srgrimes# if $timedflags == NO, timed isn't run.
2067487Srgrimesif [ "X${timedflags}" != X"NO" ]; then
2077487Srgrimes	echo -n ' timed'; timed $timedflags
2087487Srgrimesfi
2097219Sjkh
2107487Srgrimes# Portmapper should always be run, to provide RPC services for inetd.
2117487Srgrimesif [ -x /usr/sbin/portmap ]; then
2127487Srgrimes	echo -n ' portmap';		portmap
2137487Srgrimesfi
2147238Sache
2157487Srgrimes# Start ypserv if we're an NIS server.
21619076Swpaul# Run rpc.ypxfrd and rpc.yppasswdd only on the NIS master server.
2177487Srgrimesif [ "X${nis_serverflags}" != X"NO" ]; then
2187708Srgrimes	echo -n ' ypserv'; ypserv ${nis_serverflags}
2197238Sache
22019076Swpaul	if [ "X${ypxfrdflags}" != X"NO" ]; then
22119076Swpaul		echo -n ' rpc.ypxfrd'; rpc.ypxfrd ${ypxfrdflags}
22219076Swpaul	fi
22319076Swpaul
2247487Srgrimes	if [ "X${yppasswddflags}" != X"NO" ]; then
22519076Swpaul		echo -n ' rpc.yppasswdd'; rpc.yppasswdd ${yppasswddflags}
2267487Srgrimes	fi
2277487Srgrimesfi
2287238Sache
2297487Srgrimes# Start ypbind if we're an NIS client
2307487Srgrimesif [ "X${nis_clientflags}" != X"NO" ]; then
2317708Srgrimes	echo -n ' ypbind'; ypbind ${nis_clientflags}
2329593Swollman	if [ "X${nis_ypsetflags}" != X"NO" ]; then
2339593Swollman		echo -n ' ypset'; ypset ${nis_ypsetflags}
2349593Swollman	fi
2357219Sjkhfi
2367219Sjkh
23718812Speterecho '.'
23818812Speter
23918812Speter# Check the quotas (must be after ypbind if using NIS)
24018812Speterif [ "X${check_quotas}" = X"YES" ]; then
24118812Speter	echo -n 'checking quotas:'
24218812Speter	quotacheck -a
24318812Speter	echo ' done.'
24418812Speter	quotaon -a
2457238Sachefi
2467238Sache
24718812Speterecho -n starting other network daemons:
24818812Speter
2497487Srgrimesif [ "X${nfs_server}" = X"YES" -a -r /etc/exports ]; then
25010716Sjkh	echo -n ' mountd'
25113071Sjkh	if [ "X${weak_mountd_authentication}" = X"YES" ]; then
25210716Sjkh		mountd -n
25310716Sjkh	else
25410716Sjkh		mountd
25510716Sjkh	fi
2567487Srgrimes	echo -n ' nfsd';		nfsd -u -t 4
2577477Sachefi
2587477Sache
2597487Srgrimesif [ "X${nfs_client}" = X"YES" ]; then
2607487Srgrimes	echo -n ' nfsiod';		nfsiod -n 4
2617487Srgrimesfi
2627238Sache
2637487Srgrimesif [ "X${amdflags}" != X"NO" ]; then
26413455Sgraichen	echo -n ' amd'
26518813Speter	amd -p ${amdflags} > /var/run/amd.pid
2667238Sachefi
2677238Sache
26818812Speter# $rwhod is imported from /etc/sysconfig;
26918812Speter# if $rwhod is set to YES, rwhod is run.
27018812Speterif [ "X${rwhod}" = X"YES" ]; then
27118812Speter	echo -n ' rwhod';	rwhod
27218812Speterfi
27318812Speter
2747487Srgrimes# Kerberos runs ONLY on the Kerberos server machine
2757487Srgrimesif [ "X${kerberos_server}" = X"YES" ]; then
2767487Srgrimes	echo -n ' kerberos';	kerberos >> /var/log/kerberos.log &
2777487Srgrimes	echo -n ' kadmind'; \
27812053Spst		(sleep 20; kadmind -n >/dev/null 2>&1 &) &
2797238Sachefi
2807238Sache
28113701Sgpalmer# IP multicast routing daemon
28213701Sgpalmerif [ "X${mrouted}" != X"NO" -a -x /usr/sbin/mrouted ]; then
28313701Sgpalmer	echo -n ' mrouted'; mrouted ${mrouted}
28413701Sgpalmerfi
28513701Sgpalmer
2867487Srgrimesecho '.'
2877487Srgrimes
2887487Srgrimes# build ps databases
2897487Srgrimeskvm_mkdb 
2907487Srgrimesdev_mkdb
2917487Srgrimes
2927487Srgrimes# check the password temp/lock file
2937487Srgrimesif [ -f /etc/ptmp ]
2947487Srgrimesthen
2957487Srgrimes	logger -s -p auth.err \
2967487Srgrimes	"password file may be incorrect -- /etc/ptmp exists"
2977238Sachefi
2987238Sache
2997487Srgrimesif [ "X${accounting}" = X"YES" -a -d /var/account ]; then
30011992Sache	echo 'turning on accounting'
30111992Sache	if [ ! -e /var/account/acct ]; then
30211992Sache		touch /var/account/acct
30311992Sache	fi
30411992Sache	accton /var/account/acct
3057238Sachefi
3067238Sache
3077487Srgrimes# Make shared lib searching a little faster.  Leave /usr/lib first if you
3087487Srgrimes# add your own entries or you may come to grief.
3097487Srgrimesif [ -x /sbin/ldconfig ]; then
3107487Srgrimes	_LDC=/usr/lib
31117998Sphk	if [ -d /usr/lib/compat ]; then _LDC="${_LDC} /usr/lib/compat" ; fi
3127487Srgrimes	if [ -d /usr/X11R6/lib ]; then _LDC="${_LDC} /usr/X11R6/lib" ; fi
3137487Srgrimes	if [ -d /usr/X386/lib ]; then _LDC="${_LDC} /usr/X386/lib" ; fi
3147487Srgrimes	if [ -d /usr/local/lib ]; then _LDC="${_LDC} /usr/local/lib" ; fi
3157487Srgrimes	echo 'setting ldconfig path:' ${_LDC}
3167487Srgrimes	ldconfig ${_LDC}
3177296Sjkhfi
3187296Sjkh
31917210Spst# Now start up miscellaneous daemons that don't belong anywhere else
32017210Spst#
32117210Spstecho -n standard daemons:
32218812Speterecho -n ' inetd';		inetd
32317210Spstecho -n ' cron';		cron
32417210Spst
32517210Spstif [ "X${lpd}" != X"NO" -a -x /usr/sbin/lpd ]; then
32617210Spst	echo -n ' printer';		lpd
32717210Spstfi
32817210Spst
32917161Spst# $sendmail_flags is imported from /etc/sysconfig;
33017161Spst# if $sendmail_flags is something other than NO, sendmail is run.
33117161Spstif [ "X${sendmail_flags}" != X"NO" -a -r /etc/sendmail.cf ]; then
33217161Spst	echo -n ' sendmail';            /usr/sbin/sendmail ${sendmail_flags}
33317161Spstfi
33417161Spst
33517161Spstecho '.'
33617161Spst
3377487Srgrimes# configure implementation specific stuff
3387487Srgrimesarch=`uname -m`
33910895Sjkhif [ -f /etc/rc.${arch} ]; then
34010895Sjkh	. /etc/rc.${arch}
3417487Srgrimesfi
3427487Srgrimes
34316671Spst# Recover vi editor files.
34416671Spstvirecovery=`echo /var/tmp/vi.recover/recover.*`
34516671Spstif [ "$virecovery" != '/var/tmp/vi.recover/recover.*' ]; then
34616671Spst	echo 'Recovering vi editor sessions'
34716671Spst	for i in $virecovery; do
34816671Spst		sendmail -t < $i
34916671Spst	done
35016671Spstfi
35116671Spst
35213071Sjkh# for each valid dir in $local_startup, search for init scripts matching *.sh
35313071Sjkhif [ "X${local_startup}" != X"NO" ]; then
35416391Sjkh	echo -n 'Local package startup:'
35513071Sjkh	for dir in ${local_startup}; do
35613071Sjkh		[ -d ${dir} ] && for script in ${dir}/*.sh; do
35713071Sjkh			[ -x ${script} ] && ${script} start
35813071Sjkh		done
35910873Sjkh	done
36016391Sjkh	echo .
3617259Sjkhfi
36237Srgrimes
36310873Sjkh# Do traditional (but rather obsolete) rc.local file if it exists.
36410898Sjkh[ -f /etc/rc.local ] && sh /etc/rc.local
36510873Sjkh
36637Srgrimesdate
36737Srgrimesexit 0
368