xref: /freebsd/libexec/rc/rc.d/var (revision d0b2dbfa)
10696600cSBjoern A. Zeeb#!/bin/sh
20696600cSBjoern A. Zeeb#
30696600cSBjoern A. Zeeb# Copyright (c) 1999  Matt Dillon
40696600cSBjoern A. Zeeb# All rights reserved.
50696600cSBjoern A. Zeeb#
60696600cSBjoern A. Zeeb# Redistribution and use in source and binary forms, with or without
70696600cSBjoern A. Zeeb# modification, are permitted provided that the following conditions
80696600cSBjoern A. Zeeb# are met:
90696600cSBjoern A. Zeeb# 1. Redistributions of source code must retain the above copyright
100696600cSBjoern A. Zeeb#    notice, this list of conditions and the following disclaimer.
110696600cSBjoern A. Zeeb# 2. Redistributions in binary form must reproduce the above copyright
120696600cSBjoern A. Zeeb#    notice, this list of conditions and the following disclaimer in the
130696600cSBjoern A. Zeeb#    documentation and/or other materials provided with the distribution.
140696600cSBjoern A. Zeeb#
150696600cSBjoern A. Zeeb# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
160696600cSBjoern A. Zeeb# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
170696600cSBjoern A. Zeeb# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
180696600cSBjoern A. Zeeb# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
190696600cSBjoern A. Zeeb# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
200696600cSBjoern A. Zeeb# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
210696600cSBjoern A. Zeeb# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
220696600cSBjoern A. Zeeb# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
230696600cSBjoern A. Zeeb# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
240696600cSBjoern A. Zeeb# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
250696600cSBjoern A. Zeeb# SUCH DAMAGE.
260696600cSBjoern A. Zeeb#
270696600cSBjoern A. Zeeb#
280696600cSBjoern A. Zeeb
290696600cSBjoern A. Zeeb# PROVIDE: var
300696600cSBjoern A. Zeeb# REQUIRE: mountcritlocal
310696600cSBjoern A. Zeeb
320696600cSBjoern A. Zeeb# NFS /var is not supported, unless NFS /var is part of diskless NFS /
330696600cSBjoern A. Zeeb
340696600cSBjoern A. Zeeb. /etc/rc.subr
350696600cSBjoern A. Zeeb
360696600cSBjoern A. Zeebname="var"
370696600cSBjoern A. Zeebdesc="Populate /var directory"
380696600cSBjoern A. Zeebstop_cmd=':'
390696600cSBjoern A. Zeeb
400696600cSBjoern A. Zeebload_rc_config $name
410696600cSBjoern A. Zeeb
420696600cSBjoern A. Zeebpopulate_var()
430696600cSBjoern A. Zeeb{
440696600cSBjoern A. Zeeb	/usr/sbin/mtree -deiU -f /etc/mtree/BSD.var.dist -p /var > /dev/null
450696600cSBjoern A. Zeeb	case ${sendmail_enable} in
460696600cSBjoern A. Zeeb	[Nn][Oo][Nn][Ee])
470696600cSBjoern A. Zeeb		;;
480696600cSBjoern A. Zeeb	*)
490696600cSBjoern A. Zeeb		/usr/sbin/mtree -deiU -f /etc/mtree/BSD.sendmail.dist -p / > /dev/null
500696600cSBjoern A. Zeeb		;;
510696600cSBjoern A. Zeeb	esac
520696600cSBjoern A. Zeeb}
530696600cSBjoern A. Zeeb
540696600cSBjoern A. Zeeb# If we do not have a writable /var, create a memory filesystem for /var
550696600cSBjoern A. Zeeb# unless told otherwise by rc.conf.  We don't have /usr yet so use mkdir
560696600cSBjoern A. Zeeb# instead of touch to test.  We want mount to record its mounts so we
570696600cSBjoern A. Zeeb# have to make sure /var/db exists before doing the mount -a.
580696600cSBjoern A. Zeeb#
590696600cSBjoern A. Zeebcase "${varmfs}" in
600696600cSBjoern A. Zeeb[Yy][Ee][Ss])
610696600cSBjoern A. Zeeb	mount_md ${varsize} /var "${varmfs_flags}"
620696600cSBjoern A. Zeeb	;;
630696600cSBjoern A. Zeeb[Nn][Oo])
640696600cSBjoern A. Zeeb	;;
650696600cSBjoern A. Zeeb*)
660696600cSBjoern A. Zeeb	if /bin/mkdir -p /var/.diskless 2> /dev/null; then
670696600cSBjoern A. Zeeb		rmdir /var/.diskless
680696600cSBjoern A. Zeeb	else
690696600cSBjoern A. Zeeb		mount_md ${varsize} /var "${varmfs_flags}"
700696600cSBjoern A. Zeeb	fi
710696600cSBjoern A. Zeebesac
720696600cSBjoern A. Zeeb
730696600cSBjoern A. Zeeb
740696600cSBjoern A. Zeeb# If we have an empty looking /var, populate it, but only if we have
750696600cSBjoern A. Zeeb# /usr available.  Hopefully, we'll eventually find a workaround, but
760696600cSBjoern A. Zeeb# in realistic diskless setups, we're probably ok.
770696600cSBjoern A. Zeebcase "${populate_var}" in
780696600cSBjoern A. Zeeb[Yy][Ee][Ss])
790696600cSBjoern A. Zeeb	populate_var
800696600cSBjoern A. Zeeb	;;
810696600cSBjoern A. Zeeb[Nn][Oo])
820696600cSBjoern A. Zeeb	exit 0
830696600cSBjoern A. Zeeb	;;
840696600cSBjoern A. Zeeb*)
850696600cSBjoern A. Zeeb	if [ -d /var/run -a -d /var/db -a -d /var/empty ] ; then
860696600cSBjoern A. Zeeb		true
870696600cSBjoern A. Zeeb	elif [ -x /usr/sbin/mtree ] ; then
880696600cSBjoern A. Zeeb		populate_var
890696600cSBjoern A. Zeeb	else
900696600cSBjoern A. Zeeb		# We need mtree to populate /var so try mounting /usr.
910696600cSBjoern A. Zeeb		# If this does not work, we can not boot so it is OK to
920696600cSBjoern A. Zeeb		# try to mount out of order.
930696600cSBjoern A. Zeeb		mount /usr
940696600cSBjoern A. Zeeb		if [ ! -x /usr/sbin/mtree ] ; then
950696600cSBjoern A. Zeeb			exit 1
960696600cSBjoern A. Zeeb		else
970696600cSBjoern A. Zeeb			populate_var
980696600cSBjoern A. Zeeb		fi
990696600cSBjoern A. Zeeb	fi
1000696600cSBjoern A. Zeeb	;;
1010696600cSBjoern A. Zeebesac
1020696600cSBjoern A. Zeeb
1030696600cSBjoern A. Zeeb# Make sure we have /var/log/utx.lastlogin and /var/log/utx.log files
1040696600cSBjoern A. Zeebif [ ! -f /var/log/utx.lastlogin ]; then
1050696600cSBjoern A. Zeeb	cp /dev/null /var/log/utx.lastlogin
1060696600cSBjoern A. Zeeb	chmod 644 /var/log/utx.lastlogin
1070696600cSBjoern A. Zeebfi
1080696600cSBjoern A. Zeebif [ ! -f /var/log/utx.log ]; then
1090696600cSBjoern A. Zeeb	cp /dev/null /var/log/utx.log
1100696600cSBjoern A. Zeeb	chmod 644 /var/log/utx.log
1110696600cSBjoern A. Zeebfi
112