mirror_zfs/etc/init.d/zfs.redhat.in
Brian Behlendorf a7b9d0c3a0 Replace zfs.redhat.in with zfs.lsb.in init script
This commit replaces the zfs.redhat.in init script with a slightly
modified version of the existing zfs.lsb.in init script.  This was
done to minimize the functional differences between platforms.
The lsb version of the script was choosen because it's heavily
tested and provides the most functionality.

Changes made for RHEL systems:
* Configuration: /etc/default/zfs -> /etc/sysconfig/zfs
* LSB functions: /lib/lsb/init-functions -> /etc/rc.d/init.d/functions
* Logging: log_begin_msg/log_end_msg -> action

Features in LSB which are now in RHEL:
* USE_DISK_BY_ID=0      - Use the by-id names
* VERBOSE_MOUNT=0       - Verbose mounts by default
* DO_OVERLAY_MOUNTS=0   - Overlay mounts by default
* MOUNT_EXTRA_OPTIONS=0 - Generic extra options

Existing RHEL features which were removed:
* Automatically mounting FSs on ZVOLs listed in /etc/fstab

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Issue #3153
2015-03-04 11:33:07 -08:00

145 lines
3.1 KiB
Bash

#!/bin/bash
#
# zfs This script will mount/umount the zfs filesystems.
#
# chkconfig: 2345 01 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.
#
### BEGIN INIT INFO
# Provides: zfs
# Required-Start: $local_fs
# Required-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Should-Stop:
# Short-Description: Mount/umount the zfs filesystems
# Description: ZFS is an advanced filesystem designed to simplify managing
# and protecting your data. This service mounts the ZFS
# filesystems and starts all related zfs services.
### END INIT INFO
# Source function library.
. /etc/rc.d/init.d/functions
LOCKFILE=/var/lock/zfs
ZFS="@sbindir@/zfs"
ZPOOL="@sbindir@/zpool"
ZPOOL_CACHE="/etc/zfs/zpool.cache"
USE_DISK_BY_ID=0
VERBOSE_MOUNT=0
DO_OVERLAY_MOUNTS=0
MOUNT_EXTRA_OPTIONS=""
# Source zfs configuration.
[ -r '/etc/sysconfig/zfs' ] && . /etc/default/zfs
[ -x "$ZPOOL" ] || exit 1
[ -x "$ZFS" ] || exit 2
if [ -z "$init" ]; then
# Not interactive
grep -qE '(^|[^\\](\\\\)* )zfs=(off|no)( |$)' /proc/cmdline && exit 3
fi
start()
{
[ -f "$LOCKFILE" ] && return 3
# Delay until all required block devices are present.
udevadm settle
# Load the zfs module stack
/sbin/modprobe zfs
# Ensure / exists in /etc/mtab, if not update mtab accordingly.
# This should be handled by rc.sysinit but lets be paranoid.
awk '$2 == "/" { exit 1 }' /etc/mtab
RETVAL=$?
if [ "$RETVAL" -eq 0 ]; then
/bin/mount -f /
fi
# Import all pools described by the cache file, and then mount
# all filesystem based on their properties.
if [ "$USE_DISK_BY_ID" -eq 1 ]; then
action $"Importing ZFS pools" \
"$ZPOOL" import -d /dev/disk/by-id -aN 2>/dev/null
ret=$?
[ "$ret" -eq 0 ] && POOL_IMPORTED=1
elif [ -f "$ZPOOL_CACHE" ] ; then
action $"Importing ZFS pools" \
"$ZPOOL" import -c "$ZPOOL_CACHE" -aN 2>/dev/null
ret=$?
[ "$ret" -eq 0 ] && POOL_IMPORTED=1
fi
if [ -n "$POOL_IMPORTED" ]; then
if [ "$VERBOSE_MOUNT" -eq 1 ]; then
verbose=v
fi
if [ "$DO_OVERLAY_MOUNTS" -eq 1 ]; then
overlay=O
fi
action $"Mounting ZFS filesystems" \
"$ZFS" mount -a$verbose$overlay$MOUNT_EXTRA_OPTIONS
action $"Sharing ZFS filesystems" \
"$ZFS" share -a
fi
touch "$LOCKFILE"
}
stop()
{
[ ! -f "$LOCKFILE" ] && return 3
action $"Unsharing ZFS filesystems" "$ZFS" unshare -a
action $"Unmounting ZFS filesystems" "$ZFS" umount -a
rm -f "$LOCKFILE"
}
status()
{
[ ! -f "$LOCKFILE" ] && return 3
"$ZPOOL" status && echo "" && "$ZPOOL" list
}
case "$1" in
start)
start
RETVAL=$?
;;
stop)
stop
RETVAL=$?
;;
status)
status
RETVAL=$?
;;
restart)
stop
start
;;
condrestart)
if [ -f "$LOCKFILE" ]; then
stop
start
fi
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart}"
;;
esac
exit $RETVAL