summaryrefslogtreecommitdiffstats
path: root/etc/init.d/zfs.gentoo
diff options
context:
space:
mode:
authorBrian Behlendorf <[email protected]>2011-05-02 15:39:59 -0700
committerBrian Behlendorf <[email protected]>2011-05-02 15:59:13 -0700
commit712f8bd87b2d3799107e102652875996fa59647b (patch)
tree7accb1ffa17551954bc9b7dbb3451e4efdb94527 /etc/init.d/zfs.gentoo
parent5f35b190071048f25d66db81ce9763ecd0c1760e (diff)
Add Gentoo/Lunar/Redhat Init Scripts
Every distribution has slightly different requirements for their init scripts. Because of this the zfs package contains several init scripts for various distributions. These scripts have been contributed by, and are supported by, the larger zfs community. Init scripts for Gentoo/Lunar/Redhat have been contributed by: Gentoo - devsk <[email protected]> Lunar - Jean-Michel Bruenn <[email protected]> Redhat - Fajar A. Nugraha <[email protected]>
Diffstat (limited to 'etc/init.d/zfs.gentoo')
-rw-r--r--etc/init.d/zfs.gentoo151
1 files changed, 151 insertions, 0 deletions
diff --git a/etc/init.d/zfs.gentoo b/etc/init.d/zfs.gentoo
new file mode 100644
index 000000000..d2ea90267
--- /dev/null
+++ b/etc/init.d/zfs.gentoo
@@ -0,0 +1,151 @@
+#!/sbin/runscript
+# Copyright 1999-2011 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Header: /var/cvsroot/gentoo-x86/sys-fs/zfs/files/zfs,v 0.9 2011/04/30 10:13:43 devsk Exp $
+
+depend()
+{
+ before net
+ after udev
+}
+
+CACHEFILE=/etc/zfs/zpool.cache
+ZPOOL=/usr/sbin/zpool
+ZFS=/usr/sbin/zfs
+ZFS_MODULE=zfs
+LOCKFILE=/var/lock/zfs/zfs_lockfile
+
+checksystem()
+{
+ /sbin/modinfo $ZFS_MODULE &>/dev/null
+ if [[ $? -ne 0 ]]
+ then
+ eerror "$ZFS_MODULE not found. Is the ZFS package installed?"
+ return 1
+ fi
+ if [[ ! -x $ZPOOL ]]
+ then
+ eerror "$ZPOOL binary not found."
+ return 1
+ fi
+ if [[ ! -x $ZFS ]]
+ then
+ eerror "$ZFS binary not found."
+ return 1
+ fi
+
+ # create the lockdir if not there
+ lockdir=$(dirname ${LOCKFILE})
+ if [[ ! -d ${lockdir} ]]
+ then
+ mkdir -p ${lockdir} &>/dev/null
+ fi
+ return 0
+}
+
+start()
+{
+ if [[ -f $LOCKFILE ]]
+ then
+ einfo "ZFS already running, please stop it first. Delete $LOCKFILE if its not so."
+ eend 3
+ return 3
+ fi
+ ebegin "Starting ZFS"
+ checksystem || return 1
+ if ! grep -q $ZFS_MODULE /proc/modules
+ then
+ /sbin/modprobe $ZFS_MODULE &>/dev/null
+ rv=$?
+ if [[ $rv -ne 0 ]]
+ then
+ eerror "Failed to load the $ZFS_MODULE module, check 'dmesg|tail'."
+ eend $rv
+ return $rv
+ fi
+ fi
+
+ # Ensure / exists in /etc/mtab, if not update mtab accordingly.
+ # This should be handled by rc.sysinit but lets be paranoid.
+ awk '$2 == "/" { exit 1 }' /etc/mtab
+ RETVAL=$?
+ if [[ $RETVAL -eq 0 ]]
+ then
+ /bin/mount -f /
+ fi
+
+ # Import all pools described by the cache file, and then mount
+ # all filesystem based on their properties.
+ if [[ -f $CACHEFILE ]]
+ then
+ einfo "Importing ZFS pools"
+
+ # as per fedora script, import can fail if all pools are already imported
+ # The check for $rv makes no sense...but someday, it will work right.
+ $ZPOOL import -c $CACHEFILE -aN 2>/dev/null || true
+ rv=$?
+ if [[ $rv -ne 0 ]]
+ then
+ eerror "Failed to import not-yet imported pools."
+ eend $rv
+ return $rv
+ fi
+ fi
+
+ einfo "Mounting ZFS filesystems"
+ $ZFS mount -a
+ rv=$?
+ if [[ $rv -ne 0 ]]
+ then
+ eerror "Failed to mount ZFS filesystems."
+ eend $rv
+ return $rv
+ fi
+
+ # hack to read mounted file systems because otherwise
+ # zfs returns EPERM when a non-root user reads a mounted filesystem before root did
+ savepwd="$PWD"
+ mount | grep " type zfs " | sed 's/.*on //' | sed 's/ type zfs.*$//' | \
+ while read line
+ do
+ cd "$line" &> /dev/null
+ ls &> /dev/null
+ done
+ cd "$savepwd"
+
+ touch $LOCKFILE
+ eend 0
+ return 0
+}
+
+stop()
+{
+ if [[ ! -f $LOCKFILE ]]
+ then
+ einfo "ZFS is not started, remove $LOCKFILE if its not so."
+ eend 3
+ return 3
+ fi
+ ebegin "Unmounting ZFS filesystems"
+ sync
+ $ZFS umount -a
+ if [[ $rv -ne 0 ]]
+ then
+ eerror "Failed to umount ZFS filesystems."
+ fi
+ rm -f $LOCKFILE
+ eend $rv
+}
+
+status()
+{
+ if [[ ! -f $LOCKFILE ]]
+ then
+ einfo "ZFS is not started, remove $LOCKFILE if its not so."
+ eend 3
+ return 3
+ fi
+
+ # show pool status and list
+ $ZPOOL status && echo && $ZPOOL list
+}