]> git.proxmox.com Git - mirror_zfs-debian.git/blob - etc/init.d/zfs.gentoo.in
Imported Upstream version 0.6.4.2
[mirror_zfs-debian.git] / etc / init.d / zfs.gentoo.in
1 #!/sbin/runscript
2 # Copyright 1999-2011 Gentoo Foundation
3 # Released under the 2-clause BSD license.
4 # $Header: /var/cvsroot/gentoo-x86/sys-fs/zfs/files/zfs,v 0.9 2011/04/30 10:13:43 devsk Exp $
5
6 if [ -z "$init" ]; then
7 # Not interactive
8 grep -qE '(^|[^\\](\\\\)* )zfs=(off|no)( |$)' /proc/cmdline && exit 3
9 fi
10
11 depend()
12 {
13 # Try to allow people to mix and match fstab with ZFS in a way that makes sense.
14 if [ "$(mountinfo -s /)" = 'zfs' ]
15 then
16 before localmount
17 else
18 after localmount
19 fi
20
21 # bootmisc will log to /var which may be a different zfs than root.
22 before bootmisc logger
23 use mtab
24 keyword -lxc -openvz -prefix -vserver
25 }
26
27 ZFS="@sbindir@/zfs"
28 ZPOOL="@sbindir@/zpool"
29 ZPOOL_CACHE="@sysconfdir@/zfs/zpool.cache"
30 ZFS_MODULE=zfs
31
32 checksystem() {
33 if [ ! -c /dev/zfs ]; then
34 einfo "Checking if ZFS modules present"
35 if ! modinfo zfs > /dev/null 2>&1 ; then
36 eerror "$ZFS_MODULE not found. Is the ZFS package installed?"
37 return 1
38 fi
39 fi
40 einfo "Checking if zfs userspace tools present"
41 if [ ! -x $ZPOOL ]; then
42 eerror "$ZPOOL binary not found."
43 return 1
44 fi
45 if [ ! -x $ZFS ]; then
46 eerror "$ZFS binary not found."
47 return 1
48 fi
49 return 0
50 }
51
52 start() {
53 ebegin "Starting ZFS"
54 checksystem || return 1
55
56 # Delay until all required block devices are present.
57 udevadm settle
58
59 if [ ! -c /dev/zfs ]; then
60 modprobe $ZFS_MODULE
61 rv=$?
62 if [ $rv -ne 0 ]; then
63 eerror "Failed to load the $ZFS_MODULE module, check 'dmesg|tail'."
64 eend $rv
65 return $rv
66 fi
67 fi
68
69 # Import all pools described by the cache file, and then mount
70 # all filesystem based on their properties.
71 if [ -f $ZPOOL_CACHE ]; then
72 einfo "Importing ZFS pools"
73 # as per fedora script, import can fail if all pools are already imported
74 # The check for $rv makes no sense...but someday, it will work right.
75 $ZPOOL import -c $ZPOOL_CACHE -aN 2>/dev/null || true
76 rv=$?
77 if [ $rv -ne 0 ]; then
78 eerror "Failed to import not-yet imported pools."
79 eend $rv
80 return $rv
81 fi
82 fi
83
84 einfo "Mounting ZFS filesystems"
85 $ZFS mount -a
86 rv=$?
87 if [ $rv -ne 0 ]; then
88 eerror "Failed to mount ZFS filesystems."
89 eend $rv
90 return $rv
91 fi
92
93 einfo "Exporting ZFS filesystems"
94 $ZFS share -a
95 rv=$?
96 if [ $rv -ne 0 ]; then
97 eerror "Failed to export ZFS filesystems."
98 eend $rv
99 return $rv
100 fi
101
102 eend 0
103 return 0
104 }
105
106 stop()
107 {
108 ebegin "Unmounting ZFS filesystems"
109 $ZFS umount -a
110 rv=$?
111 if [ $rv -ne 0 ]; then
112 einfo "Some ZFS filesystems not unmounted"
113 fi
114
115 # Don't fail if we couldn't umount everything. /usr might be in use.
116 eend 0
117 return 0
118 }
119
120 status()
121 {
122 # show pool status and list
123 $ZPOOL status && echo && $ZPOOL list
124 }