2011-03-17 22:02:28 +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
|
|
|
|
# Required-Start: $local_fs
|
|
|
|
# Required-Stop: $local_fs
|
2011-04-20 00:45:21 +00:00
|
|
|
# Default-Start: 2 3 4 5
|
|
|
|
# Default-Stop: 0 1 6
|
2011-03-17 22:02:28 +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
|
|
|
|
|
|
|
|
# Source function library.
|
|
|
|
. /lib/lsb/init-functions
|
|
|
|
|
|
|
|
LOCKFILE=/var/lock/zfs
|
2011-07-25 00:00:53 +00:00
|
|
|
ZFS="@sbindir@/zfs"
|
|
|
|
ZPOOL="@sbindir@/zpool"
|
2011-08-22 22:58:54 +00:00
|
|
|
ZPOOL_CACHE="@sysconfdir@/zfs/zpool.cache"
|
2013-12-05 11:36:58 +00:00
|
|
|
USE_DISK_BY_ID=0
|
2011-03-17 22:02:28 +00:00
|
|
|
|
2011-12-04 20:18:28 +00:00
|
|
|
# Source zfs configuration.
|
2011-12-04 21:32:18 +00:00
|
|
|
[ -r '/etc/default/zfs' ] && . /etc/default/zfs
|
2011-12-04 20:18:28 +00:00
|
|
|
|
2011-12-04 21:32:18 +00:00
|
|
|
[ -x "$ZPOOL" ] || exit 1
|
|
|
|
[ -x "$ZFS" ] || exit 2
|
2011-03-17 22:02:28 +00:00
|
|
|
|
2013-04-14 15:41:51 +00:00
|
|
|
if [ -z "$init" ]; then
|
|
|
|
# Not interactive
|
2013-11-06 22:56:50 +00:00
|
|
|
grep -qE '(^|[^\\](\\\\)* )zfs=(off|no)( |$)' /proc/cmdline && exit 3
|
2013-04-14 15:41:51 +00:00
|
|
|
fi
|
|
|
|
|
2011-03-17 22:02:28 +00:00
|
|
|
start()
|
|
|
|
{
|
2011-12-04 21:32:18 +00:00
|
|
|
[ -f "$LOCKFILE" ] && return 3
|
2011-03-17 22:02:28 +00:00
|
|
|
|
|
|
|
# Requires selinux policy which has not been written.
|
|
|
|
if [ -r "/selinux/enforce" ] &&
|
|
|
|
[ "$(cat /selinux/enforce)" = "1" ]; then
|
|
|
|
|
|
|
|
log_failure_msg "SELinux ZFS policy required"
|
|
|
|
return 4
|
|
|
|
fi
|
|
|
|
|
2011-06-30 21:45:33 +00:00
|
|
|
# Delay until all required block devices are present.
|
|
|
|
udevadm settle
|
|
|
|
|
2011-03-17 22:02:28 +00:00
|
|
|
# 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=$?
|
2011-12-04 21:32:18 +00:00
|
|
|
if [ "$RETVAL" -eq 0 ]; then
|
2011-03-17 22:02:28 +00:00
|
|
|
/bin/mount -f /
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Import all pools described by the cache file, and then mount
|
|
|
|
# all filesystem based on their properties.
|
2013-12-05 11:36:58 +00:00
|
|
|
if [ "$USE_DISK_BY_ID" -eq 1 ]; then
|
|
|
|
log_begin_msg "Importing ZFS pools"
|
|
|
|
"$ZPOOL" import -d /dev/disk/by-id -aN 2>/dev/null
|
|
|
|
ret=$?
|
|
|
|
log_end_msg $ret
|
|
|
|
[ "$ret" -eq 0 ] && POOL_IMPORTED=1
|
|
|
|
elif [ -f "$ZPOOL_CACHE" ] ; then
|
2011-03-17 22:02:28 +00:00
|
|
|
log_begin_msg "Importing ZFS pools"
|
2011-12-04 21:32:18 +00:00
|
|
|
"$ZPOOL" import -c "$ZPOOL_CACHE" -aN 2>/dev/null
|
2013-12-05 11:36:58 +00:00
|
|
|
ret=$?
|
|
|
|
log_end_msg $ret
|
|
|
|
[ "$ret" -eq 0 ] && POOL_IMPORTED=1
|
|
|
|
fi
|
2011-03-17 22:02:28 +00:00
|
|
|
|
2013-12-05 11:36:58 +00:00
|
|
|
if [ -n "$POOL_IMPORTED" ]; then
|
2011-03-17 22:02:28 +00:00
|
|
|
log_begin_msg "Mounting ZFS filesystems"
|
2011-12-04 21:32:18 +00:00
|
|
|
"$ZFS" mount -a
|
2011-03-17 22:02:28 +00:00
|
|
|
log_end_msg $?
|
2011-07-03 00:43:25 +00:00
|
|
|
|
|
|
|
log_begin_msg "Exporting ZFS filesystems"
|
2011-12-04 21:32:18 +00:00
|
|
|
"$ZFS" share -a
|
2011-07-03 00:43:25 +00:00
|
|
|
log_end_msg $?
|
2011-03-17 22:02:28 +00:00
|
|
|
fi
|
2011-07-25 00:00:53 +00:00
|
|
|
|
2011-12-04 21:32:18 +00:00
|
|
|
touch "$LOCKFILE"
|
2011-03-17 22:02:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
stop()
|
|
|
|
{
|
2011-12-04 21:32:18 +00:00
|
|
|
[ ! -f "$LOCKFILE" ] && return 3
|
2011-03-17 22:02:28 +00:00
|
|
|
|
|
|
|
log_begin_msg "Unmounting ZFS filesystems"
|
2011-12-04 21:32:18 +00:00
|
|
|
"$ZFS" umount -a
|
2011-03-17 22:02:28 +00:00
|
|
|
log_end_msg $?
|
|
|
|
|
2011-12-04 21:32:18 +00:00
|
|
|
rm -f "$LOCKFILE"
|
2011-03-17 22:02:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
status()
|
|
|
|
{
|
2011-12-04 21:32:18 +00:00
|
|
|
[ ! -f "$LOCKFILE" ] && return 3
|
2011-03-17 22:02:28 +00:00
|
|
|
|
2011-12-04 21:32:18 +00:00
|
|
|
"$ZPOOL" status && echo "" && "$ZPOOL" list
|
2011-03-17 22:02:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
start)
|
|
|
|
start
|
|
|
|
RETVAL=$?
|
|
|
|
;;
|
|
|
|
stop)
|
|
|
|
stop
|
|
|
|
RETVAL=$?
|
|
|
|
;;
|
|
|
|
status)
|
|
|
|
status
|
|
|
|
RETVAL=$?
|
|
|
|
;;
|
|
|
|
restart)
|
|
|
|
stop
|
|
|
|
start
|
|
|
|
;;
|
|
|
|
condrestart)
|
2011-12-04 21:32:18 +00:00
|
|
|
if [ -f "$LOCKFILE" ]; then
|
2011-03-17 22:02:28 +00:00
|
|
|
stop
|
|
|
|
start
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo $"Usage: $0 {start|stop|status|restart|condrestart}"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
exit $RETVAL
|