2011-05-02 22:39:59 +00:00
|
|
|
#!/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
|
2015-03-04 19:09:17 +00:00
|
|
|
# Required-Start: $local_fs
|
|
|
|
# Required-Stop: $local_fs
|
|
|
|
# Default-Start: 2 3 4 5
|
|
|
|
# Default-Stop: 0 1 6
|
2011-05-02 22:39:59 +00:00
|
|
|
# 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
|
|
|
|
|
2015-03-04 19:09:17 +00:00
|
|
|
# Source function library.
|
2011-05-02 22:39:59 +00:00
|
|
|
. /etc/rc.d/init.d/functions
|
|
|
|
|
2015-03-04 19:09:17 +00:00
|
|
|
LOCKFILE=/var/lock/zfs
|
2015-03-05 21:11:05 +00:00
|
|
|
ZED="@sbindir@/zed"
|
|
|
|
ZED_PIDFILE="@runstatedir@/zed.pid"
|
2011-07-25 00:00:53 +00:00
|
|
|
ZFS="@sbindir@/zfs"
|
|
|
|
ZPOOL="@sbindir@/zpool"
|
2015-03-04 19:09:17 +00:00
|
|
|
ZPOOL_CACHE="/etc/zfs/zpool.cache"
|
|
|
|
USE_DISK_BY_ID=0
|
|
|
|
VERBOSE_MOUNT=0
|
|
|
|
DO_OVERLAY_MOUNTS=0
|
|
|
|
MOUNT_EXTRA_OPTIONS=""
|
2011-05-02 22:39:59 +00:00
|
|
|
|
2015-03-04 19:09:17 +00:00
|
|
|
# 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
|
2011-05-02 22:39:59 +00:00
|
|
|
|
|
|
|
start()
|
|
|
|
{
|
2015-03-04 19:09:17 +00:00
|
|
|
[ -f "$LOCKFILE" ] && return 3
|
2011-05-02 22:39:59 +00:00
|
|
|
|
2011-06-30 21:45:33 +00:00
|
|
|
# Delay until all required block devices are present.
|
2015-03-04 19:09:17 +00:00
|
|
|
udevadm settle
|
|
|
|
|
|
|
|
# Load the zfs module stack
|
|
|
|
/sbin/modprobe zfs
|
|
|
|
|
2015-03-05 21:11:05 +00:00
|
|
|
# Start the ZED for event handling
|
|
|
|
action $"Starting ZFS Event Daemon" daemon --pidfile="$ZED_PIDFILE" "$ZED"
|
|
|
|
|
2015-03-04 19:09:17 +00:00
|
|
|
# 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 /
|
2011-07-07 07:22:19 +00:00
|
|
|
fi
|
2011-06-30 21:45:33 +00:00
|
|
|
|
2015-03-04 19:09:17 +00:00
|
|
|
# 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
|
2011-05-02 22:39:59 +00:00
|
|
|
fi
|
|
|
|
|
2015-03-04 19:09:17 +00:00
|
|
|
if [ -n "$POOL_IMPORTED" ]; then
|
|
|
|
if [ "$VERBOSE_MOUNT" -eq 1 ]; then
|
|
|
|
verbose=v
|
|
|
|
fi
|
2011-05-02 22:39:59 +00:00
|
|
|
|
2015-03-04 19:09:17 +00:00
|
|
|
if [ "$DO_OVERLAY_MOUNTS" -eq 1 ]; then
|
|
|
|
overlay=O
|
|
|
|
fi
|
|
|
|
|
|
|
|
action $"Mounting ZFS filesystems" \
|
|
|
|
"$ZFS" mount -a$verbose$overlay$MOUNT_EXTRA_OPTIONS
|
2011-07-03 00:43:25 +00:00
|
|
|
|
2015-03-04 19:09:17 +00:00
|
|
|
action $"Sharing ZFS filesystems" \
|
|
|
|
"$ZFS" share -a
|
|
|
|
fi
|
2011-05-02 22:39:59 +00:00
|
|
|
|
2015-03-04 19:09:17 +00:00
|
|
|
touch "$LOCKFILE"
|
2011-05-02 22:39:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
stop()
|
|
|
|
{
|
2015-03-04 19:09:17 +00:00
|
|
|
[ ! -f "$LOCKFILE" ] && return 3
|
|
|
|
|
|
|
|
action $"Unsharing ZFS filesystems" "$ZFS" unshare -a
|
|
|
|
action $"Unmounting ZFS filesystems" "$ZFS" umount -a
|
2015-03-05 21:11:05 +00:00
|
|
|
action $"Shutting down ZFS Event Daemon" killproc -p "$ZED_PIDFILE" "$ZED"
|
2011-05-02 22:39:59 +00:00
|
|
|
|
|
|
|
rm -f "$LOCKFILE"
|
|
|
|
}
|
|
|
|
|
2015-03-04 19:09:17 +00:00
|
|
|
status()
|
|
|
|
{
|
|
|
|
[ ! -f "$LOCKFILE" ] && return 3
|
|
|
|
|
|
|
|
"$ZPOOL" status && echo "" && "$ZPOOL" list
|
|
|
|
}
|
|
|
|
|
2011-05-02 22:39:59 +00:00
|
|
|
case "$1" in
|
|
|
|
start)
|
|
|
|
start
|
|
|
|
RETVAL=$?
|
|
|
|
;;
|
|
|
|
stop)
|
|
|
|
stop
|
|
|
|
RETVAL=$?
|
|
|
|
;;
|
|
|
|
status)
|
2015-03-04 19:09:17 +00:00
|
|
|
status
|
|
|
|
RETVAL=$?
|
2011-05-02 22:39:59 +00:00
|
|
|
;;
|
|
|
|
restart)
|
|
|
|
stop
|
|
|
|
start
|
|
|
|
;;
|
|
|
|
condrestart)
|
2015-03-04 19:09:17 +00:00
|
|
|
if [ -f "$LOCKFILE" ]; then
|
2011-05-02 22:39:59 +00:00
|
|
|
stop
|
|
|
|
start
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo $"Usage: $0 {start|stop|status|restart|condrestart}"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
exit $RETVAL
|