aboutsummaryrefslogtreecommitdiffstats
path: root/etc/init.d/zfs.lunar.in
blob: 7a51104c2647ca60521318c2d531b4d3cff46415 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/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

ZFS="@sbindir@/zfs"
ZPOOL="@sbindir@/zpool"
ZPOOL_CACHE="@sysconfdir@/zfs/zpool.cache"

if [ -z "$init" ]; then
    # Not interactive
    grep -qE '(^|[^\\](\\\\)* )zfs=(off|no)( |$)' /proc/cmdline && exit 3
fi

case $1 in
  start)  echo "$1ing ZFS filesystems"

    # Delay until all required block devices are present.
    udevadm settle

    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

    # mount the filesystems
    while IFS= read -r -d $'\n' dev; do
      mdev=$(echo "$dev" | awk '{ print $1; }')
      echo -n "mounting $mdev..."
      if $ZFS mount $mdev; then
        echo -e "done";
      else
        echo -e "failed";
      fi
    done < <($ZFS list -H);

    # export the filesystems
    echo -n "exporting ZFS filesystems..."
    if $ZFS share -a; then
      echo -e "done";
    else
      echo -e "failed";
    fi


  ;;

  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...";
        if $ZFS umount $mdev; then
          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
      done < <($ZFS list -H | tac);

      # 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