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