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