Remove UUCP support. Note: /usr/src/gnu/libexec/uucp and /usr/src/libexec/uucpd
[dragonfly.git] / etc / rc
1 #!/bin/sh
2 #
3 # Copyright (c) 2000  The FreeBSD Project
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
9 # 1. Redistributions of source code must retain the above copyright
10 #    notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 #    notice, this list of conditions and the following disclaimer in the
13 #    documentation and/or other materials provided with the distribution.
14 #
15 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 # ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 # SUCH DAMAGE.
26 #
27 #       @(#)rc  5.27 (Berkeley) 6/5/91
28 # $FreeBSD: src/etc/rc,v 1.212.2.51 2002/10/17 17:25:07 schweikh Exp $
29 # $DragonFly: src/etc/rc,v 1.2 2003/06/17 04:24:45 dillon Exp $
30 #
31
32 # System startup script run by init on autoboot
33 # or after single-user.
34 # Output and error are redirected to console by init,
35 # and the console is the controlling terminal.
36
37 # Note that almost all of the user-configurable behavior is no longer in
38 # this file, but rather in /etc/defaults/rc.conf.  Please check that file
39 # first before contemplating any changes here.  If you do need to change
40 # this file for some reason, we would like to know about it.
41
42 stty status '^T'
43
44 # Set shell to ignore SIGINT (2), but not children;
45 # shell catches SIGQUIT (3) and returns to single user after fsck.
46 #
47 trap : 2
48 trap : 3        # shouldn't be needed
49
50 bootmode=$1
51
52 HOME=/
53 PATH=/sbin:/bin:/usr/sbin:/usr/bin
54 export HOME PATH
55
56 # BOOTP diskless boot.  We have to run the rc file early in order to
57 # retarget various config files.
58 # See /usr/share/examples/diskless/clone_root for details on how
59 # to setup diskless on the client and the server.
60 #
61 if [ -r /etc/rc.diskless1 ]; then
62         dlv=`/sbin/sysctl -n vfs.nfs.diskless_valid 2> /dev/null`
63         if [ ${dlv:=0} != 0 ]; then
64                 . /etc/rc.diskless1
65         fi
66 fi
67
68 # If there is a global system configuration file, suck it in.
69 #
70 if [ -r /etc/defaults/rc.conf ]; then
71         . /etc/defaults/rc.conf
72         source_rc_confs
73 elif [ -r /etc/rc.conf ]; then
74         . /etc/rc.conf
75 fi
76
77 chkdepend() {
78         svc=$1
79         svc_var=$2
80         dep=$3
81         dep_var=$4
82
83         eval svc_val=\${$svc_var}
84         eval dep_val=\${$dep_var}
85
86         case ${svc_val} in
87         [Yy][Ee][Ss])
88                 case ${dep_val} in
89                 [Yy][Ee][Ss])
90                         ;;
91                 *)
92                         eval ${dep_var}="YES"
93                         echo "DEPENDENCY NOTE: ${dep} will be enabled" \
94                                 "to support ${svc}"
95                         ;;
96                 esac
97                 ;;
98         esac
99 }
100
101 chkdepend amd amd_enable        portmap portmap_enable
102 chkdepend amd amd_enable        NFS nfs_client_enable
103 chkdepend NFS nfs_server_enable portmap portmap_enable
104 chkdepend NIS nis_server_enable portmap portmap_enable
105 chkdepend NIS nis_client_enable portmap portmap_enable
106
107 # Enable dumpdev early so that a crash during the boot process can be caught.
108 #
109 case ${dumpdev} in
110 [Nn][Oo] | '')
111         dumpdev='NO'
112         ;;
113 *)
114         /sbin/dumpon -v ${dumpdev}
115         ;;
116 esac
117
118 # Configure ccd devices.
119 #
120 if [ -r /etc/ccd.conf ]; then
121         ccdconfig -C
122 fi
123
124 case ${start_vinum} in
125 [Yy][Ee][Ss])
126         vinum start
127         ;;
128 esac
129
130 swapon -a
131
132 # Last chance to do things before potentially waiting for
133 # operator to do fsck related tasks
134 if [ -r /etc/rc.early ]; then
135         . /etc/rc.early
136 fi
137
138 case ${bootmode} in
139 autoboot)
140         echo 'Automatic boot in progress...'
141         fsck -p
142         case $? in
143         0)
144                 ;;
145         2)
146                 exit 1
147                 ;;
148         4)
149                 reboot
150                 echo 'Reboot failed... help!'
151                 exit 1
152                 ;;
153         8)
154                 case ${fsck_y_enable} in
155                 [Yy][Ee][Ss])
156                         echo 'File system preen failed, trying fsck -y . . .'
157                         fsck -y
158                         case $? in
159                         0)
160                                 ;;
161                         *)
162                         echo 'Automatic file system check failed . . . help!'
163                                 exit 1
164                                 ;;
165                         esac
166                         ;;
167                 *)
168                         echo 'Automatic file system check failed . . . help!'
169                         exit 1
170                         ;;
171                 esac
172                 ;;
173         12)
174                 echo 'Reboot interrupted'
175                 exit 1
176                 ;;
177         130)
178                 # interrupt before catcher installed
179                 exit 1
180                 ;;
181         *)
182                 echo 'Unknown error in reboot'
183                 exit 1
184                 ;;
185         esac
186         ;;
187 *)
188         echo 'Skipping disk checks ...'
189         ;;
190 esac
191
192 set -T
193 trap "echo 'Reboot interrupted'; exit 1" 3
194
195 # root normally must be read/write, but if this is a BOOTP NFS
196 # diskless boot it does not have to be.
197 #
198 case ${root_rw_mount} in
199 [Nn][Oo] | '')
200         ;;
201 *)
202         if ! mount -u -o rw /; then
203                 echo 'Mounting root filesystem rw failed, startup aborted'
204                 exit 1
205         fi
206         ;;
207 esac
208
209 umount -a >/dev/null 2>&1
210
211 # If using diskless, run custom disk mounting function here
212 #
213 if [ -n "${diskless_mount}" -a -r "${diskless_mount}" ]; then
214         sh ${diskless_mount}
215 else
216 # otherwise mount everything except nfs filesystems.
217         mount -a -t nonfs
218 fi
219
220 case $? in
221 0)
222         ;;
223 *)
224         echo 'Mounting /etc/fstab filesystems failed, startup aborted'
225         exit 1
226         ;;
227 esac
228
229 adjkerntz -i
230
231 purgedir() {
232         local dir file
233
234         if [ $# -eq 0 ]; then
235                 purgedir .
236         else
237                 for dir
238                 do
239                 (
240                         cd "$dir" && for file in .* *
241                         do
242                                 [ ."$file" = .. -o ."$file" = ... ] && continue
243                                 if [ -d "$file" -a ! -L "$file" ]; then
244                                         purgedir "$file"
245                                 else
246                                         rm -f -- "$file"
247                                 fi
248                         done
249                 )
250                 done
251         fi
252 }
253
254 clean_var() {
255         if [ -d /var/run -a ! -f /var/run/clean_var ]; then
256                 purgedir /var/run
257                 # Keep a copy of the boot messages around
258                 dmesg >/var/run/dmesg.boot
259                 # And an initial utmp file
260                 (cd /var/run && cp /dev/null utmp && chmod 644 utmp;)
261                 >/var/run/clean_var
262         fi
263         if [ -d /var/spool/lock -a ! -f /var/spool/lock/clean_var ]; then
264                 purgedir /var/spool/lock
265                 >/var/spool/lock/clean_var
266         fi
267         rm -rf /var/spool/uucp/.Temp/*
268 }
269
270 # network_pass1() *may* end up writing stuff to /var - we don't want to
271 # remove it immediately afterwards - *nor* do we want to fail to clean
272 # an NFS-mounted /var.
273 rm -f /var/run/clean_var /var/spool/lock/clean_var
274 clean_var
275
276 # Add additional swapfile, if configured.
277 #
278 case ${swapfile} in
279 [Nn][Oo] | '')
280         ;;
281 *)
282         if [ -w "${swapfile}" -a -c /dev/vn0b ]; then
283                 echo "Adding ${swapfile} as additional swap"
284                 vnconfig -e /dev/vn0b ${swapfile} swap
285         fi
286         ;;
287 esac
288
289 # Early pass to set the variables we can
290 #
291 if [ -r /etc/rc.sysctl ]; then
292         sh /etc/rc.sysctl first
293 fi
294
295 # Configure serial devices
296 #
297 if [ -r /etc/rc.serial ]; then
298         . /etc/rc.serial
299 fi
300
301 # Start up PC-card configuration
302 #
303 if [ -r /etc/rc.pccard ]; then
304         . /etc/rc.pccard
305 fi
306
307 # Start up the initial network configuration.
308 #
309 if [ -r /etc/rc.network ]; then
310         . /etc/rc.network       # We only need to do this once.
311         network_pass1
312 fi
313
314 case ${ipv6_enable} in
315 [Yy][Ee][Ss])
316         if [ -r /etc/rc.network6 ]; then
317                 . /etc/rc.network6      # We only need to do this once also.
318                 network6_pass1
319         fi
320         ;;
321 esac
322
323 # Mount NFS filesystems if present in /etc/fstab
324 #
325 case "`mount -d -a -t nfs 2> /dev/null`" in
326 *mount_nfs*)
327         echo -n 'Mounting NFS file systems:'
328         mount -a -t nfs
329         echo '.'
330         ;;
331 esac
332
333 # If we booted a special kernel remove the record so we will boot
334 # the default kernel next time
335 #
336 rm -f /boot/nextboot.conf
337
338 # Whack the pty perms back into shape.
339 #
340 if ls /dev/tty[pqrsPQRS]* > /dev/null 2>&1; then
341         chflags 0 /dev/tty[pqrsPQRS]*
342         chmod 666 /dev/tty[pqrsPQRS]*
343         chown root:wheel /dev/tty[pqrsPQRS]*
344 fi
345
346 # Clean up left-over files
347 #
348 clean_var                       # If it hasn't already been done
349 rm /var/run/clean_var /var/spool/lock/clean_var
350
351 # Clearing /tmp at boot-time seems to have a long tradition.  It doesn't
352 # help in any way for long-living systems, and it might accidentally
353 # clobber files you would rather like to have preserved after a crash
354 # (if not using mfs /tmp anyway).
355 #
356 # See also the example of another cleanup policy in /etc/periodic/daily.
357 #
358 case ${clear_tmp_enable} in
359 [Yy][Ee][Ss])
360         echo -n 'Clearing /tmp:'
361         # prune quickly with one rm, then use find to clean up /tmp/[lq]*
362         # (not needed with mfs /tmp, but doesn't hurt there...)
363         (cd /tmp && rm -rf [a-km-pr-zA-Z]* &&
364                 find -d . ! -name . ! -name lost+found ! -name quota.user \
365                 ! -name quota.group -exec rm -rf -- {} \;)
366         echo '.'
367         ;;
368 esac
369
370 # Remove X lock files, since they will prevent you from restarting X11
371 # after a system crash.
372 #
373 rm -f /tmp/.X*-lock
374 rm -fr /tmp/.X11-unix
375 mkdir -m 1777 /tmp/.X11-unix
376
377 # Snapshot any kernel -c changes back to disk here <someday>.
378 # This has changed with ELF and /kernel.config.
379
380 echo -n 'Additional daemons:'
381
382 # Start system logging and name service.  Named needs to start before syslogd
383 # if you don't have a /etc/resolv.conf.
384 #
385 case ${syslogd_enable} in
386 [Yy][Ee][Ss])
387         # Transitional symlink (for the next couple of years :) until all
388         # binaries have had a chance to move towards /var/run/log.
389         if [ ! -L /dev/log ]; then
390                 # might complain for r/o root f/s
391                 ln -sf /var/run/log /dev/log
392         fi
393
394         rm -f /var/run/log
395         echo -n ' syslogd';
396         ${syslogd_program:-/usr/sbin/syslogd} ${syslogd_flags}
397         ;;
398 esac
399
400 echo '.'
401
402 # Build devices database
403 #
404 dev_mkdb
405
406 # $dumpdir should be a directory or a symbolic link
407 # to the crash directory if core dumps are to be saved.
408 #
409 if [ "${dumpdev}" != 'NO' ]; then
410         case ${dumpdir} in
411         '')
412                 dumpdir='/var/crash'
413                 ;;
414         [Nn][Oo])
415                 dumpdir='NO'
416                 ;;
417         esac
418
419         if [ "${dumpdir}" != 'NO' ]; then
420                 echo -n 'Checking for core dump: '
421                 /sbin/savecore ${savecore_flags} "${dumpdir}"
422         fi
423 fi
424
425 if [ -n "${network_pass1_done}" ]; then
426         network_pass2
427 fi
428
429 # Enable/Check the quotas (must be after ypbind if using NIS)
430 #
431 case ${enable_quotas} in
432 [Yy][Ee][Ss])
433         case ${check_quotas} in
434         [Yy][Ee][Ss])
435                 echo -n 'Checking quotas:'
436                 quotacheck -a
437                 echo ' done.'
438                 ;;
439         esac
440
441         echo -n 'Enabling quotas:'
442         quotaon -a
443         echo ' done.'
444         ;;
445 esac
446
447 if [ -n "${network_pass2_done}" ]; then
448         network_pass3
449 fi
450
451 # Check the password temp/lock file
452 #
453 if [ -e /etc/ptmp ]; then
454         logger -s -p auth.err \
455         "password file may be incorrect -- /etc/ptmp exists"
456 fi
457
458 case ${accounting_enable} in
459 [Yy][Ee][Ss])
460         if [ -d /var/account ]; then
461                 echo 'Turning on accounting:'
462                 if [ ! -e /var/account/acct ]; then
463                         touch /var/account/acct
464                 fi
465                 accton /var/account/acct
466         fi
467         ;;
468 esac
469
470 # Make shared lib searching a little faster.  Leave /usr/lib first if you
471 # add your own entries or you may come to grief.
472 #
473 ldconfig="/sbin/ldconfig"
474 case ${ldconfig_insecure} in
475 [Yy][Ee][Ss])
476         ldconfig="${ldconfig} -i"
477         ;;
478 esac
479 if [ -x /sbin/ldconfig ]; then
480         case `/usr/bin/objformat` in
481         elf)
482                 _LDC=/usr/lib
483                 for i in ${ldconfig_paths}; do
484                         if [ -d "${i}" ]; then
485                                 _LDC="${_LDC} ${i}"
486                         fi
487                 done
488                 echo 'ELF ldconfig path:' ${_LDC}
489                 ${ldconfig} -elf ${_LDC}
490                 ;;
491         esac
492
493         # Legacy aout support for i386 only
494         case `sysctl -n hw.machine_arch` in
495         i386)
496                 # Default the a.out ldconfig path.
497                 : ${ldconfig_paths_aout=${ldconfig_paths}}
498                 _LDC=/usr/lib/aout
499                 for i in ${ldconfig_paths_aout}; do
500                         if [ -d "${i}" ]; then
501                                 _LDC="${_LDC} ${i}"
502                         fi
503                 done
504                 echo 'a.out ldconfig path:' ${_LDC}
505                 ${ldconfig} -aout ${_LDC}
506                 ;;
507         esac
508 fi
509
510 # Now start up miscellaneous daemons that don't belong anywhere else
511 #
512 echo -n 'Starting standard daemons:'
513 case ${inetd_enable} in
514 [Nn][Oo])
515         ;;
516 *)
517         echo -n ' inetd'; ${inetd_program:-/usr/sbin/inetd} ${inetd_flags}
518         ;;
519 esac
520
521 case ${cron_enable} in
522 [Nn][Oo])
523         ;;
524 *)
525         echo -n ' cron';        ${cron_program:-/usr/sbin/cron} ${cron_flags}
526         ;;
527 esac
528
529 case ${lpd_enable} in
530 [Yy][Ee][Ss])
531         echo -n ' printer';     ${lpd_program:-/usr/sbin/lpd} ${lpd_flags}
532         ;;
533 esac
534
535 case ${sshd_enable} in
536 [Yy][Ee][Ss])
537         if [ -x ${sshd_program:-/usr/sbin/sshd} ]; then
538                 echo -n ' sshd';
539                 ${sshd_program:-/usr/sbin/sshd} ${sshd_flags}
540         fi
541         ;;
542 esac
543
544 case ${usbd_enable} in
545 [Yy][Ee][Ss])
546         echo -n ' usbd';        /usr/sbin/usbd ${usbd_flags}
547         ;;
548 esac
549
550 case ${mta_start_script} in
551 /*)
552         if [ -r ${mta_start_script} ]; then
553                 sh ${mta_start_script}
554         fi
555         ;;
556 esac
557
558 echo '.'
559
560 # Recover vi editor files.
561 find /var/tmp/vi.recover ! -type f -a ! -type d -delete
562 vibackup=`echo /var/tmp/vi.recover/vi.*`
563 if [ "${vibackup}" != '/var/tmp/vi.recover/vi.*' ]; then
564         echo -n 'Recovering vi editor sessions:'
565         for i in /var/tmp/vi.recover/vi.*; do
566                 # Only test files that are readable.
567                 if [ ! -r "${i}" ]; then
568                         continue
569                 fi
570
571                 # Unmodified nvi editor backup files either have the
572                 # execute bit set or are zero length.  Delete them.
573                 if [ -x "${i}" -o ! -s "${i}" ]; then
574                         rm -f "${i}"
575                 fi
576         done
577
578         # It is possible to get incomplete recovery files, if the editor
579         # crashes at the right time.
580         virecovery=`echo /var/tmp/vi.recover/recover.*`
581         if [ "${virecovery}" != "/var/tmp/vi.recover/recover.*" ]; then
582                 for i in /var/tmp/vi.recover/recover.*; do
583                         # Only test files that are readable.
584                         if [ ! -r "${i}" ]; then
585                                 continue
586                         fi
587
588                         # Delete any recovery files that are zero length,
589                         # corrupted, or that have no corresponding backup file.
590                         # Else send mail to the user.
591                         recfile=`awk '/^X-vi-recover-path:/{print $2}' < "${i}"`
592                         if [ -n "${recfile}" -a -s "${recfile}" ]; then
593                                 sendmail -t < "${i}"
594                         else
595                                 rm -f "${i}"
596                         fi
597                 done
598         fi
599         echo '.'
600 fi
601
602 # Make a bounds file for msgs(1) if there isn't one already
603 #
604 if [ -d /var/msgs -a ! -f /var/msgs/bounds -a ! -L /var/msgs/bounds ]; then
605         echo 0 > /var/msgs/bounds
606 fi
607
608 case ${update_motd} in
609 [Nn][Oo] | '')
610         ;;
611 *)
612         if T=`mktemp /tmp/_motd.XXXXXX`; then
613                 uname -v | sed -e 's,^\([^#]*\) #\(.* [1-2][0-9][0-9][0-9]\).*/\([^\]*\) $,\1 (\3) #\2,' > ${T}
614                 awk '{if (NR == 1) {if ($1 == "FreeBSD") {next} else {print "\n"$0}} else {print}}' < /etc/motd >> ${T}
615                 cmp -s ${T} /etc/motd || {
616                         cp ${T} /etc/motd
617                         chmod 644 /etc/motd
618                 }
619                 rm -f ${T}
620         fi
621         ;;
622 esac
623
624 # Configure implementation specific stuff
625 #
626 arch=`uname -p`
627 if [ -r /etc/rc.${arch} ]; then
628         . /etc/rc.${arch}
629 fi
630
631 # Configure the system console
632 #
633 if [ -r /etc/rc.syscons ]; then
634         . /etc/rc.syscons
635 fi
636
637 echo -n 'Additional ABI support:'
638
639 # Start the Linux binary compatibility if requested.
640 #
641 case ${linux_enable} in
642 [Yy][Ee][Ss])
643         echo -n ' linux'
644         if ! kldstat -v | grep -E 'linux(aout|elf)' > /dev/null; then
645                 kldload linux > /dev/null 2>&1
646         fi
647         if [ -x /compat/linux/sbin/ldconfig ]; then
648                 /compat/linux/sbin/ldconfig
649         fi
650         ;;
651 esac
652
653 # Start the SysVR4 binary emulation if requested.
654 #
655 case ${svr4_enable} in
656 [Yy][Ee][Ss])
657         echo -n ' svr4';
658         kldload streams > /dev/null 2>&1
659         kldload svr4 > /dev/null 2>&1
660         ;;
661 esac
662
663 echo '.'
664
665 # Do traditional (but rather obsolete) rc.local file if it exists.  If you
666 # use this file and want to make it programmatic, source /etc/defaults/rc.conf
667 # in /etc/rc.local and add your custom variables to /etc/rc.conf, as
668 # shown below.  Please do not put local extensions into /etc/rc itself.
669 # Use /etc/rc.local
670 #
671 # ---- rc.local ----
672 #       if [ -r /etc/defaults/rc.conf ]; then
673 #               . /etc/defaults/rc.conf
674 #               source_rc_confs
675 #       elif [ -r /etc/rc.conf ]; then
676 #               . /etc/rc.conf
677 #       fi
678 #
679 #       ... additional startup conditionals ...
680 # ---- rc.local ----
681 #
682 if [ -r /etc/rc.local ]; then
683         echo -n 'Starting local daemons:'
684         sh /etc/rc.local
685         echo '.'
686 fi
687
688 # For each valid dir in $local_startup, search for init scripts matching *.sh
689 #
690 case ${local_startup} in
691 [Nn][Oo] | '')
692         ;;
693 *)
694         echo -n 'Local package initialization:'
695         slist=""
696         if [ -z "${script_name_sep}" ]; then
697                 script_name_sep=" "
698         fi
699         for dir in ${local_startup}; do
700                 if [ -d "${dir}" ]; then
701                         for script in ${dir}/*.sh; do
702                                 slist="${slist}${script_name_sep}${script}"
703                         done
704                 fi
705         done
706         script_save_sep="$IFS"
707         IFS="${script_name_sep}"
708         for script in ${slist}; do
709                 if [ -x "${script}" ]; then
710                         (set -T
711                         trap 'exit 1' 2
712                         ${script} start)
713                 elif [ -f "${script}" -o -L "${script}" ]; then
714                         echo -n " (skipping ${script##*/}, not executable)"
715                 fi
716         done
717         IFS="${script_save_sep}"
718         echo '.'
719         ;;
720 esac
721
722 if [ -n "${network_pass3_done}" ]; then
723         network_pass4
724 fi
725
726 # Late pass to set variables we missed the first time
727 #
728 if [ -r /etc/rc.sysctl ]; then
729         sh /etc/rc.sysctl last
730 fi
731
732 # Raise kernel security level.  This should be done only after `fsck' has
733 # repaired local file systems if you want the securelevel to be greater than 1.
734 #
735 case ${kern_securelevel_enable} in
736 [Yy][Ee][Ss])
737         if [ "${kern_securelevel}" -ge 0 ]; then
738                 echo 'Raising kernel security level: '
739                 sysctl kern.securelevel=${kern_securelevel}
740         fi
741         ;;
742 esac
743
744 echo ''
745
746 date
747
748 exit 0
749