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