]> git.proxmox.com Git - mirror_zfs-debian.git/blob - etc/init.d/zfs.lunar.in
Imported Upstream version 0.6.4.2
[mirror_zfs-debian.git] / etc / init.d / zfs.lunar.in
1 #!/bin/bash
2 #
3 # zfs This shell script takes care of starting (mount) and
4 # stopping (umount) zfs shares.
5 #
6 # chkconfig: 35 60 40
7 # description: ZFS is a filesystem developed by Sun, ZFS is a
8 # combined file system and logical volume manager
9 # designed by Sun Microsystems. Made available to Linux
10 # using SPL (Solaris Porting Layer) by zfsonlinux.org.
11 # probe: true
12
13 ZFS="@sbindir@/zfs"
14 ZPOOL="@sbindir@/zpool"
15 ZPOOL_CACHE="@sysconfdir@/zfs/zpool.cache"
16
17 if [ -z "$init" ]; then
18 # Not interactive
19 grep -qE '(^|[^\\](\\\\)* )zfs=(off|no)( |$)' /proc/cmdline && exit 3
20 fi
21
22 case $1 in
23 start) echo "$1ing ZFS filesystems"
24
25 # Delay until all required block devices are present.
26 udevadm settle
27
28 if ! grep "zfs" /proc/modules > /dev/null; then
29 echo "ZFS kernel module not loaded yet; loading...";
30 if ! modprobe zfs; then
31 echo "Failed to load ZFS kernel module...";
32 exit 0;
33 fi
34 fi
35
36 if ! [ `uname -m` == "x86_64" ]; then
37 echo "Warning: You're not running 64bit. Currently native zfs in";
38 echo " linux is only supported and tested on 64bit.";
39 # should we break here? People doing this should know what they
40 # do, thus i'm not breaking here.
41 fi
42
43 # mount the filesystems
44 while IFS= read -r -d $'\n' dev; do
45 mdev=$(echo "$dev" | awk '{ print $1; }')
46 echo -n "mounting $mdev..."
47 if $ZFS mount $mdev; then
48 echo -e "done";
49 else
50 echo -e "failed";
51 fi
52 done < <($ZFS list -H);
53
54 # export the filesystems
55 echo -n "exporting ZFS filesystems..."
56 if $ZFS share -a; then
57 echo -e "done";
58 else
59 echo -e "failed";
60 fi
61
62
63 ;;
64
65 stop) echo "$1ping ZFS filesystems"
66
67 if grep "zfs" /proc/modules > /dev/null; then
68 # module is loaded, so we can try to umount filesystems
69 while IFS= read -r -d $'\n' dev; do
70 mdev=$(echo "$dev" | awk '{ print $1 }');
71 echo -n "umounting $mdev...";
72 if $ZFS umount $mdev; then
73 echo -e "done";
74 else
75 echo -e "failed";
76 fi
77 # the next line is, because i have to reverse the
78 # output, otherwise it wouldn't work as it should
79 done < <($ZFS list -H | tac);
80
81 # and finally let's rmmod the module
82 rmmod zfs
83
84
85 else
86 # module not loaded, no need to umount anything
87 exit 0
88 fi
89
90 ;;
91
92 restart) echo "$1ing ZFS filesystems"
93 $0 stop
94 $0 start
95 ;;
96
97 *) echo "Usage: $0 {start|stop|restart}"
98 ;;
99
100 esac