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