mirror_zfs/etc/init.d/zfs-mount.in
James Lee 3f1cc17c90 Reorder zfs-* services to allow /var on separate dataset
ZED depends on /var.  When /var is a separate dataset, it must be
mounted before starting ZED.  This change moves the zfs-zed service
from starting first, to starting after zfs-mount, but before zfs-share.

As discussed in issue #3513, ZED does not need to start first in order
to consume events made during the zfs-import and zfs-mount services.
The events will be queued and can be handled later in the boot process.

ZED may, however, handle sharing in the future, so it should be started
before the zfs-share service.

This commit also stops the zfs-import service from writing temp files
to /var/tmp on shutdown and it corrects the return code for the OpenRC
service.

Other OpenRC-specific changes noted in issue #3513 were reitereated in
issue #3715 and committed in da619f3.

Signed-off-by: James Lee <jlee@thestaticvoid.com>
Signed-off-by: Richard Yao <ryao@gentoo.org>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #3513
2015-09-02 09:16:39 -07:00

236 lines
5.4 KiB
Plaintext
Executable File

#!@SHELL@
#
# zfs-mount This script will mount/umount the zfs filesystems.
#
# chkconfig: 2345 06 99
# description: This script will mount/umount the zfs filesystems during
# system boot/shutdown. Configuration of which filesystems
# should be mounted is handled by the zfs 'mountpoint' and
# 'canmount' properties. See the zfs(8) man page for details.
# It is also responsible for all userspace zfs services.
# probe: true
#
### BEGIN INIT INFO
# Provides: zfs-mount
# Required-Start: $local_fs zfs-import
# Required-Stop: $local_fs zfs-import
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# X-Stop-After: zfs-zed
# Short-Description: Mount ZFS filesystems and volumes
# Description: Run the `zfs mount -a` or `zfs umount -a` commands.
### END INIT INFO
#
# Released under the 2-clause BSD license.
#
# The original script that acted as a template for this script came from
# the Debian GNU/Linux kFreeBSD ZFS packages (which did not include a
# licensing stansa) in the commit dated Mar 24, 2011:
# https://github.com/zfsonlinux/pkg-zfs/commit/80a3ae582b59c0250d7912ba794dca9e669e605a
# Source the common init script
. @sysconfdir@/zfs/zfs-functions
# ----------------------------------------------------
chkroot() {
while read line; do
set -- $line
if [ "$2" = "/" ]; then
return 0
fi
done < /etc/mtab
return 1
}
do_depend()
{
# Try to allow people to mix and match fstab with ZFS in a way that makes sense.
if [ "$(mountinfo -s /)" = 'zfs' ]
then
before localmount
else
after localmount
fi
# bootmisc will log to /var which may be a different zfs than root.
before bootmisc logger
after zfs-import sysfs
use mtab
keyword -lxc -openvz -prefix -vserver
}
# Mount all datasets/filesystems
do_mount()
{
local verbose overlay i mntpt val
[ "$VERBOSE_MOUNT" = 'yes' ] && verbose=v
[ "$OVERLAY_MOUNTS" = 'yes' ] && overlay=O
zfs_action "Mounting ZFS filesystem(s)" \
"$ZFS" mount -a$verbose$overlay "$MOUNT_EXTRA_OPTIONS"
# Require each volume/filesytem to have 'noauto' and no fsck
# option. This shouldn't really be necessary, as long as one
# can get zfs-import to run sufficiently early on in the boot
# process - before local mounts. This is just here in case/if
# this isn't possible.
[ "$VERBOSE_MOUNT" = 'yes' ] && \
zfs_log_begin_msg "Mounting volumes and filesystems registered in fstab"
read_mtab "^/dev/(zd|zvol)"
read_fstab "^/dev/(zd|zvol)"
i=0; var=$(eval echo FSTAB_$i)
while [ -n "$(eval echo "$""$var")" ]
do
mntpt=$(eval echo "$""$var")
dev=$(eval echo "$"FSTAB_dev_$i)
if ! in_mtab "$mntpt" && ! is_mounted "$mntpt" && [ -e "$dev" ]
then
[ "$VERBOSE_MOUNT" = 'yes' ] && \
zfs_log_progress_msg "$mntpt "
fsck "$dev" && mount "$mntpt"
fi
i=$((i + 1))
var=$(eval echo FSTAB_$i)
done
read_mtab "[[:space:]]zfs[[:space:]]"
read_fstab "[[:space:]]zfs[[:space:]]"
i=0; var=$(eval echo FSTAB_$i)
while [ -n "$(eval echo "$""$var")" ]
do
mntpt=$(eval echo "$""$var")
if ! in_mtab "$mntpt" && ! is_mounted "$mntpt"
then
[ "$VERBOSE_MOUNT" = 'yes' ] && \
zfs_log_progress_msg "$mntpt "
mount "$mntpt"
fi
i=$((i + 1))
var=$(eval echo FSTAB_$i)
done
[ "$VERBOSE_MOUNT" = 'yes' ] && zfs_log_end_msg 0
return 0
}
# Unmount all filesystems
do_unmount()
{
local i var mntpt
# This shouldn't really be necessary, as long as one can get
# zfs-import to run sufficiently late in the shutdown/reboot process
# - after unmounting local filesystems. This is just here in case/if
# this isn't possible.
zfs_action "Unmounting ZFS filesystems" "$ZFS" unmount -a
[ "$VERBOSE_MOUNT" = 'yes' ] && \
zfs_log_begin_msg "Unmounting volumes and filesystems registered in fstab"
read_mtab "^/dev/(zd|zvol)"
read_fstab "^/dev/(zd|zvol)"
i=0; var=$(eval echo FSTAB_$i)
while [ -n "$(eval echo "$""$var")" ]
do
mntpt=$(eval echo "$""$var")
dev=$(eval echo "$"FSTAB_dev_$i)
if in_mtab "$mntpt"
then
[ "$VERBOSE_MOUNT" = 'yes' ] && \
zfs_log_progress_msg "$mntpt "
umount "$mntpt"
fi
i=$((i + 1))
var=$(eval echo FSTAB_$i)
done
read_mtab "[[:space:]]zfs[[:space:]]"
read_fstab "[[:space:]]zfs[[:space:]]"
i=0; var=$(eval echo FSTAB_$i)
while [ -n "$(eval echo "$""$var")" ]
do
mntpt=$(eval echo "$""$var")
if in_mtab "$mntpt"; then
[ "$VERBOSE_MOUNT" = 'yes' ] && \
zfs_log_progress_msg "$mntpt "
umount "$mntpt"
fi
i=$((i + 1))
var=$(eval echo FSTAB_$i)
done
[ "$VERBOSE_MOUNT" = 'yes' ] && zfs_log_end_msg 0
return 0
}
do_start()
{
check_module_loaded "zfs" || exit 0
case "$ZFS_MOUNT" in
[Oo][Ff][Ff]|[Nn][Oo]|''|0)
exit 3
;;
esac
# Ensure / exists in /etc/mtab, if not update mtab accordingly.
# This should be handled by rc.sysinit but lets be paranoid.
if ! chkroot
then
mount -f /
fi
do_mount
}
do_stop()
{
case "$ZFS_UNMOUNT" in
[Oo][Ff][Ff]|[Nn][Oo]|''|0)
exit 0
;;
esac
check_module_loaded "zfs" || exit 0
do_unmount
}
# ----------------------------------------------------
if [ ! -e /etc/gentoo-release ]
then
case "$1" in
start)
do_start
;;
stop)
do_stop
;;
force-reload|condrestart|reload|restart|status)
# no-op
;;
*)
[ -n "$1" ] && echo "Error: Unknown command $1."
echo "Usage: $0 {start|stop}"
exit 3
;;
esac
exit $?
else
# Create wrapper functions since Gentoo don't use the case part.
depend() { do_depend; }
start() { do_start; }
stop() { do_stop; }
fi