]> git.proxmox.com Git - mirror_zfs-debian.git/blame - etc/init.d/zfs.gentoo.in
Imported Upstream version 0.6.4.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
a08ee875 8 grep -qE '(^|[^\\](\\\\)* )zfs=(off|no)( |$)' /proc/cmdline && exit 3
c06d4368
AX
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
ea04106b 23 use mtab
04c22478 24 keyword -lxc -openvz -prefix -vserver
712f8bd8
BB
25}
26
5faa9c03
KF
27ZFS="@sbindir@/zfs"
28ZPOOL="@sbindir@/zpool"
1a2e6a63 29ZPOOL_CACHE="@sysconfdir@/zfs/zpool.cache"
712f8bd8 30ZFS_MODULE=zfs
712f8bd8 31
04c22478 32checksystem() {
e93ced48 33 if [ ! -c /dev/zfs ]; then
04c22478 34 einfo "Checking if ZFS modules present"
2ce9d0ec 35 if ! modinfo zfs > /dev/null 2>&1 ; then
04c22478
AS
36 eerror "$ZFS_MODULE not found. Is the ZFS package installed?"
37 return 1
38 fi
712f8bd8 39 fi
04c22478
AS
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
712f8bd8
BB
49 return 0
50}
51
04c22478 52start() {
712f8bd8
BB
53 ebegin "Starting ZFS"
54 checksystem || return 1
2a005961
BB
55
56 # Delay until all required block devices are present.
57 udevadm settle
58
04c22478
AS
59 if [ ! -c /dev/zfs ]; then
60 modprobe $ZFS_MODULE
712f8bd8 61 rv=$?
04c22478 62 if [ $rv -ne 0 ]; then
712f8bd8
BB
63 eerror "Failed to load the $ZFS_MODULE module, check 'dmesg|tail'."
64 eend $rv
65 return $rv
66 fi
67 fi
68
712f8bd8
BB
69 # Import all pools described by the cache file, and then mount
70 # all filesystem based on their properties.
5faa9c03 71 if [ -f $ZPOOL_CACHE ]; then
712f8bd8 72 einfo "Importing ZFS pools"
712f8bd8
BB
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.
5faa9c03 75 $ZPOOL import -c $ZPOOL_CACHE -aN 2>/dev/null || true
712f8bd8 76 rv=$?
04c22478 77 if [ $rv -ne 0 ]; then
712f8bd8
BB
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=$?
04c22478 87 if [ $rv -ne 0 ]; then
712f8bd8
BB
88 eerror "Failed to mount ZFS filesystems."
89 eend $rv
90 return $rv
91 fi
92
8b0cf399
GB
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
712f8bd8
BB
102 eend 0
103 return 0
104}
105
106stop()
107{
712f8bd8 108 ebegin "Unmounting ZFS filesystems"
712f8bd8 109 $ZFS umount -a
06abcdd3 110 rv=$?
04c22478 111 if [ $rv -ne 0 ]; then
e93ced48 112 einfo "Some ZFS filesystems not unmounted"
712f8bd8 113 fi
04c22478 114
e93ced48
ZB
115 # Don't fail if we couldn't umount everything. /usr might be in use.
116 eend 0
117 return 0
712f8bd8
BB
118}
119
120status()
121{
712f8bd8
BB
122 # show pool status and list
123 $ZPOOL status && echo && $ZPOOL list
124}