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