]> git.proxmox.com Git - mirror_zfs-debian.git/blob - etc/init.d/zfs.gentoo.in
Make Gentoo initscript use modinfo
[mirror_zfs-debian.git] / etc / init.d / zfs.gentoo.in
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
6 depend()
7 {
8 # bootmisc will log to /var which may be a different zfs than root.
9 before net bootmisc
10 after udev localmount
11 keyword -lxc -openvz -prefix -vserver
12 }
13
14 ZFS="@sbindir@/zfs"
15 ZPOOL="@sbindir@/zpool"
16 ZPOOL_CACHE="@sysconfdir@/zfs/zpool.cache"
17 ZFS_MODULE=zfs
18
19 checksystem() {
20 if [ ! -c /dev/zfs ]; then
21 einfo "Checking if ZFS modules present"
22 if ! modinfo zfs > /dev/null 2>&1 ; then
23 eerror "$ZFS_MODULE not found. Is the ZFS package installed?"
24 return 1
25 fi
26 fi
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
36 return 0
37 }
38
39 start() {
40 ebegin "Starting ZFS"
41 checksystem || return 1
42
43 # Delay until all required block devices are present.
44 udevadm settle
45
46 if [ ! -c /dev/zfs ]; then
47 modprobe $ZFS_MODULE
48 rv=$?
49 if [ $rv -ne 0 ]; then
50 eerror "Failed to load the $ZFS_MODULE module, check 'dmesg|tail'."
51 eend $rv
52 return $rv
53 fi
54 fi
55
56 # Import all pools described by the cache file, and then mount
57 # all filesystem based on their properties.
58 if [ -f $ZPOOL_CACHE ]; then
59 einfo "Importing ZFS pools"
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.
62 $ZPOOL import -c $ZPOOL_CACHE -aN 2>/dev/null || true
63 rv=$?
64 if [ $rv -ne 0 ]; then
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=$?
74 if [ $rv -ne 0 ]; then
75 eerror "Failed to mount ZFS filesystems."
76 eend $rv
77 return $rv
78 fi
79
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
89 eend 0
90 return 0
91 }
92
93 stop()
94 {
95 ebegin "Unmounting ZFS filesystems"
96 $ZFS umount -a
97 rv=$?
98 if [ $rv -ne 0 ]; then
99 einfo "Some ZFS filesystems not unmounted"
100 fi
101
102 # Don't fail if we couldn't umount everything. /usr might be in use.
103 eend 0
104 return 0
105 }
106
107 status()
108 {
109 # show pool status and list
110 $ZPOOL status && echo && $ZPOOL list
111 }