2 # $Id: rc,v 1.174 1999/01/29 06:18:12 dillon Exp $
3 # From: @(#)rc 5.27 (Berkeley) 6/5/91
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.
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.
16 # Set shell to ignore SIGINT (2), but not children;
17 # shell catches SIGQUIT (3) and returns to single user after fsck.
19 trap : 3 # shouldn't be needed
22 PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin
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
30 if [ -f /etc/rc.diskless ]; then
31 dlv=`/sbin/sysctl -n vfs.nfs.diskless_valid 2> /dev/null`
32 if [ ${dlv:=0} != 0 ]; then
37 # If there is a global system configuration file, suck it in.
39 if [ -f /etc/rc.conf ]; then
43 # Configure ccd devices.
44 if [ "X$skip_diskconf" != "XYES" -a -f /etc/ccd.conf ]; then
48 if [ "X$skip_diskconf" != "XYES" -a -n "$vinum_drives" ]; then
49 vinum read $vinum_drives
52 if [ "X$skip_diskconf" != "XYES" ]; then
56 if [ "X$skip_diskconf" != "XYES" -a $1x = autobootx ]; then
57 echo Automatic reboot in progress...
67 echo "reboot failed... help!"
71 echo "Automatic file system check failed... help!"
75 echo "Reboot interrupted"
79 # interrupt before catcher installed
83 echo "Unknown error in reboot"
88 echo Skipping disk checks ...
91 trap "echo 'Reboot interrupted'; exit 1" 3
93 # root normally must be read/write, but if this is a BOOTP NFS
94 # diskless boot it does not have to be.
97 if [ "X$skip_diskconf" != "XYES" ]; then
101 echo "Filesystem mount failed, startup aborted"
105 umount -a >/dev/null 2>&1
109 echo "Filesystem mount failed, startup aborted"
114 # Run custom disk mounting function here
117 if [ "X$diskless_mount_func" != "X" ]; then
122 # If old file exists, whine until they fix it.
123 if [ -f /etc/sysconfig ]; then
124 echo "Warning: /etc/sysconfig has been replaced by /etc/rc.conf."
125 echo "You should switch to /etc/rc.conf ASAP to eliminate this warning."
131 if [ ! -f /var/run/clean_var ]; then
133 rm -f /var/spool/lock/*
134 rm -rf /var/spool/uucp/.Temp/*
135 # Keep a copy of the boot messages around
136 dmesg >/var/run/dmesg.boot
137 # And an initial utmp file
138 (cd /var/run && cp /dev/null utmp && chmod 644 utmp; )
143 if [ -d /var/run -a -d /var/spool/lock -a -d /var/spool/uucp/.Temp ]; then
144 # network_pass1() *may* end up writing stuff to /var - we don't want to
145 # remove it immediately afterwards - *nor* to we want to fail to clean
146 # an nfs-mounted /var.
150 # Add additional swapfile, if configured.
151 if [ "x$swapfile" != "xNO" -a -w "$swapfile" -a -b /dev/vn0b ]; then
152 echo "Adding $swapfile as additional swap."
153 vnconfig /dev/vn0b $swapfile && swapon /dev/vn0b
156 # configure serial devices
157 if [ -f /etc/rc.serial ]; then
161 # start up PC-card configuration
162 if [ -f /etc/rc.pccard ]; then
166 # start up the initial network configuration.
167 if [ -f /etc/rc.network ]; then
168 . /etc/rc.network # We only need to do this once.
172 echo -n "Mounting NFS file systems"
176 # Whack the pty perms back into shape.
177 chmod 666 /dev/tty[pqrsPQRS]*
179 # clean up left-over files
180 clean_var # If it hasn't already been done
181 rm /var/run/clean_var
184 # Clearing /tmp at boot-time seems to have a long tradition. It doesn't
185 # help in any way for long-living systems, and it might accidentally
186 # clobber files you would rather like to have preserved after a crash
187 # (if not using mfs /tmp anyway).
189 # See also the example of another cleanup policy in /etc/periodic/daily.
191 if [ "X${clear_tmp_enable}" = X"YES" ]; then
194 # prune quickly with one rm, then use find to clean up /tmp/[lq]*
195 # (not needed with mfs /tmp, but doesn't hurt there...)
196 (cd /tmp && rm -rf [a-km-pr-zA-Z]* &&
197 find -d . ! -name . ! -name lost+found ! -name quotas -exec rm -rf -- {} \;)
201 # Remove X lock files, since they will prevent you from restarting X11
202 # after a system crash.
203 rm -f /tmp/.X*-lock /tmp/.X11-unix/*
205 # snapshot any kernel -c changes back to disk here <someday>
206 # this has changed with ELF and /kernel.config.
208 echo -n 'additional daemons:'
209 # start system logging and name service (named needs to start before syslogd
210 # if you don't have a /etc/resolv.conf)
212 if [ "X${syslogd_enable}" = X"YES" ]; then
213 # Transitional symlink (for the next couple of years :) until all
214 # binaries had a chance to move towards /var/run/log.
215 if [ ! -h /dev/log ] ; then
216 # might complain for r/o root f/s
217 ln -sf /var/run/log /dev/log
221 echo -n ' syslogd'; syslogd ${syslogd_flags}
225 # enable dumpdev so that savecore can see it
226 # /var/crash should be a directory or a symbolic link
227 # to the crash directory if core dumps are to be saved.
228 if [ "X${dumpdev}" != X"NO" -a -e ${dumpdev} -a -d /var/crash ]; then
230 echo -n checking for core dump...
234 if [ -n "$network_pass1_done" ]; then
238 # Check the quotas (must be after ypbind if using NIS)
239 if [ "X${check_quotas}" = X"YES" ]; then
240 echo -n 'checking quotas:'
246 if [ -n "$network_pass2_done" ]; then
255 # check the password temp/lock file
258 logger -s -p auth.err \
259 "password file may be incorrect -- /etc/ptmp exists"
262 if [ "X${accounting_enable}" = X"YES" -a -d /var/account ]; then
263 echo 'turning on accounting'
264 if [ ! -e /var/account/acct ]; then
265 touch /var/account/acct
267 accton /var/account/acct
270 # Make shared lib searching a little faster. Leave /usr/lib first if you
271 # add your own entries or you may come to grief.
272 if [ -x /sbin/ldconfig ]; then
273 if [ X"`/usr/bin/objformat`" = X"elf" ]; then
275 for i in $ldconfig_paths; do
280 echo 'setting ELF ldconfig path:' ${_LDC}
281 ldconfig -elf ${_LDC}
284 # Legacy aout support for i386 only
285 if [ X"`sysctl -n hw.machine`" = X"i386" ]; then
286 # Default the a.out ldconfig path, in case the system's
287 # /etc/rc.conf hasn't been updated.
288 : ${ldconfig_paths_aout=${ldconfig_paths}}
290 for i in $ldconfig_paths_aout; do
295 echo 'setting a.out ldconfig path:' ${_LDC}
296 ldconfig -aout ${_LDC}
300 # Now start up miscellaneous daemons that don't belong anywhere else
302 echo -n starting standard daemons:
303 if [ "X${inetd_enable}" != X"NO" ]; then
304 echo -n ' inetd'; inetd ${inetd_flags}
307 if [ "X${cron_enable}" != X"NO" ]; then
308 echo -n ' cron'; cron
311 if [ "X${lpd_enable}" = X"YES" ]; then
312 echo -n ' printer'; lpd ${lpd_flags}
315 if [ "X${sendmail_enable}" = X"YES" -a -r /etc/sendmail.cf ]; then
316 echo -n ' sendmail'; /usr/sbin/sendmail ${sendmail_flags}
319 if [ "X${usbd_enable}" = X"YES" ]; then
320 echo -n ' usbd'; /usr/sbin/usbd ${usbd_flags}
325 # configure implementation specific stuff
327 if [ -f /etc/rc.${arch} ]; then
331 # Recover vi editor files.
332 vibackup=`echo /var/tmp/vi.recover/vi.*`
333 if [ "$vibackup" != '/var/tmp/vi.recover/vi.*' ]; then
334 echo 'Recovering vi editor sessions'
335 for i in $vibackup; do
336 # Only test files that are readable.
337 if test ! -r $i; then
341 # Unmodified nvi editor backup files either have the
342 # execute bit set or are zero length. Delete them.
343 if test -x $i -o ! -s $i; then
348 # It is possible to get incomplete recovery files, if the editor
349 # crashes at the right time.
350 virecovery=`echo /var/tmp/vi.recover/recover.*`
351 if [ "$virecovery" != "/var/tmp/vi.recover/recover.*" ]; then
352 for i in $virecovery; do
353 # Only test files that are readable.
354 if test ! -r $i; then
358 # Delete any recovery files that are zero length,
359 # corrupted, or that have no corresponding backup file.
360 # Else send mail to the user.
361 recfile=`awk '/^X-vi-recover-path:/{print $2}' < $i`
362 if test -n "$recfile" -a -s "$recfile"; then
371 # make a bounds file for msgs(1) if there isn't one already
372 if [ ! -f /var/msgs/bounds ]; then
373 echo 0 > /var/msgs/bounds
376 # for each valid dir in $local_startup, search for init scripts matching *.sh
377 if [ "X${local_startup}" != X"NO" ]; then
378 echo -n 'Local package initialization:'
379 for dir in ${local_startup}; do
380 [ -d ${dir} ] && for script in ${dir}/*.sh; do
381 [ -x ${script} ] && \
382 (trap 'exit 1' 2 ; ${script} start ; echo -n)
388 if [ "X${update_motd}" != X"NO" ]; then
391 uname -v | sed -e 's,^\([^#]*\) #\(.* [1-2][0-9][0-9][0-9]\).*/\([^\]*\) $,\1 (\3) #\2,' > $T
392 awk '{if (NR == 1) {if ($1 == "FreeBSD") {next} else {print "\n"$0}} else {print}}' < /etc/motd >> $T
398 # Run rc.devfs if present to customify devfs
399 [ -f /etc/rc.devfs ] && sh /etc/rc.devfs
401 # Do traditional (but rather obsolete) rc.local file if it exists. If you
402 # use this file and want to make it programmatic, source /etc/rc.conf in
403 # /etc/rc.local and add your custom variables to /etc/rc.conf.local, as
404 # shown below. Please do not put local extensions into /etc/rc itself.
408 # if [ -f /etc/rc.conf ]; then
412 # ... additional startup conditionals ...
416 # Do traditional rc.local file if it exists.
419 if [ -f $conf_dir/rc.local ]; then
420 echo -n 'starting local daemons:'
421 sh $conf_dir/rc.local
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.
427 if [ "X${kern_securelevel_enable}" = X"YES" -a "${kern_securelevel}" -ge 0 ];
429 echo 'Raising kernel security level'
430 sysctl -w kern.securelevel=${kern_securelevel}