2011-05-02 22:39:59 +00:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# zfs This shell script takes care of starting (mount) and
|
|
|
|
# stopping (umount) zfs shares.
|
|
|
|
#
|
|
|
|
# chkconfig: 35 60 40
|
|
|
|
# description: ZFS is a filesystem developed by Sun, ZFS is a
|
|
|
|
# combined file system and logical volume manager
|
|
|
|
# designed by Sun Microsystems. Made available to Linux
|
|
|
|
# using SPL (Solaris Porting Layer) by zfsonlinux.org.
|
|
|
|
# probe: true
|
|
|
|
|
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"
|
2011-07-25 00:00:53 +00:00
|
|
|
|
2013-04-14 15:41:51 +00:00
|
|
|
if [ -z "$init" ]; then
|
|
|
|
# Not interactive
|
|
|
|
grep -Eqi 'zfs=off|zfs=no' /proc/cmdline && exit 3
|
|
|
|
fi
|
|
|
|
|
2011-05-02 22:39:59 +00:00
|
|
|
case $1 in
|
|
|
|
start) echo "$1ing ZFS filesystems"
|
|
|
|
|
2011-06-30 21:45:33 +00:00
|
|
|
# Delay until all required block devices are present.
|
|
|
|
udevadm settle
|
|
|
|
|
2011-05-02 22:39:59 +00:00
|
|
|
if ! grep "zfs" /proc/modules > /dev/null; then
|
|
|
|
echo "ZFS kernel module not loaded yet; loading...";
|
|
|
|
if ! modprobe zfs; then
|
|
|
|
echo "Failed to load ZFS kernel module...";
|
|
|
|
exit 0;
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if ! [ `uname -m` == "x86_64" ]; then
|
|
|
|
echo "Warning: You're not running 64bit. Currently native zfs in";
|
|
|
|
echo " linux is only supported and tested on 64bit.";
|
|
|
|
# should we break here? People doing this should know what they
|
|
|
|
# do, thus i'm not breaking here.
|
|
|
|
fi
|
|
|
|
|
2011-07-03 00:35:58 +00:00
|
|
|
# mount the filesystems
|
|
|
|
while IFS= read -r -d $'\n' dev; do
|
|
|
|
mdev=$(echo "$dev" | awk '{ print $1; }')
|
|
|
|
echo -n "mounting $mdev..."
|
2011-07-25 00:00:53 +00:00
|
|
|
if $ZFS mount $mdev; then
|
2011-07-03 00:35:58 +00:00
|
|
|
echo -e "done";
|
|
|
|
else
|
|
|
|
echo -e "failed";
|
|
|
|
fi
|
2011-07-25 00:00:53 +00:00
|
|
|
done < <($ZFS list -H);
|
2011-05-02 22:39:59 +00:00
|
|
|
|
2011-07-03 00:43:25 +00:00
|
|
|
# export the filesystems
|
|
|
|
echo -n "exporting ZFS filesystems..."
|
2011-07-25 00:00:53 +00:00
|
|
|
if $ZFS share -a; then
|
2011-07-03 00:43:25 +00:00
|
|
|
echo -e "done";
|
|
|
|
else
|
|
|
|
echo -e "failed";
|
|
|
|
fi
|
|
|
|
|
2011-05-02 22:39:59 +00:00
|
|
|
|
|
|
|
;;
|
|
|
|
|
|
|
|
stop) echo "$1ping ZFS filesystems"
|
|
|
|
|
|
|
|
if grep "zfs" /proc/modules > /dev/null; then
|
|
|
|
# module is loaded, so we can try to umount filesystems
|
|
|
|
while IFS= read -r -d $'\n' dev; do
|
|
|
|
mdev=$(echo "$dev" | awk '{ print $1 }');
|
|
|
|
echo -n "umounting $mdev...";
|
2011-07-25 00:00:53 +00:00
|
|
|
if $ZFS umount $mdev; then
|
2011-05-02 22:39:59 +00:00
|
|
|
echo -e "done";
|
|
|
|
else
|
|
|
|
echo -e "failed";
|
|
|
|
fi
|
|
|
|
# the next line is, because i have to reverse the
|
|
|
|
# output, otherwise it wouldn't work as it should
|
2011-07-25 00:00:53 +00:00
|
|
|
done < <($ZFS list -H | tac);
|
2011-05-02 22:39:59 +00:00
|
|
|
|
|
|
|
# and finally let's rmmod the module
|
|
|
|
rmmod zfs
|
|
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
# module not loaded, no need to umount anything
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
;;
|
|
|
|
|
|
|
|
restart) echo "$1ing ZFS filesystems"
|
|
|
|
$0 stop
|
|
|
|
$0 start
|
|
|
|
;;
|
|
|
|
|
|
|
|
*) echo "Usage: $0 {start|stop|restart}"
|
|
|
|
;;
|
|
|
|
|
|
|
|
esac
|