Removed erroneous backticks in the zfs.lunar init script.
[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
46   ;;
47
48   stop)  echo "$1ping ZFS filesystems"
49
50     if grep "zfs" /proc/modules > /dev/null; then
51       # module is loaded, so we can try to umount filesystems
52       while IFS= read -r -d $'\n' dev; do
53         mdev=$(echo "$dev" | awk '{ print $1 }');
54         echo -n "umounting $mdev...";
55         if zfs umount $mdev; then
56           echo -e "done";
57         else
58           echo -e "failed";
59         fi
60         # the next line is, because i have to reverse the
61         # output, otherwise it wouldn't work as it should
62       done < <(zfs list -H | tac);
63
64       # and finally let's rmmod the module
65       rmmod zfs
66
67
68     else
69       # module not loaded, no need to umount anything
70       exit 0
71     fi
72
73   ;;
74
75   restart) echo "$1ing ZFS filesystems"
76     $0 stop
77     $0 start
78   ;;
79
80   *)  echo "Usage: $0 {start|stop|restart}"
81   ;;
82
83 esac