bdc461af861b258dfc9dda6ebee254e78788e580
[zfs.git] / etc / init.d / zfs.lunar
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 case $1 in
14   start)  echo "$1ing ZFS filesystems"
15
16     # Delay until all required block devices are present.
17     udevadm settle
18
19     if ! grep "zfs" /proc/modules > /dev/null; then
20       echo "ZFS kernel module not loaded yet; loading...";
21       if ! modprobe zfs; then
22         echo "Failed to load ZFS kernel module...";
23         exit 0;
24       fi
25     fi
26
27     if ! [ `uname -m` == "x86_64" ]; then
28       echo "Warning: You're not running 64bit. Currently native zfs in";
29       echo "         linux is only supported and tested on 64bit.";
30       # should we break here? People doing this should know what they
31       # do, thus i'm not breaking here.
32     fi
33
34     # mount the filesystems
35     while IFS= read -r -d $'\n' dev; do
36       mdev=$(echo "$dev" | awk '{ print $1; }')
37       echo -n "mounting $mdev..."
38       if zfs mount $mdev; then
39         echo -e "done";
40       else
41         echo -e "failed";
42       fi
43     done < <(zfs list -H);
44
45     # export the filesystems
46     echo -n "exporting ZFS filesystems..."
47     if zfs share -a; then
48       echo -e "done";
49     else
50       echo -e "failed";
51     fi
52
53
54   ;;
55
56   stop)  echo "$1ping ZFS filesystems"
57
58     if grep "zfs" /proc/modules > /dev/null; then
59       # module is loaded, so we can try to umount filesystems
60       while IFS= read -r -d $'\n' dev; do
61         mdev=$(echo "$dev" | awk '{ print $1 }');
62         echo -n "umounting $mdev...";
63         if zfs umount $mdev; then
64           echo -e "done";
65         else
66           echo -e "failed";
67         fi
68         # the next line is, because i have to reverse the
69         # output, otherwise it wouldn't work as it should
70       done < <(zfs list -H | tac);
71
72       # and finally let's rmmod the module
73       rmmod zfs
74
75
76     else
77       # module not loaded, no need to umount anything
78       exit 0
79     fi
80
81   ;;
82
83   restart) echo "$1ing ZFS filesystems"
84     $0 stop
85     $0 start
86   ;;
87
88   *)  echo "Usage: $0 {start|stop|restart}"
89   ;;
90
91 esac