]> git.proxmox.com Git - mirror_zfs-debian.git/blame - etc/init.d/zfs.gentoo.in
Merge branch 'udev'
[mirror_zfs-debian.git] / etc / init.d / zfs.gentoo.in
CommitLineData
712f8bd8
BB
1#!/sbin/runscript
2# Copyright 1999-2011 Gentoo Foundation
3# Distributed under the terms of the GNU General Public License v2
4# $Header: /var/cvsroot/gentoo-x86/sys-fs/zfs/files/zfs,v 0.9 2011/04/30 10:13:43 devsk Exp $
5
6depend()
7{
e93ced48
ZB
8 # bootmisc will log to /var which may be a different zfs than root.
9 before net bootmisc
b59322a0 10 after udev localmount
04c22478 11 keyword -lxc -openvz -prefix -vserver
712f8bd8
BB
12}
13
5faa9c03
KF
14ZFS="@sbindir@/zfs"
15ZPOOL="@sbindir@/zpool"
aa2b4896 16ZPOOL_CACHE="@initdir@/zpool.cache"
712f8bd8 17ZFS_MODULE=zfs
712f8bd8 18
04c22478 19checksystem() {
e93ced48 20 if [ ! -c /dev/zfs ]; then
04c22478 21 einfo "Checking if ZFS modules present"
06abcdd3 22 if [ "x$(modprobe -l $ZFS_MODULE | grep $ZFS_MODULE)" == "x" ]; then
04c22478
AS
23 eerror "$ZFS_MODULE not found. Is the ZFS package installed?"
24 return 1
25 fi
712f8bd8 26 fi
04c22478
AS
27 einfo "Checking if zfs userspace tools present"
28 if [ ! -x $ZPOOL ]; then
29 eerror "$ZPOOL binary not found."
30 return 1
31 fi
32 if [ ! -x $ZFS ]; then
33 eerror "$ZFS binary not found."
34 return 1
35 fi
712f8bd8
BB
36 return 0
37}
38
04c22478 39start() {
712f8bd8
BB
40 ebegin "Starting ZFS"
41 checksystem || return 1
2a005961
BB
42
43 # Delay until all required block devices are present.
44 udevadm settle
45
04c22478
AS
46 if [ ! -c /dev/zfs ]; then
47 modprobe $ZFS_MODULE
712f8bd8 48 rv=$?
04c22478 49 if [ $rv -ne 0 ]; then
712f8bd8
BB
50 eerror "Failed to load the $ZFS_MODULE module, check 'dmesg|tail'."
51 eend $rv
52 return $rv
53 fi
54 fi
55
712f8bd8
BB
56 # Import all pools described by the cache file, and then mount
57 # all filesystem based on their properties.
5faa9c03 58 if [ -f $ZPOOL_CACHE ]; then
712f8bd8 59 einfo "Importing ZFS pools"
712f8bd8
BB
60 # as per fedora script, import can fail if all pools are already imported
61 # The check for $rv makes no sense...but someday, it will work right.
5faa9c03 62 $ZPOOL import -c $ZPOOL_CACHE -aN 2>/dev/null || true
712f8bd8 63 rv=$?
04c22478 64 if [ $rv -ne 0 ]; then
712f8bd8
BB
65 eerror "Failed to import not-yet imported pools."
66 eend $rv
67 return $rv
68 fi
69 fi
70
71 einfo "Mounting ZFS filesystems"
72 $ZFS mount -a
73 rv=$?
04c22478 74 if [ $rv -ne 0 ]; then
712f8bd8
BB
75 eerror "Failed to mount ZFS filesystems."
76 eend $rv
77 return $rv
78 fi
79
8b0cf399
GB
80 einfo "Exporting ZFS filesystems"
81 $ZFS share -a
82 rv=$?
83 if [ $rv -ne 0 ]; then
84 eerror "Failed to export ZFS filesystems."
85 eend $rv
86 return $rv
87 fi
88
712f8bd8
BB
89 eend 0
90 return 0
91}
92
93stop()
94{
712f8bd8 95 ebegin "Unmounting ZFS filesystems"
712f8bd8 96 $ZFS umount -a
06abcdd3 97 rv=$?
04c22478 98 if [ $rv -ne 0 ]; then
e93ced48 99 einfo "Some ZFS filesystems not unmounted"
712f8bd8 100 fi
04c22478 101
e93ced48
ZB
102 # Don't fail if we couldn't umount everything. /usr might be in use.
103 eend 0
104 return 0
712f8bd8
BB
105}
106
107status()
108{
712f8bd8
BB
109 # show pool status and list
110 $ZPOOL status && echo && $ZPOOL list
111}