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