rc revision 42897
1#!/bin/sh
2#	$Id: rc,v 1.168 1999/01/18 03:25:10 grog Exp $
3#	From: @(#)rc	5.27 (Berkeley) 6/5/91
4
5# System startup script run by init on autoboot
6# or after single-user.
7# Output and error are redirected to console by init,
8# and the console is the controlling terminal.
9
10# Note that almost all the user-configurable behavior is no longer in
11# this file, but rather in /etc/rc.conf.  Please check this file
12# first before contemplating any changes here.
13
14stty status '^T'
15
16# Set shell to ignore SIGINT (2), but not children;
17# shell catches SIGQUIT (3) and returns to single user after fsck.
18trap : 2
19trap : 3	# shouldn't be needed
20
21HOME=/; export HOME
22PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin
23export PATH
24
25# Configure ccd devices.
26if [ -f /etc/ccd.conf ]; then
27	ccdconfig -C
28fi
29
30if [ -n "$vinum_slices" ]; then
31	if [ -r /modules/vinum.ko ]; then	# jkh paranoia
32		kldload vinum
33		vinum read $vinum_slices
34	else
35		echo "Can't find /modules/vinum.ko"
36	fi
37fi
38
39swapon -a
40
41if [ $1x = autobootx ]; then
42	echo Automatic reboot in progress...
43	fsck -p
44	case $? in
45	0)
46		;;
47	2)
48		exit 1
49		;;
50	4)
51		reboot
52		echo "reboot failed... help!"
53		exit 1
54		;;
55	8)
56		echo "Automatic file system check failed... help!"
57		exit 1
58		;;
59	12)
60		echo "Reboot interrupted"
61		exit 1
62		;;
63	130)
64		# interrupt before catcher installed
65		exit 1
66		;;
67	*)
68		echo "Unknown error in reboot"
69		exit 1
70		;;
71	esac
72else
73	echo Skipping disk checks ...
74fi
75
76trap "echo 'Reboot interrupted'; exit 1" 3
77
78# root must be read/write for NFS diskless before proceeding any further.
79mount -u -o rw /
80if [ $? != 0 ]; then
81	echo "Filesystem mount failed, startup aborted"
82	exit 1
83fi
84
85umount -a >/dev/null 2>&1
86
87mount -a -t nonfs
88if [ $? != 0 ]; then
89	echo "Filesystem mount failed, startup aborted"
90	exit 1
91fi
92
93# If there is a global system configuration file, suck it in.
94if [ -f /etc/rc.conf ]; then
95	. /etc/rc.conf
96fi
97
98# If old file exists, whine until they fix it.
99if [ -f /etc/sysconfig ]; then
100	echo "Warning: /etc/sysconfig has been replaced by /etc/rc.conf."
101	echo "You should switch to /etc/rc.conf ASAP to eliminate this warning."
102fi
103
104adjkerntz -i
105
106clean_var() {
107	if [ ! -f /var/run/clean_var ]; then
108		rm -rf /var/run/*
109		rm -f /var/spool/lock/*
110		rm -rf /var/spool/uucp/.Temp/*
111		# Keep a copy of the boot messages around
112		dmesg >/var/run/dmesg.boot
113		# And an initial utmp file
114		(cd /var/run && cp /dev/null utmp && chmod 644 utmp; )
115		>/var/run/clean_var
116	fi
117}
118
119if [ -d /var/run -a -d /var/spool/lock -a -d /var/spool/uucp/.Temp ]; then
120	# network_pass1() *may* end up writing stuff to /var - we don't want to
121	# remove it immediately afterwards - *nor* to we want to fail to clean
122	# an nfs-mounted /var.
123	clean_var
124fi
125
126# Add additional swapfile, if configured.
127if [ "x$swapfile" != "xNO" -a -w "$swapfile" -a -b /dev/vn0b ]; then
128	echo "Adding $swapfile as additional swap."
129	vnconfig /dev/vn0b $swapfile && swapon /dev/vn0b
130fi
131
132# configure serial devices
133if [ -f /etc/rc.serial ]; then
134	. /etc/rc.serial
135fi
136
137# start up PC-card configuration
138if [ -f /etc/rc.pccard ]; then
139	. /etc/rc.pccard
140fi
141
142# start up the initial network configuration.
143if [ -f /etc/rc.network ]; then
144	. /etc/rc.network	# We only need to do this once.
145	network_pass1
146fi
147
148echo -n "Mounting NFS file systems"
149mount -a -t nfs
150echo .
151
152# Whack the pty perms back into shape.
153chmod 666 /dev/tty[pqrsPQRS]*
154
155# clean up left-over files
156clean_var			# If it hasn't already been done
157rm /var/run/clean_var
158
159#
160# Clearing /tmp at boot-time seems to have a long tradition.  It doesn't
161# help in any way for long-living systems, and it might accidentally
162# clobber files you would rather like to have preserved after a crash
163# (if not using mfs /tmp anyway).
164#
165# See also the example of another cleanup policy in /etc/periodic/daily.
166#
167if [ "X${clear_tmp_enable}" = X"YES" ]; then
168	echo clearing /tmp
169
170	# prune quickly with one rm, then use find to clean up /tmp/[lq]*
171	# (not needed with mfs /tmp, but doesn't hurt there...)
172	(cd /tmp && rm -rf [a-km-pr-zA-Z]* &&
173		find -d . ! -name . ! -name lost+found ! -name quotas -exec rm -rf -- {} \;)
174
175fi
176
177# Remove X lock files, since they will prevent you from restarting X11 
178# after a system crash.
179rm -f /tmp/.X*-lock /tmp/.X11-unix/*
180
181# snapshot any kernel -c changes back to disk here <someday>
182# this has changed with ELF and /kernel.config.
183
184echo -n 'additional daemons:'
185# start system logging and name service (named needs to start before syslogd
186# if you don't have a /etc/resolv.conf)
187#
188if [ "X${syslogd_enable}" = X"YES" ]; then
189	# Transitional symlink (for the next couple of years :) until all
190	# binaries had a chance to move towards /var/run/log.
191	if [ ! -h /dev/log ] ; then
192		# might complain for r/o root f/s
193		ln -sf /var/run/log /dev/log
194	fi
195
196	rm -f /var/run/log
197	echo -n ' syslogd';		syslogd ${syslogd_flags}
198fi
199echo '.'
200
201# enable dumpdev so that savecore can see it
202# /var/crash should be a directory or a symbolic link
203# to the crash directory if core dumps are to be saved.
204if [ "X${dumpdev}" != X"NO" -a -e ${dumpdev} -a -d /var/crash ]; then
205	dumpon ${dumpdev}
206	echo -n checking for core dump...
207	savecore /var/crash
208fi
209
210if [ -n "$network_pass1_done" ]; then
211	network_pass2
212fi
213
214# Check the quotas (must be after ypbind if using NIS)
215if [ "X${check_quotas}" = X"YES" ]; then
216	echo -n 'checking quotas:'
217	quotacheck -a
218	echo ' done.'
219	quotaon -a
220fi
221
222if [ -n "$network_pass2_done" ]; then
223	network_pass3
224fi
225
226
227# build ps databases
228kvm_mkdb 
229dev_mkdb
230
231# check the password temp/lock file
232if [ -f /etc/ptmp ]
233then
234	logger -s -p auth.err \
235	"password file may be incorrect -- /etc/ptmp exists"
236fi
237
238if [ "X${accounting_enable}" = X"YES" -a -d /var/account ]; then
239	echo 'turning on accounting'
240	if [ ! -e /var/account/acct ]; then
241		touch /var/account/acct
242	fi
243	accton /var/account/acct
244fi
245
246# Make shared lib searching a little faster.  Leave /usr/lib first if you
247# add your own entries or you may come to grief.
248if [ -x /sbin/ldconfig ]; then
249	if [ X"`/usr/bin/objformat`" = X"elf" ]; then
250		_LDC=/usr/lib
251		for i in $ldconfig_paths; do
252			if test -d $i; then
253				_LDC="${_LDC} $i"
254			fi
255		done
256		echo 'setting ELF ldconfig path:' ${_LDC}
257		ldconfig -elf ${_LDC}
258	fi
259
260	# Legacy aout support for i386 only
261	if [ X"`sysctl -n hw.machine`" = X"i386" ]; then
262		# Default the a.out ldconfig path, in case the system's
263		# /etc/rc.conf hasn't been updated.
264		: ${ldconfig_paths_aout=${ldconfig_paths}}
265		_LDC=/usr/lib/aout
266		for i in $ldconfig_paths_aout; do
267			if test -d $i; then
268				_LDC="${_LDC} $i"
269			fi
270		done
271		echo 'setting a.out ldconfig path:' ${_LDC}
272		ldconfig -aout ${_LDC}
273	fi
274fi
275
276# Now start up miscellaneous daemons that don't belong anywhere else
277#
278echo -n starting standard daemons:
279if [ "X${inetd_enable}" != X"NO" ]; then
280	echo -n ' inetd';	inetd ${inetd_flags}
281fi
282
283if [ "X${cron_enable}" != X"NO" ]; then
284	echo -n ' cron';	cron
285fi
286
287if [ "X${lpd_enable}" = X"YES" ]; then
288	echo -n ' printer';		lpd ${lpd_flags}
289fi
290
291if [ "X${sendmail_enable}" = X"YES" -a -r /etc/sendmail.cf ]; then
292	echo -n ' sendmail';	/usr/sbin/sendmail ${sendmail_flags}
293fi
294
295if [ "X${usbd_enable}" = X"YES" ]; then
296	echo -n ' usbd';	/usr/sbin/usbd ${usbd_flags}
297fi
298
299echo '.'
300
301# configure implementation specific stuff
302arch=`uname -m`
303if [ -f /etc/rc.${arch} ]; then
304	. /etc/rc.${arch}
305fi
306
307# Recover vi editor files.
308vibackup=`echo /var/tmp/vi.recover/vi.*`
309if [ "$vibackup" != '/var/tmp/vi.recover/vi.*' ]; then
310	echo 'Recovering vi editor sessions'
311	for i in $vibackup; do
312		# Only test files that are readable.
313		if test ! -r $i; then
314			continue
315		fi
316
317		# Unmodified nvi editor backup files either have the
318		# execute bit set or are zero length.  Delete them.
319		if test -x $i -o ! -s $i; then
320			rm -f $i
321		fi
322	done
323
324	# It is possible to get incomplete recovery files, if the editor
325	# crashes at the right time.
326	virecovery=`echo /var/tmp/vi.recover/recover.*`
327	if [ "$virecovery" != "/var/tmp/vi.recover/recover.*" ]; then
328		for i in $virecovery; do
329			# Only test files that are readable.
330			if test ! -r $i; then
331				continue
332			fi
333
334			# Delete any recovery files that are zero length,
335			# corrupted, or that have no corresponding backup file.
336			# Else send mail to the user.
337			recfile=`awk '/^X-vi-recover-path:/{print $2}' < $i`
338			if test -n "$recfile" -a -s "$recfile"; then
339				sendmail -t < $i
340			else
341				rm -f $i
342			fi
343		done
344	fi
345fi
346
347# make a bounds file for msgs(1) if there isn't one already
348if [ ! -f /var/msgs/bounds ]; then
349	echo 0 > /var/msgs/bounds
350fi
351
352# for each valid dir in $local_startup, search for init scripts matching *.sh
353if [ "X${local_startup}" != X"NO" ]; then
354	echo -n 'Local package initialization:'
355	for dir in ${local_startup}; do
356		[ -d ${dir} ] && for script in ${dir}/*.sh; do
357			[ -x ${script} ] && \
358				(trap 'exit 1' 2 ; ${script} start ; echo -n)
359		done
360	done
361	echo .
362fi
363
364if [ "X${update_motd}" != X"NO" ]; then
365	T=/tmp/_motd
366	rm -f $T
367	uname -v | sed -e 's,^\([^#]*\) #\(.* [1-2][0-9][0-9][0-9]\).*/\([^\]*\) $,\1 (\3) #\2,' > $T
368	awk '{if (NR == 1) {if ($1 == "FreeBSD") {next} else {print "\n"$0}} else {print}}' < /etc/motd >> $T
369	cp $T /etc/motd
370	chmod 644 /etc/motd
371	rm -f $T
372fi
373
374# Run rc.devfs if present to customify devfs
375[ -f /etc/rc.devfs ] && sh /etc/rc.devfs
376
377# Do traditional (but rather obsolete) rc.local file if it exists.  If you
378# use this file and want to make it programmatic, source /etc/rc.conf in
379# /etc/rc.local and add your custom variables to /etc/rc.conf.local, as
380# shown below.  Please do not put local extensions into /etc/rc itself. 
381# Use /etc/rc.local
382#
383# ---- rc.local  ----
384#     if [ -f /etc/rc.conf ]; then
385#             . /etc/rc.conf
386#     fi
387#
388#     ... additional startup conditionals ...
389# ---- rc.local  ----
390#
391
392if [ -f /etc/rc.local ]; then
393    echo -n 'starting local daemons:'
394    sh /etc/rc.local
395    echo '.'
396fi
397
398# Raise kernel security level.  This should be done only after `fsck' has
399# repaired local file systems if you want the securelevel to be greater than 1.
400if [ "X${kern_securelevel_enable}" = X"YES" -a "${kern_securelevel}" -ge 0 ]; 
401then
402	echo 'Raising kernel security level'
403	sysctl -w kern.securelevel=${kern_securelevel}
404fi
405
406date
407exit 0
408