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