File zfs.init of Package zfs
#!/bin/sh
#
### BEGIN INIT INFO
# Provides: zfs
# Required-Start: $local_fs
# Should-Start:
# Required-Stop: $local_fs
# Should-Stop:
# Default-Start: 3 5
# Default-Stop: 0 1 2 6
# 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
# Check for missing binaries (stale symlinks should not happen)
# Note: Special treatment of stop for LSB conformance
/sbin/modinfo zfs > /dev/null 2>&1 || { echo "zfs kernel module not installed";
if [ "$1" = "stop" ]; then exit 0;
else exit 5; fi; }
ZFS_BIN=/usr/sbin/zfs
test -x $ZFS_BIN || { echo "$ZFS_BIN not installed";
if [ "$1" = "stop" ]; then exit 0;
else exit 5; fi; }
ZPOOL_BIN=/usr/sbin/zpool
test -x $ZPOOL_BIN || { echo "$ZPOOL_BIN not installed";
if [ "$1" = "stop" ]; then exit 0;
else exit 5; fi; }
LOCKFILE=/var/lock/zfs
ZPOOL_CACHE="/etc/zfs/zpool.cache"
. /etc/rc.status
# Reset status of this service
rc_reset
start()
{
[ -f "$LOCKFILE" ] && return 0
# Requires selinux policy which has not been written.
if [ -r "/selinux/enforce" ] &&
[ "$(cat /selinux/enforce)" = "1" ]; then
echo "SELinux ZFS policy required"
return 6
fi
# Delay until all required block devices are present.
udevadm settle
# Load the zfs module stack
if ! grep -q zfs /proc/modules ; then
/sbin/modprobe zfs
sleep 1
fi
# Import all pools described by the cache file, and then mount
# all filesystem based on their properties.
if [ -f $ZPOOL_CACHE ]; then
echo "Importing ZFS pools"
# as per fedora script, import can fail if all pools are already imported
# The check for $rv makes no sense...but someday, it will work right.
$ZPOOL_BIN import -c $ZPOOL_CACHE -aN 2>/dev/null || true
rv=$?
if [ $rv -ne 0 ]; then
echo "Failed to import not-yet imported pools."
return $rv
fi
fi
echo "Mounting ZFS filesystems"
$ZFS_BIN mount -a
rv=$?
if [ $rv -ne 0 ]; then
echo "Failed to mount ZFS filesystems."
return $rv
fi
echo "Exporting ZFS filesystems"
$ZFS_BIN share -a
rv=$?
if [ $rv -ne 0 ]; then
echo "Failed to export ZFS filesystems."
return $rv
fi
touch "$LOCKFILE"
}
stop()
{
[ ! -f "$LOCKFILE" ] && return 0
$ZFS_BIN umount -a
if [ $? -ne 0 ]; then
# Don't fail if we couldn't umount everything. /usr might be in use
return 0
fi
rm -f "$LOCKFILE"
}
status()
{
rv=0
lsmod | grep -q zfs || rv=3
$ZPOOL_BIN status && echo && $ZFS_BIN list || {
[ -f "$LOCKFILE" ] && rv=2 || rv=4
}
return $rv
}
case "$1" in
start)
echo -n "Starting zfs "
start
rc_status -v
;;
stop)
echo -n "Shutting down zfs "
stop
rc_status -v
;;
try-restart|condrestart)
status
if [ $? -eq 0 ]; then
$0 restart
else
rc_reset
fi
rc_status
;;
restart)
$0 stop
$0 start
rc_status
;;
reload)
rc_failed 3
rc_status -v
;;
status)
echo -n "Checking for service zfs "
status
rc_status -v
;;
*)
echo "Usage: $0 {start|stop|status|try-restart|restart|reload}"
exit 1
;;
esac
rc_exit