| 
									
										
										
										
											2011-05-03 02:39:59 +04:00
										 |  |  | #!/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 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-25 04:00:53 +04:00
										 |  |  | ZFS="@sbindir@/zfs" | 
					
						
							|  |  |  | ZPOOL="@sbindir@/zpool" | 
					
						
							| 
									
										
										
										
											2011-08-10 03:49:18 +04:00
										 |  |  | ZPOOL_CACHE="@initdir@/zpool.cache" | 
					
						
							| 
									
										
										
										
											2011-07-25 04:00:53 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-03 02:39:59 +04:00
										 |  |  | case $1 in | 
					
						
							|  |  |  |   start)  echo "$1ing ZFS filesystems" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-01 01:45:33 +04:00
										 |  |  |     # Delay until all required block devices are present. | 
					
						
							|  |  |  |     udevadm settle | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-03 02:39:59 +04:00
										 |  |  |     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 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-03 04:35:58 +04:00
										 |  |  |     # mount the filesystems | 
					
						
							|  |  |  |     while IFS= read -r -d $'\n' dev; do | 
					
						
							|  |  |  |       mdev=$(echo "$dev" | awk '{ print $1; }') | 
					
						
							|  |  |  |       echo -n "mounting $mdev..." | 
					
						
							| 
									
										
										
										
											2011-07-25 04:00:53 +04:00
										 |  |  |       if $ZFS mount $mdev; then | 
					
						
							| 
									
										
										
										
											2011-07-03 04:35:58 +04:00
										 |  |  |         echo -e "done"; | 
					
						
							|  |  |  |       else | 
					
						
							|  |  |  |         echo -e "failed"; | 
					
						
							|  |  |  |       fi | 
					
						
							| 
									
										
										
										
											2011-07-25 04:00:53 +04:00
										 |  |  |     done < <($ZFS list -H); | 
					
						
							| 
									
										
										
										
											2011-05-03 02:39:59 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-03 04:43:25 +04:00
										 |  |  |     # export the filesystems | 
					
						
							|  |  |  |     echo -n "exporting ZFS filesystems..." | 
					
						
							| 
									
										
										
										
											2011-07-25 04:00:53 +04:00
										 |  |  |     if $ZFS share -a; then | 
					
						
							| 
									
										
										
										
											2011-07-03 04:43:25 +04:00
										 |  |  |       echo -e "done"; | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       echo -e "failed"; | 
					
						
							|  |  |  |     fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-03 02:39:59 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  |   ;; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   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..."; | 
					
						
							| 
									
										
										
										
											2011-07-25 04:00:53 +04:00
										 |  |  |         if $ZFS umount $mdev; then | 
					
						
							| 
									
										
										
										
											2011-05-03 02:39:59 +04:00
										 |  |  |           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 | 
					
						
							| 
									
										
										
										
											2011-07-25 04:00:53 +04:00
										 |  |  |       done < <($ZFS list -H | tac); | 
					
						
							| 
									
										
										
										
											2011-05-03 02:39:59 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  |       # 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 |