rc revision 15568
1116742Ssam#!/bin/sh
2116904Ssam#	$Id: rc,v 1.87 1996/03/14 18:24:05 nate Exp $
3186904Ssam#	From: @(#)rc	5.27 (Berkeley) 6/5/91
4116742Ssam
5116742Ssam# System startup script run by init on autoboot
6116742Ssam# or after single-user.
7116742Ssam# Output and error are redirected to console by init,
8116742Ssam# and the console is the controlling terminal.
9116742Ssam
10116742Ssam# Note that almost all the user-configurable behavior is no longer in
11116742Ssam# this file, but rather in /etc/sysconfig.  Please check this file
12116742Ssam# first before contemplating any changes here.
13116742Ssam
14116742Ssamstty status '^T'
15116904Ssam
16116904Ssam# Set shell to ignore SIGINT (2), but not children;
17116904Ssam# shell catches SIGQUIT (3) and returns to single user after fsck.
18116904Ssamtrap : 2
19116904Ssamtrap : 3	# shouldn't be needed
20116904Ssam
21116904SsamHOME=/; export HOME
22116904SsamPATH=/sbin:/bin:/usr/sbin:/usr/bin
23116904Ssamexport PATH
24116904Ssam
25116904Ssam# Configure ccd devices.
26116742Ssamif [ -f /etc/ccd.conf ]
27116742Ssamthen
28116742Ssam	ccdconfig -C
29116742Ssamfi
30116742Ssam
31138568Ssamswapon -a
32170530Ssam
33116742Ssamif [ $1x = autobootx ]
34138568Ssamthen
35178354Ssam	echo Automatic reboot in progress...
36178354Ssam	fsck -p
37178354Ssam	case $? in
38178354Ssam	0)
39178354Ssam		;;
40178354Ssam	2)
41178354Ssam		exit 1
42178354Ssam		;;
43178354Ssam	4)
44178354Ssam		reboot
45138568Ssam		echo "reboot failed... help!"
46138568Ssam		exit 1
47138568Ssam		;;
48138568Ssam	8)
49138568Ssam		echo "Automatic file system check failed... help!"
50138568Ssam		exit 1
51138568Ssam		;;
52138568Ssam	12)
53138568Ssam		echo "Reboot interrupted"
54170530Ssam		exit 1
55138568Ssam		;;
56172211Ssam	130)
57172211Ssam		# interrupt before catcher installed
58172211Ssam		exit 1
59116742Ssam		;;
60116742Ssam	*)
61116742Ssam		echo "Unknown error in reboot"
62170530Ssam		exit 1
63138568Ssam		;;
64116742Ssam	esac
65138568Ssamelse
66138568Ssam	echo Skipping disk checks ...
67178354Ssamfi
68138568Ssam
69116742Ssamtrap "echo 'Reboot interrupted'; exit 1" 3
70178354Ssam
71178354Ssam# root must be read/write both for NFS diskless and for VFS LKMs before
72190093Srpaulo# proceeding any further.
73178354Ssammount -u -o rw /
74178354Ssamif [ $? != 0 ]; then
75178354Ssam	echo "Filesystem mount failed, startup aborted"
76178354Ssam	exit 1
77178354Ssamfi
78178354Ssam
79178354Ssamumount -a >/dev/null 2>&1
80178354Ssam
81178354Ssammount -a -t nonfs
82178354Ssamif [ $? != 0 ]; then
83186904Ssam	echo "Filesystem mount failed, startup aborted"
84178354Ssam	exit 1
85178354Ssamfi
86178354Ssam
87178354Ssam# If the machine runs wall CMOS clock (compatible with MSDOS),
88178354Ssam# activate following line by creating empty file /etc/wall_cmos_clock
89178354Ssam# If this file not exist, following line does nothing (assumed
90116742Ssam# the machine runs UTC CMOS clock). See adjkerntz(8) for details.
91116742Ssamadjkerntz -i
92116742Ssam
93116742Ssam# If there is a global system configuration file, suck it in.
94116742Ssamif [ -f /etc/sysconfig ]; then
95116742Ssam	. /etc/sysconfig
96178354Ssamfi
97178354Ssam
98178354Ssam# configure serial devices
99178354Ssamif [ -f /etc/rc.serial ]; then
100178354Ssam	. /etc/rc.serial
101178354Ssamfi
102120483Ssam
103183252Ssam# start up PC-card configuration
104183252Ssamif [ -f /etc/rc.pccard ]; then
105183252Ssam	. /etc/rc.pccard
106183252Ssamfi
107183252Ssam
108183252Ssam# start up the network
109183252Ssamif [ -f /etc/netstart ]; then
110183252Ssam	sh /etc/netstart
111183252Ssamfi
112183252Ssam
113183252Ssammount -a -t nfs >/dev/null 2>&1
114183252Ssam
115183252Ssam# Whack the pty perms back into shape.
116183255Ssamchmod 666 /dev/tty[pqrs]*
117183255Ssam
118183256Ssam# clean up left-over files
119183257Ssamrm -f /etc/nologin
120183257Ssamrm -f /var/spool/lock/*
121186099Ssamrm -rf /var/spool/uucp/.Temp/*
122183252Ssamrm -f /dev/log
123183252Ssam(cd /var/run && { rm -rf -- *; cp /dev/null utmp; chmod 644 utmp; })
124183252Ssam
125170530Ssamecho clearing /tmp
126170530Ssam
127170530Ssam# prune quickly with one rm, then use find to clean up /tmp/[lq]*
128170530Ssam# (not needed with mfs /tmp, but doesn't hurt there...)
129170530Ssam(cd /tmp && rm -rf [a-km-pr-zA-Z]* &&
130170530Ssam    find -d . ! -name . ! -name lost+found ! -name quotas -exec rm -rf -- {} \;)
131170530Ssam
132170530Ssam# enable dumpdev so that savecore can see it
133183252Ssamif [ "X${dumpdev}" != X"NO" ]; then
134170530Ssam	dumpon ${dumpdev}
135183251Ssamfi
136173273Ssam
137170530Ssam# /var/crash should be a directory or a symbolic link
138178354Ssam# to the crash directory if core dumps are to be saved.
139172225Ssamif [ "X${savecore}" = X"YES" -a -d /var/crash ]; then
140172225Ssam	echo -n checking for core dump...
141172225Ssam	savecore /var/crash
142172225Ssamfi
143170530Ssam
144138568Ssam# snapshot any kernel -c changes back to disk
145138568Ssamecho 'recording kernel -c changes'
146116742Ssam/sbin/dset -q
147116742Ssam
148170530Ssam# Check the quotas
149178354Ssamif [ "X${check_quotas}" = X"YES" ]; then
150170530Ssam	echo 'checking quotas:'
151116742Ssam	quotacheck -a
152116742Ssam	echo ' done.'
153170530Ssam	quotaon -a
154170530Ssamfi
155116742Ssam
156116742Ssam# start system logging and name service (named needs to start before syslogd
157138568Ssam# if you don't have a /etc/resolv.conf)
158170530Ssam#
159178354Ssamecho -n starting system daemons:
160138568Ssam
161170530Ssamecho ' syslogd.';			syslogd
162170530Ssam
163170530Ssamecho -n starting network daemons:
164170530Ssam
165116742Ssam# $namedflags is imported from /etc/sysconfig
166170530Ssamif [ "X${namedflags}" != "XNO" ]; then
167170530Ssam	echo -n ' named';		named $namedflags
168170530Ssamfi
169178354Ssam
170170530Ssam# $ntpdate and $xntpdflags are imported from /etc/sysconfig.
171170530Ssam# If $ntpdate != NO, run ntpdate $ntpdate to set the date correctly.
172170530Ssam# If $xntpdflags != NO, start xntpd.
173116742Ssamif [ "X${ntpdate}" != X"NO" -o "X${xntpdflags}" != X"NO" ]; then
174170530Ssam	if [ "X${tickadjflags}" != X"NO" ]; then
175170530Ssam		echo -n ' tickadj';	tickadj ${tickadjflags--Aq}
176170530Ssam	fi
177170530Ssam
178170530Ssam	if [ "X${ntpdate}" != X"NO" ]; then
179170530Ssam		echo -n ' ntpdate';	ntpdate ${ntpdate} >/dev/null 2>&1
180170530Ssam	fi
181170530Ssam
182170530Ssam	if [ "X${xntpdflags}" != X"NO" ]; then
183170530Ssam		echo -n ' xntpd';	xntpd ${xntpdflags}
184170530Ssam	fi
185170530Ssamfi
186116742Ssam
187138568Ssam# $timedflags is imported from /etc/sysconfig;
188138568Ssam# if $timedflags == NO, timed isn't run.
189178354Ssamif [ "X${timedflags}" != X"NO" ]; then
190184288Ssam	echo -n ' timed'; timed $timedflags
191138568Ssamfi
192178354Ssam
193178354Ssam# Portmapper should always be run, to provide RPC services for inetd.
194178354Ssamif [ -x /usr/sbin/portmap ]; then
195178354Ssam	echo -n ' portmap';		portmap
196116742Ssamfi
197138568Ssam
198178354Ssam# Start ypserv if we're an NIS server.
199116742Ssam# Run yppasswdd only on the NIS master server
200170530Ssamif [ "X${nis_serverflags}" != X"NO" ]; then
201173273Ssam	echo -n ' ypserv'; ypserv ${nis_serverflags}
202173273Ssam
203182828Ssam	if [ "X${yppasswddflags}" != X"NO" ]; then
204182828Ssam		echo -n ' yppasswdd'; rpc.yppasswdd ${yppasswddflags}
205183255Ssam	fi
206183257Ssamfi
207183257Ssam
208170530Ssam# Start ypbind if we're an NIS client
209187797Ssamif [ "X${nis_clientflags}" != X"NO" ]; then
210187797Ssam	echo -n ' ypbind'; ypbind ${nis_clientflags}
211187797Ssam	if [ "X${nis_ypsetflags}" != X"NO" ]; then
212187797Ssam		echo -n ' ypset'; ypset ${nis_ypsetflags}
213187797Ssam	fi
214138568Ssamfi
215138568Ssam
216138568Ssam# $rwhod is imported from /etc/sysconfig;
217138568Ssam# if $rwhod is set to YES, rwhod is run.
218138568Ssamif [ "X${rwhod}" = X"YES" ]; then
219138568Ssam	echo -n ' rwhod';	rwhod
220178354Ssamfi
221178354Ssam
222178354Ssamif [ "X${nfs_server}" = X"YES" -a -r /etc/exports ]; then
223178354Ssam	echo -n ' mountd'
224178354Ssam	if [ "X${weak_mountd_authentication}" = X"YES" ]; then
225178354Ssam		mountd -n
226178354Ssam	else
227178354Ssam		mountd
228178354Ssam	fi
229178354Ssam	echo -n ' nfsd';		nfsd -u -t 4
230178354Ssamfi
231178354Ssam
232178354Ssamif [ "X${nfs_client}" = X"YES" ]; then
233178354Ssam	echo -n ' nfsiod';		nfsiod -n 4
234178354Ssamfi
235178354Ssam
236178354Ssamif [ "X${amdflags}" != X"NO" ]; then
237178354Ssam	echo -n ' amd'
238178354Ssam	amd ${amdflags} > /var/run/amd.pid
239178354Ssamfi
240178354Ssam
241178354Ssam# Kerberos runs ONLY on the Kerberos server machine
242178354Ssamif [ "X${kerberos_server}" = X"YES" ]; then
243178354Ssam	echo -n ' kerberos';	kerberos >> /var/log/kerberos.log &
244178354Ssam	echo -n ' kadmind'; \
245178354Ssam		(sleep 20; kadmind -n >/dev/null 2>&1 &) &
246178354Ssamfi
247178354Ssam
248178354Ssam# IP multicast routing daemon
249178354Ssamif [ "X${mrouted}" != X"NO" -a -x /usr/sbin/mrouted ]; then
250178354Ssam	echo -n ' mrouted'; mrouted ${mrouted}
251178354Ssamfi
252116742Ssam
253116742Ssamecho -n ' inetd';		inetd
254116742Ssamecho '.'
255138568Ssam
256116742Ssam# build ps databases
257116742Ssamkvm_mkdb 
258116742Ssamdev_mkdb
259116742Ssam
260116742Ssam# check the password temp/lock file
261116742Ssamif [ -f /etc/ptmp ]
262138568Ssamthen
263116742Ssam	logger -s -p auth.err \
264116742Ssam	"password file may be incorrect -- /etc/ptmp exists"
265116742Ssamfi
266116742Ssam
267116742Ssam# Recover vi editor files.
268144618Ssamvirecovery=`echo /var/tmp/vi.recover/recover.*`
269144618Ssamif [ "$virecovery" != '/var/tmp/vi.recover/recover.*' ]; then
270144618Ssam	echo 'Recovering vi editor sessions'
271178354Ssam	for i in $virecovery; do
272178354Ssam		sendmail -t < $i
273178354Ssam	done
274127877Ssamfi
275138568Ssam
276138568Ssamif [ "X${accounting}" = X"YES" -a -d /var/account ]; then
277138568Ssam	echo 'turning on accounting'
278138568Ssam	if [ ! -e /var/account/acct ]; then
279138568Ssam		touch /var/account/acct
280116742Ssam	fi
281148302Ssam	accton /var/account/acct
282148302Ssamfi
283138568Ssam
284178354Ssam# Now start up miscellaneous daemons that don't belong anywhere else
285178354Ssam#
286178354Ssamecho -n standard daemons:
287178354Ssamecho -n ' cron';		cron
288178354Ssam
289191746Sthompsaif [ "X${lpd}" != X"NO" -a -x /usr/sbin/lpd ]; then
290191746Sthompsa	echo -n ' printer';		lpd
291178354Ssamfi
292148306Ssam
293170530Ssam# $sendmail_flags is imported from /etc/sysconfig;
294184274Ssam# if $sendmail_flags is something other than NO, sendmail is run.
295170530Ssamif [ "X${sendmail_flags}" != X"NO" -a -r /etc/sendmail.cf ]; then
296178354Ssam	echo -n ' sendmail';            /usr/sbin/sendmail ${sendmail_flags}
297178354Ssamfi
298138568Ssam
299178354Ssamecho '.'
300178354Ssam
301178354Ssam# Make shared lib searching a little faster.  Leave /usr/lib first if you
302178354Ssam# add your own entries or you may come to grief.
303178354Ssamif [ -x /sbin/ldconfig ]; then
304178354Ssam	_LDC=/usr/lib
305178354Ssam	if [ -d /usr/X11R6/lib ]; then _LDC="${_LDC} /usr/X11R6/lib" ; fi
306138568Ssam	if [ -d /usr/X386/lib ]; then _LDC="${_LDC} /usr/X386/lib" ; fi
307138568Ssam	if [ -d /usr/local/lib ]; then _LDC="${_LDC} /usr/local/lib" ; fi
308178354Ssam	echo 'setting ldconfig path:' ${_LDC}
309178354Ssam	ldconfig ${_LDC}
310178354Ssamfi
311178354Ssam
312138568Ssam# configure implementation specific stuff
313138568Ssamarch=`uname -m`
314138568Ssamif [ -f /etc/rc.${arch} ]; then
315138568Ssam	. /etc/rc.${arch}
316138568Ssamfi
317138568Ssam
318170530Ssam# for each valid dir in $local_startup, search for init scripts matching *.sh
319170530Ssamif [ "X${local_startup}" != X"NO" ]; then
320178354Ssam	for dir in ${local_startup}; do
321138568Ssam		[ -d ${dir} ] && for script in ${dir}/*.sh; do
322178354Ssam			[ -x ${script} ] && ${script} start
323138568Ssam		done
324138568Ssam	done
325138568Ssamfi
326178354Ssam
327178354Ssam# Do traditional (but rather obsolete) rc.local file if it exists.
328178354Ssam[ -f /etc/rc.local ] && sh /etc/rc.local
329178354Ssam
330178354Ssamdate
331178354Ssamexit 0
332178354Ssam