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