From 5faa9c0367e8d6b1ee1c45f1ebeffd3e53ef35e8 Mon Sep 17 00:00:00 2001 From: Kyle Fuller Date: Mon, 25 Jul 2011 01:00:53 +0100 Subject: Turn the init.d scripts into autoconf config files This change ensures the paths used by the provided init scripts always reference the prefixes provided at configure time. The @sbindir@ and @sysconfdir@ prefixes will be correctly replaced at build time. Signed-off-by: Brian Behlendorf Closes #336 --- configure | 8 +- configure.ac | 6 ++ etc/init.d/Makefile.in | 20 +++- etc/init.d/zfs.arch | 58 ----------- etc/init.d/zfs.arch.in | 62 ++++++++++++ etc/init.d/zfs.fedora | 243 ---------------------------------------------- etc/init.d/zfs.fedora.in | 244 +++++++++++++++++++++++++++++++++++++++++++++++ etc/init.d/zfs.gentoo | 111 --------------------- etc/init.d/zfs.gentoo.in | 111 +++++++++++++++++++++ etc/init.d/zfs.lsb | 132 ------------------------- etc/init.d/zfs.lsb.in | 132 +++++++++++++++++++++++++ etc/init.d/zfs.lunar | 91 ------------------ etc/init.d/zfs.lunar.in | 95 ++++++++++++++++++ etc/init.d/zfs.redhat | 175 --------------------------------- etc/init.d/zfs.redhat.in | 176 ++++++++++++++++++++++++++++++++++ 15 files changed, 851 insertions(+), 813 deletions(-) delete mode 100644 etc/init.d/zfs.arch create mode 100644 etc/init.d/zfs.arch.in delete mode 100644 etc/init.d/zfs.fedora create mode 100644 etc/init.d/zfs.fedora.in delete mode 100644 etc/init.d/zfs.gentoo create mode 100644 etc/init.d/zfs.gentoo.in delete mode 100644 etc/init.d/zfs.lsb create mode 100644 etc/init.d/zfs.lsb.in delete mode 100644 etc/init.d/zfs.lunar create mode 100644 etc/init.d/zfs.lunar.in delete mode 100644 etc/init.d/zfs.redhat create mode 100644 etc/init.d/zfs.redhat.in diff --git a/configure b/configure index cb17d5cbc..f46cc5110 100755 --- a/configure +++ b/configure @@ -20562,7 +20562,7 @@ fi $as_echo "$enable_debug" >&6; } -ac_config_files="$ac_config_files Makefile dracut/Makefile dracut/90zfs/Makefile etc/Makefile etc/udev/Makefile etc/udev/rules.d/Makefile etc/init.d/Makefile etc/zfs/Makefile man/Makefile man/man8/Makefile lib/Makefile lib/libspl/Makefile lib/libspl/asm-generic/Makefile lib/libspl/asm-i386/Makefile lib/libspl/asm-x86_64/Makefile lib/libspl/include/Makefile lib/libspl/include/ia32/Makefile lib/libspl/include/ia32/sys/Makefile lib/libspl/include/rpc/Makefile lib/libspl/include/sys/Makefile lib/libspl/include/sys/sysevent/Makefile lib/libspl/include/sys/dktp/Makefile lib/libspl/include/util/Makefile lib/libavl/Makefile lib/libefi/Makefile lib/libnvpair/Makefile lib/libunicode/Makefile lib/libuutil/Makefile lib/libzpool/Makefile lib/libzfs/Makefile lib/libshare/Makefile cmd/Makefile cmd/zdb/Makefile cmd/zfs/Makefile cmd/zinject/Makefile cmd/zpool/Makefile cmd/ztest/Makefile cmd/zpios/Makefile cmd/mount_zfs/Makefile cmd/zpool_layout/Makefile cmd/zvol_id/Makefile cmd/zpool_id/Makefile cmd/sas_switch_id/Makefile module/Makefile module/avl/Makefile module/nvpair/Makefile module/unicode/Makefile module/zcommon/Makefile module/zfs/Makefile module/zpios/Makefile include/Makefile include/linux/Makefile include/sys/Makefile include/sys/fs/Makefile include/sys/fm/Makefile include/sys/fm/fs/Makefile scripts/Makefile scripts/zpios-profile/Makefile scripts/zpios-test/Makefile scripts/zpool-config/Makefile scripts/zpool-layout/Makefile scripts/common.sh zfs.spec zfs-modules.spec zfs-script-config.sh" +ac_config_files="$ac_config_files Makefile dracut/Makefile dracut/90zfs/Makefile etc/Makefile etc/udev/Makefile etc/udev/rules.d/Makefile etc/init.d/Makefile etc/init.d/zfs.arch etc/init.d/zfs.gentoo etc/init.d/zfs.lunar etc/init.d/zfs.fedora etc/init.d/zfs.lsb etc/init.d/zfs.redhat etc/zfs/Makefile man/Makefile man/man8/Makefile lib/Makefile lib/libspl/Makefile lib/libspl/asm-generic/Makefile lib/libspl/asm-i386/Makefile lib/libspl/asm-x86_64/Makefile lib/libspl/include/Makefile lib/libspl/include/ia32/Makefile lib/libspl/include/ia32/sys/Makefile lib/libspl/include/rpc/Makefile lib/libspl/include/sys/Makefile lib/libspl/include/sys/sysevent/Makefile lib/libspl/include/sys/dktp/Makefile lib/libspl/include/util/Makefile lib/libavl/Makefile lib/libefi/Makefile lib/libnvpair/Makefile lib/libunicode/Makefile lib/libuutil/Makefile lib/libzpool/Makefile lib/libzfs/Makefile lib/libshare/Makefile cmd/Makefile cmd/zdb/Makefile cmd/zfs/Makefile cmd/zinject/Makefile cmd/zpool/Makefile cmd/ztest/Makefile cmd/zpios/Makefile cmd/mount_zfs/Makefile cmd/zpool_layout/Makefile cmd/zvol_id/Makefile cmd/zpool_id/Makefile cmd/sas_switch_id/Makefile module/Makefile module/avl/Makefile module/nvpair/Makefile module/unicode/Makefile module/zcommon/Makefile module/zfs/Makefile module/zpios/Makefile include/Makefile include/linux/Makefile include/sys/Makefile include/sys/fs/Makefile include/sys/fm/Makefile include/sys/fm/fs/Makefile scripts/Makefile scripts/zpios-profile/Makefile scripts/zpios-test/Makefile scripts/zpool-config/Makefile scripts/zpool-layout/Makefile scripts/common.sh zfs.spec zfs-modules.spec zfs-script-config.sh" cat >confcache <<\_ACEOF @@ -21485,6 +21485,12 @@ do "etc/udev/Makefile") CONFIG_FILES="$CONFIG_FILES etc/udev/Makefile" ;; "etc/udev/rules.d/Makefile") CONFIG_FILES="$CONFIG_FILES etc/udev/rules.d/Makefile" ;; "etc/init.d/Makefile") CONFIG_FILES="$CONFIG_FILES etc/init.d/Makefile" ;; + "etc/init.d/zfs.arch") CONFIG_FILES="$CONFIG_FILES etc/init.d/zfs.arch" ;; + "etc/init.d/zfs.gentoo") CONFIG_FILES="$CONFIG_FILES etc/init.d/zfs.gentoo" ;; + "etc/init.d/zfs.lunar") CONFIG_FILES="$CONFIG_FILES etc/init.d/zfs.lunar" ;; + "etc/init.d/zfs.fedora") CONFIG_FILES="$CONFIG_FILES etc/init.d/zfs.fedora" ;; + "etc/init.d/zfs.lsb") CONFIG_FILES="$CONFIG_FILES etc/init.d/zfs.lsb" ;; + "etc/init.d/zfs.redhat") CONFIG_FILES="$CONFIG_FILES etc/init.d/zfs.redhat" ;; "etc/zfs/Makefile") CONFIG_FILES="$CONFIG_FILES etc/zfs/Makefile" ;; "man/Makefile") CONFIG_FILES="$CONFIG_FILES man/Makefile" ;; "man/man8/Makefile") CONFIG_FILES="$CONFIG_FILES man/man8/Makefile" ;; diff --git a/configure.ac b/configure.ac index fda9faf43..8afd0fcad 100644 --- a/configure.ac +++ b/configure.ac @@ -61,6 +61,12 @@ AC_CONFIG_FILES([ etc/udev/Makefile etc/udev/rules.d/Makefile etc/init.d/Makefile + etc/init.d/zfs.arch + etc/init.d/zfs.gentoo + etc/init.d/zfs.lunar + etc/init.d/zfs.fedora + etc/init.d/zfs.lsb + etc/init.d/zfs.redhat etc/zfs/Makefile man/Makefile man/man8/Makefile diff --git a/etc/init.d/Makefile.in b/etc/init.d/Makefile.in index 9763877d8..1ea6c623c 100644 --- a/etc/init.d/Makefile.in +++ b/etc/init.d/Makefile.in @@ -35,7 +35,10 @@ build_triplet = @build@ host_triplet = @host@ target_triplet = @target@ subdir = etc/init.d -DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in +DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in \ + $(srcdir)/zfs.arch.in $(srcdir)/zfs.fedora.in \ + $(srcdir)/zfs.gentoo.in $(srcdir)/zfs.lsb.in \ + $(srcdir)/zfs.lunar.in $(srcdir)/zfs.redhat.in ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = \ $(top_srcdir)/config/always-no-unused-but-set-variable.m4 \ @@ -83,7 +86,8 @@ am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) mkinstalldirs = $(install_sh) -d CONFIG_HEADER = $(top_builddir)/zfs_config.h -CONFIG_CLEAN_FILES = +CONFIG_CLEAN_FILES = zfs.arch zfs.gentoo zfs.lunar zfs.fedora zfs.lsb \ + zfs.redhat CONFIG_CLEAN_VPATH_FILES = AM_V_GEN = $(am__v_GEN_$(V)) am__v_GEN_ = $(am__v_GEN_$(AM_DEFAULT_VERBOSITY)) @@ -296,6 +300,18 @@ $(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) $(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(am__aclocal_m4_deps): +zfs.arch: $(top_builddir)/config.status $(srcdir)/zfs.arch.in + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ +zfs.gentoo: $(top_builddir)/config.status $(srcdir)/zfs.gentoo.in + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ +zfs.lunar: $(top_builddir)/config.status $(srcdir)/zfs.lunar.in + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ +zfs.fedora: $(top_builddir)/config.status $(srcdir)/zfs.fedora.in + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ +zfs.lsb: $(top_builddir)/config.status $(srcdir)/zfs.lsb.in + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ +zfs.redhat: $(top_builddir)/config.status $(srcdir)/zfs.redhat.in + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ mostlyclean-libtool: -rm -f *.lo diff --git a/etc/init.d/zfs.arch b/etc/init.d/zfs.arch deleted file mode 100644 index c0fb209a9..000000000 --- a/etc/init.d/zfs.arch +++ /dev/null @@ -1,58 +0,0 @@ -#!/bin/bash - -. /etc/rc.conf -. /etc/rc.d/functions - -case "$1" in - start) - stat_busy "Starting zfs" - - if [ ! -c /dev/zfs ]; then - modprobe zfs - if [ $? -ne 0 ]; then - stat_fail - exit 1 - fi - fi - - # Import ZFS pools (via cache file) - if [ -f /etc/zfs/zpool.cache ]; then - /usr/sbin/zpool import -c /etc/zfs/zpool.cache -aN 2>/dev/null - if [ $? -ne 0 ]; then - stat_fail - exit 1 - fi - fi - - # Mount ZFS filesystems - /usr/sbin/zfs mount -a - if [ $? -ne 0 ]; then - stat_fail - exit 1 - fi - - # Export ZFS flesystems - /usr/sbin/zfs share -a - if [ $? -ne 0 ]; then - stat_fail - exit 1 - fi - - add_daemon zfs - stat_done - ;; - stop) - stat_busy "Stopping zfs" - zfs umount -a - rm_daemon zfs - stat_done - ;; - restart) - $0 stop - $0 start - ;; - *) - echo "usage: $0 {start|stop|restart}" -esac - -exit 0 diff --git a/etc/init.d/zfs.arch.in b/etc/init.d/zfs.arch.in new file mode 100644 index 000000000..de2ea8a2d --- /dev/null +++ b/etc/init.d/zfs.arch.in @@ -0,0 +1,62 @@ +#!/bin/bash + +. /etc/rc.conf +. /etc/rc.d/functions + +ZFS="@sbindir@/zfs" +ZPOOL="@sbindir@/zpool" +ZPOOL_CACHE="@sysconfdir@/zfs/zpool.cache" + +case "$1" in + start) + stat_busy "Starting zfs" + + if [ ! -c /dev/zfs ]; then + modprobe zfs + if [ $? -ne 0 ]; then + stat_fail + exit 1 + fi + fi + + # Import ZFS pools (via cache file) + if [ -f $ZPOOL_CACHE ]; then + $ZPOOL import -c $ZPOOL_CACHE -aN 2>/dev/null + if [ $? -ne 0 ]; then + stat_fail + exit 1 + fi + fi + + # Mount ZFS filesystems + $ZFS mount -a + if [ $? -ne 0 ]; then + stat_fail + exit 1 + fi + + # Export ZFS flesystems + $ZFS share -a + if [ $? -ne 0 ]; then + stat_fail + exit 1 + fi + + add_daemon zfs + stat_done + ;; + stop) + stat_busy "Stopping zfs" + $ZFS umount -a + rm_daemon zfs + stat_done + ;; + restart) + $0 stop + $0 start + ;; + *) + echo "usage: $0 {start|stop|restart}" +esac + +exit 0 diff --git a/etc/init.d/zfs.fedora b/etc/init.d/zfs.fedora deleted file mode 100644 index 70b728106..000000000 --- a/etc/init.d/zfs.fedora +++ /dev/null @@ -1,243 +0,0 @@ -#!/bin/bash -# -# zfs This script will mount/umount the zfs filesystems. -# -# chkconfig: 2345 01 99 -# description: This script will mount/umount the zfs filesystems during -# system boot/shutdown. Configuration of which filesystems -# should be mounted is handled by the zfs 'mountpoint' and -# 'canmount' properties. See the zfs(8) man page for details. -# It is also responsible for all userspace zfs services. -# -### BEGIN INIT INFO -# Provides: zfs -# Required-Start: -# Required-Stop: -# Should-Start: -# Should-Stop: -# Default-Start: 2 3 4 5 -# Default-Stop: 1 -# Short-Description: Mount/umount the zfs filesystems -# Description: ZFS is an advanced filesystem designed to simplify managing -# and protecting your data. This service mounts the ZFS -# filesystems and starts all related zfs services. -### END INIT INFO - -export PATH=/usr/local/sbin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin - -# Source function library & LSB routines -. /etc/rc.d/init.d/functions - -# script variables -RETVAL=0 -ZPOOL=zpool -ZFS=zfs -servicename=zfs -LOCKFILE=/var/lock/subsys/$servicename - -# functions -zfs_installed() { - modinfo zfs > /dev/null 2>&1 || return 5 - $ZPOOL > /dev/null 2>&1 - [ $? == 127 ] && return 5 - $ZFS > /dev/null 2>&1 - [ $? == 127 ] && return 5 - return 0 -} - -reregister_mounts() { - cat /etc/mtab | while read -r fs mntpnt fstype opts rest ; do - fs=`printf '%b\n' "$fs"` - mntpnt=`printf '%b\n' "$mntpnt"` - if [ "$fstype" == "zfs" ] ; then - if [ "$mntpnt" == "/" ] ; then - mount -f -o zfsutil -t zfs --move / /removethismountpointhoweverpossible - umount --fake /removethismountpointhoweverpossible - else - umount --fake "$mntpnt" - fi - elif echo "$fs" | grep -q "^/dev/zd" ; then - if [ "$mntpnt" == "/" ] ; then - mount -f -t "$fstype" --move / /removethismountpointhoweverpossible - umount --fake /removethismountpointhoweverpossible - else - umount --fake "$mntpnt" - fi - fi - done - cat /proc/mounts | while read -r fs mntpnt fstype opts rest ; do - fs=`printf '%b\n' "$fs"` - mntpnt=`printf '%b\n' "$mntpnt"` - if [ "$fstype" == "zfs" ] ; then - mount -f -t zfs -o zfsutil "$fs" "$mntpnt" - elif echo "$fs" | grep -q "^/dev/zd" ; then - mount -f -t "$fstype" -o "$opts" "$fs" "$mntpnt" - fi - done -} - -# i need a bash guru to simplify this, since this is copy and paste, but donno how -# to correctly dereference variable names in bash, or how to do this right - -declare -A MTAB -declare -A FSTAB - -# first parameter is a regular expression that filters mtab -read_mtab() { - for fs in "${!MTAB[@]}" ; do unset MTAB["$fs"] ; done - while read -r fs mntpnt fstype opts blah ; do - fs=`printf '%b\n' "$fs"` - MTAB["$fs"]=$mntpnt - done < <(grep "$1" /etc/mtab) -} - -in_mtab() { - [ "${MTAB[$1]}" != "" ] - return $? -} - -# first parameter is a regular expression that filters fstab -read_fstab() { - for fs in "${!FSTAB[@]}" ; do unset FSTAB["$fs"] ; done - while read -r fs mntpnt fstype opts blah ; do - fs=`printf '%b\n' "$fs"` - FSTAB["$fs"]=$mntpnt - done < <(grep "$1" /etc/fstab) -} - -in_fstab() { - [ "${FSTAB[$1]}" != "" ] - return $? -} - -start() -{ - if [ -f "$LOCKFILE" ] ; then return 0 ; fi - - # check if ZFS is installed. If not, comply to FC standards and bail - zfs_installed || { - action $"Checking if ZFS is installed: not installed" /bin/false - return 5 - } - - # Requires selinux policy which has not been written. - if [ -r "/selinux/enforce" ] && - [ "$(cat /selinux/enforce)" = "1" ]; then - action $"SELinux ZFS policy required: " /bin/false || return 6 - fi - - # Delay until all required block devices are present. - udevadm settle - - # load kernel module infrastructure - if ! grep -q zfs /proc/modules ; then - action $"Loading kernel ZFS infrastructure: " modprobe zfs || return 5 - fi - - # fix mtab to include already-mounted fs filesystems, in case there are any - # we ONLY do this if mtab does not point to /proc/mounts - # which is the case in some systems (systemd may bring that soon) - if ! readlink /etc/mtab | grep -q /proc ; then - if grep -qE "(^/dev/zd| zfs )" /proc/mounts ; then - action $"Registering already-mounted ZFS filesystems and volumes: " reregister_mounts || return 150 - fi - fi - - if [ -f /etc/zfs/zpool.cache ] ; then - - echo -n $"Importing ZFS pools not yet imported: " - $ZPOOL import -c /etc/zfs/zpool.cache -aN || true # stupid zpool will fail if all pools are already imported - RETVAL=$? - if [ $RETVAL -ne 0 ]; then - failure "Importing ZFS pools not yet imported: " - return 151 - fi - success "Importing ZFS pools not yet imported: " - - fi - - action $"Mounting ZFS filesystems not yet mounted: " $ZFS mount -a || return 152 - - action $"Exporting ZFS filesystems: " $ZFS share -a || return 153 - - read_mtab "^/dev/zd" - read_fstab "^/dev/zd" - - template=$"Mounting volume %s registered in fstab: " - for volume in "${!FSTAB[@]}" ; do - if in_mtab "$volume" ; then continue ; fi - string=`printf "$template" "$volume"` - action "$string" mount "$volume" - done - - touch "$LOCKFILE" -} - -stop() -{ - if [ ! -f "$LOCKFILE" ] ; then return 0 ; fi - - # check if ZFS is installed. If not, comply to FC standards and bail - zfs_installed || { - action $"Checking if ZFS is installed: not installed" /bin/false - return 5 - } - - # the poweroff of the system takes care of this - # but it never unmounts the root filesystem itself - # shit - - action $"Syncing ZFS filesystems: " sync - # about the only thing we can do, and then we - # hope that the umount process will succeed - # unfortunately the umount process does not dismount - # the root file system, there ought to be some way - # we can tell zfs to just flush anything in memory - # when a request to remount,ro comes in - - #echo -n $"Unmounting ZFS filesystems: " - #$ZFS umount -a - #RETVAL=$? - #if [ $RETVAL -ne 0 ]; then - # failure - - # return 8 - #fi - #success - - rm -f "$LOCKFILE" -} - -# See how we are called -case "$1" in - start) - start - RETVAL=$? - ;; - stop) - stop - RETVAL=$? - ;; - status) - lsmod | grep -q zfs || RETVAL=3 - $ZPOOL status && echo && $ZFS list || { - [ -f "$LOCKFILE" ] && RETVAL=2 || RETVAL=4 - } - ;; - restart) - stop - start - ;; - condrestart) - if [ -f "$LOCKFILE" ] ; then - stop - start - fi - ;; - *) - echo $"Usage: $0 {start|stop|status|restart|condrestart}" - RETVAL=3 - ;; -esac - -exit $RETVAL diff --git a/etc/init.d/zfs.fedora.in b/etc/init.d/zfs.fedora.in new file mode 100644 index 000000000..04f2077ce --- /dev/null +++ b/etc/init.d/zfs.fedora.in @@ -0,0 +1,244 @@ +#!/bin/bash +# +# zfs This script will mount/umount the zfs filesystems. +# +# chkconfig: 2345 01 99 +# description: This script will mount/umount the zfs filesystems during +# system boot/shutdown. Configuration of which filesystems +# should be mounted is handled by the zfs 'mountpoint' and +# 'canmount' properties. See the zfs(8) man page for details. +# It is also responsible for all userspace zfs services. +# +### BEGIN INIT INFO +# Provides: zfs +# Required-Start: +# Required-Stop: +# Should-Start: +# Should-Stop: +# Default-Start: 2 3 4 5 +# Default-Stop: 1 +# Short-Description: Mount/umount the zfs filesystems +# Description: ZFS is an advanced filesystem designed to simplify managing +# and protecting your data. This service mounts the ZFS +# filesystems and starts all related zfs services. +### END INIT INFO + +export PATH=/usr/local/sbin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin + +# Source function library & LSB routines +. /etc/rc.d/init.d/functions + +# script variables +RETVAL=0 +ZFS="@sbindir@/zfs" +ZPOOL="@sbindir@/zpool" +ZPOOL_CACHE="@sysconfdir@/zfs/zpool.cache" +servicename=zfs +LOCKFILE=/var/lock/subsys/$servicename + +# functions +zfs_installed() { + modinfo zfs > /dev/null 2>&1 || return 5 + $ZPOOL > /dev/null 2>&1 + [ $? == 127 ] && return 5 + $ZFS > /dev/null 2>&1 + [ $? == 127 ] && return 5 + return 0 +} + +reregister_mounts() { + cat /etc/mtab | while read -r fs mntpnt fstype opts rest ; do + fs=`printf '%b\n' "$fs"` + mntpnt=`printf '%b\n' "$mntpnt"` + if [ "$fstype" == "zfs" ] ; then + if [ "$mntpnt" == "/" ] ; then + mount -f -o zfsutil -t zfs --move / /removethismountpointhoweverpossible + umount --fake /removethismountpointhoweverpossible + else + umount --fake "$mntpnt" + fi + elif echo "$fs" | grep -q "^/dev/zd" ; then + if [ "$mntpnt" == "/" ] ; then + mount -f -t "$fstype" --move / /removethismountpointhoweverpossible + umount --fake /removethismountpointhoweverpossible + else + umount --fake "$mntpnt" + fi + fi + done + cat /proc/mounts | while read -r fs mntpnt fstype opts rest ; do + fs=`printf '%b\n' "$fs"` + mntpnt=`printf '%b\n' "$mntpnt"` + if [ "$fstype" == "zfs" ] ; then + mount -f -t zfs -o zfsutil "$fs" "$mntpnt" + elif echo "$fs" | grep -q "^/dev/zd" ; then + mount -f -t "$fstype" -o "$opts" "$fs" "$mntpnt" + fi + done +} + +# i need a bash guru to simplify this, since this is copy and paste, but donno how +# to correctly dereference variable names in bash, or how to do this right + +declare -A MTAB +declare -A FSTAB + +# first parameter is a regular expression that filters mtab +read_mtab() { + for fs in "${!MTAB[@]}" ; do unset MTAB["$fs"] ; done + while read -r fs mntpnt fstype opts blah ; do + fs=`printf '%b\n' "$fs"` + MTAB["$fs"]=$mntpnt + done < <(grep "$1" /etc/mtab) +} + +in_mtab() { + [ "${MTAB[$1]}" != "" ] + return $? +} + +# first parameter is a regular expression that filters fstab +read_fstab() { + for fs in "${!FSTAB[@]}" ; do unset FSTAB["$fs"] ; done + while read -r fs mntpnt fstype opts blah ; do + fs=`printf '%b\n' "$fs"` + FSTAB["$fs"]=$mntpnt + done < <(grep "$1" /etc/fstab) +} + +in_fstab() { + [ "${FSTAB[$1]}" != "" ] + return $? +} + +start() +{ + if [ -f "$LOCKFILE" ] ; then return 0 ; fi + + # check if ZFS is installed. If not, comply to FC standards and bail + zfs_installed || { + action $"Checking if ZFS is installed: not installed" /bin/false + return 5 + } + + # Requires selinux policy which has not been written. + if [ -r "/selinux/enforce" ] && + [ "$(cat /selinux/enforce)" = "1" ]; then + action $"SELinux ZFS policy required: " /bin/false || return 6 + fi + + # Delay until all required block devices are present. + udevadm settle + + # load kernel module infrastructure + if ! grep -q zfs /proc/modules ; then + action $"Loading kernel ZFS infrastructure: " modprobe zfs || return 5 + fi + + # fix mtab to include already-mounted fs filesystems, in case there are any + # we ONLY do this if mtab does not point to /proc/mounts + # which is the case in some systems (systemd may bring that soon) + if ! readlink /etc/mtab | grep -q /proc ; then + if grep -qE "(^/dev/zd| zfs )" /proc/mounts ; then + action $"Registering already-mounted ZFS filesystems and volumes: " reregister_mounts || return 150 + fi + fi + + if [ -f $ZPOOL_CACHE ] ; then + + echo -n $"Importing ZFS pools not yet imported: " + $ZPOOL import -c $ZPOOL_CACHE -aN || true # stupid zpool will fail if all pools are already imported + RETVAL=$? + if [ $RETVAL -ne 0 ]; then + failure "Importing ZFS pools not yet imported: " + return 151 + fi + success "Importing ZFS pools not yet imported: " + + fi + + action $"Mounting ZFS filesystems not yet mounted: " $ZFS mount -a || return 152 + + action $"Exporting ZFS filesystems: " $ZFS share -a || return 153 + + read_mtab "^/dev/zd" + read_fstab "^/dev/zd" + + template=$"Mounting volume %s registered in fstab: " + for volume in "${!FSTAB[@]}" ; do + if in_mtab "$volume" ; then continue ; fi + string=`printf "$template" "$volume"` + action "$string" mount "$volume" + done + + touch "$LOCKFILE" +} + +stop() +{ + if [ ! -f "$LOCKFILE" ] ; then return 0 ; fi + + # check if ZFS is installed. If not, comply to FC standards and bail + zfs_installed || { + action $"Checking if ZFS is installed: not installed" /bin/false + return 5 + } + + # the poweroff of the system takes care of this + # but it never unmounts the root filesystem itself + # shit + + action $"Syncing ZFS filesystems: " sync + # about the only thing we can do, and then we + # hope that the umount process will succeed + # unfortunately the umount process does not dismount + # the root file system, there ought to be some way + # we can tell zfs to just flush anything in memory + # when a request to remount,ro comes in + + #echo -n $"Unmounting ZFS filesystems: " + #$ZFS umount -a + #RETVAL=$? + #if [ $RETVAL -ne 0 ]; then + # failure + + # return 8 + #fi + #success + + rm -f "$LOCKFILE" +} + +# See how we are called +case "$1" in + start) + start + RETVAL=$? + ;; + stop) + stop + RETVAL=$? + ;; + status) + lsmod | grep -q zfs || RETVAL=3 + $ZPOOL status && echo && $ZFS list || { + [ -f "$LOCKFILE" ] && RETVAL=2 || RETVAL=4 + } + ;; + restart) + stop + start + ;; + condrestart) + if [ -f "$LOCKFILE" ] ; then + stop + start + fi + ;; + *) + echo $"Usage: $0 {start|stop|status|restart|condrestart}" + RETVAL=3 + ;; +esac + +exit $RETVAL diff --git a/etc/init.d/zfs.gentoo b/etc/init.d/zfs.gentoo deleted file mode 100644 index f709ed9e7..000000000 --- a/etc/init.d/zfs.gentoo +++ /dev/null @@ -1,111 +0,0 @@ -#!/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() -{ - # bootmisc will log to /var which may be a different zfs than root. - before net bootmisc - after udev localmount - keyword -lxc -openvz -prefix -vserver -} - -CACHEFILE=/etc/zfs/zpool.cache -ZPOOL=/sbin/zpool -ZFS=/sbin/zfs -ZFS_MODULE=zfs - -checksystem() { - if [ ! -c /dev/zfs ]; then - einfo "Checking if ZFS modules present" - if [ "x$(modprobe -l $ZFS_MODULE | grep $ZFS_MODULE)" == "x" ]; then - eerror "$ZFS_MODULE not found. Is the ZFS package installed?" - return 1 - fi - fi - einfo "Checking if zfs userspace tools present" - if [ ! -x $ZPOOL ]; then - eerror "$ZPOOL binary not found." - return 1 - fi - if [ ! -x $ZFS ]; then - eerror "$ZFS binary not found." - return 1 - fi - return 0 -} - -start() { - ebegin "Starting ZFS" - checksystem || return 1 - - # Delay until all required block devices are present. - udevadm settle - - if [ ! -c /dev/zfs ]; then - modprobe $ZFS_MODULE - rv=$? - if [ $rv -ne 0 ]; then - eerror "Failed to load the $ZFS_MODULE module, check 'dmesg|tail'." - eend $rv - return $rv - fi - 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 - - einfo "Exporting ZFS filesystems" - $ZFS share -a - rv=$? - if [ $rv -ne 0 ]; then - eerror "Failed to export ZFS filesystems." - eend $rv - return $rv - fi - - eend 0 - return 0 -} - -stop() -{ - ebegin "Unmounting ZFS filesystems" - $ZFS umount -a - rv=$? - if [ $rv -ne 0 ]; then - einfo "Some ZFS filesystems not unmounted" - fi - - # Don't fail if we couldn't umount everything. /usr might be in use. - eend 0 - return 0 -} - -status() -{ - # show pool status and list - $ZPOOL status && echo && $ZPOOL list -} diff --git a/etc/init.d/zfs.gentoo.in b/etc/init.d/zfs.gentoo.in new file mode 100644 index 000000000..767aba8f9 --- /dev/null +++ b/etc/init.d/zfs.gentoo.in @@ -0,0 +1,111 @@ +#!/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() +{ + # bootmisc will log to /var which may be a different zfs than root. + before net bootmisc + after udev localmount + keyword -lxc -openvz -prefix -vserver +} + +ZFS="@sbindir@/zfs" +ZPOOL="@sbindir@/zpool" +ZPOOL_CACHE="@sysconfdir@/zfs/zpool.cache" +ZFS_MODULE=zfs + +checksystem() { + if [ ! -c /dev/zfs ]; then + einfo "Checking if ZFS modules present" + if [ "x$(modprobe -l $ZFS_MODULE | grep $ZFS_MODULE)" == "x" ]; then + eerror "$ZFS_MODULE not found. Is the ZFS package installed?" + return 1 + fi + fi + einfo "Checking if zfs userspace tools present" + if [ ! -x $ZPOOL ]; then + eerror "$ZPOOL binary not found." + return 1 + fi + if [ ! -x $ZFS ]; then + eerror "$ZFS binary not found." + return 1 + fi + return 0 +} + +start() { + ebegin "Starting ZFS" + checksystem || return 1 + + # Delay until all required block devices are present. + udevadm settle + + if [ ! -c /dev/zfs ]; then + modprobe $ZFS_MODULE + rv=$? + if [ $rv -ne 0 ]; then + eerror "Failed to load the $ZFS_MODULE module, check 'dmesg|tail'." + eend $rv + return $rv + fi + fi + + # Import all pools described by the cache file, and then mount + # all filesystem based on their properties. + if [ -f $ZPOOL_CACHE ]; 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 $ZPOOL_CACHE -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 + + einfo "Exporting ZFS filesystems" + $ZFS share -a + rv=$? + if [ $rv -ne 0 ]; then + eerror "Failed to export ZFS filesystems." + eend $rv + return $rv + fi + + eend 0 + return 0 +} + +stop() +{ + ebegin "Unmounting ZFS filesystems" + $ZFS umount -a + rv=$? + if [ $rv -ne 0 ]; then + einfo "Some ZFS filesystems not unmounted" + fi + + # Don't fail if we couldn't umount everything. /usr might be in use. + eend 0 + return 0 +} + +status() +{ + # show pool status and list + $ZPOOL status && echo && $ZPOOL list +} diff --git a/etc/init.d/zfs.lsb b/etc/init.d/zfs.lsb deleted file mode 100644 index ce541a9cd..000000000 --- a/etc/init.d/zfs.lsb +++ /dev/null @@ -1,132 +0,0 @@ -#!/bin/bash -# -# zfs This script will mount/umount the zfs filesystems. -# -# chkconfig: 2345 01 99 -# description: This script will mount/umount the zfs filesystems during -# system boot/shutdown. Configuration of which filesystems -# should be mounted is handled by the zfs 'mountpoint' and -# 'canmount' properties. See the zfs(8) man page for details. -# It is also responsible for all userspace zfs services. -# -### BEGIN INIT INFO -# Provides: zfs -# Required-Start: $local_fs -# Required-Stop: $local_fs -# Default-Start: 2 3 4 5 -# Default-Stop: 0 1 6 -# Should-Stop: -# Short-Description: Mount/umount the zfs filesystems -# Description: ZFS is an advanced filesystem designed to simplify managing -# and protecting your data. This service mounts the ZFS -# filesystems and starts all related zfs services. -### END INIT INFO - -# Source function library. -. /lib/lsb/init-functions - -# Source zfs configuration. -[ -f /etc/defaults/zfs ] && . /etc/defaults/zfs - -RETVAL=0 - -LOCKFILE=/var/lock/zfs -CACHEFILE=/etc/zfs/zpool.cache -ZPOOL=/sbin/zpool -ZFS=/sbin/zfs - -[ -x $ZPOOL ] || exit 1 -[ -x $ZFS ] || exit 2 - -start() -{ - [ -f $LOCKFILE ] && return 3 - - # Requires selinux policy which has not been written. - if [ -r "/selinux/enforce" ] && - [ "$(cat /selinux/enforce)" = "1" ]; then - - log_failure_msg "SELinux ZFS policy required" - return 4 - fi - - # Delay until all required block devices are present. - udevadm settle - - # Load the zfs module stack - /sbin/modprobe zfs - - # 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 - log_begin_msg "Importing ZFS pools" - $ZPOOL import -c $CACHEFILE -aN 2>/dev/null - log_end_msg $? - - log_begin_msg "Mounting ZFS filesystems" - $ZFS mount -a - log_end_msg $? - - log_begin_msg "Exporting ZFS filesystems" - $ZFS share -a - log_end_msg $? - fi - - touch $LOCKFILE -} - -stop() -{ - [ ! -f $LOCKFILE ] && return 3 - - log_begin_msg "Unmounting ZFS filesystems" - $ZFS umount -a - log_end_msg $? - - rm -f $LOCKFILE -} - -status() -{ - [ ! -f $LOCKFILE ] && return 3 - - $ZPOOL status && echo && $ZPOOL list -} - -case "$1" in - start) - start - RETVAL=$? - ;; - stop) - stop - RETVAL=$? - ;; - status) - status - RETVAL=$? - ;; - restart) - stop - start - ;; - condrestart) - if [ -f $LOCKFILE ]; then - stop - start - fi - ;; - *) - echo $"Usage: $0 {start|stop|status|restart|condrestart}" - ;; -esac - -exit $RETVAL diff --git a/etc/init.d/zfs.lsb.in b/etc/init.d/zfs.lsb.in new file mode 100644 index 000000000..c781f05f4 --- /dev/null +++ b/etc/init.d/zfs.lsb.in @@ -0,0 +1,132 @@ +#!/bin/bash +# +# zfs This script will mount/umount the zfs filesystems. +# +# chkconfig: 2345 01 99 +# description: This script will mount/umount the zfs filesystems during +# system boot/shutdown. Configuration of which filesystems +# should be mounted is handled by the zfs 'mountpoint' and +# 'canmount' properties. See the zfs(8) man page for details. +# It is also responsible for all userspace zfs services. +# +### BEGIN INIT INFO +# Provides: zfs +# Required-Start: $local_fs +# Required-Stop: $local_fs +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Should-Stop: +# Short-Description: Mount/umount the zfs filesystems +# Description: ZFS is an advanced filesystem designed to simplify managing +# and protecting your data. This service mounts the ZFS +# filesystems and starts all related zfs services. +### END INIT INFO + +# Source function library. +. /lib/lsb/init-functions + +# Source zfs configuration. +[ -f /etc/defaults/zfs ] && . /etc/defaults/zfs + +RETVAL=0 + +LOCKFILE=/var/lock/zfs +ZFS="@sbindir@/zfs" +ZPOOL="@sbindir@/zpool" +ZPOOL_CACHE="@sysconfdir@/zfs/zpool.cache" + +[ -x $ZPOOL ] || exit 1 +[ -x $ZFS ] || exit 2 + +start() +{ + [ -f $LOCKFILE ] && return 3 + + # Requires selinux policy which has not been written. + if [ -r "/selinux/enforce" ] && + [ "$(cat /selinux/enforce)" = "1" ]; then + + log_failure_msg "SELinux ZFS policy required" + return 4 + fi + + # Delay until all required block devices are present. + udevadm settle + + # Load the zfs module stack + /sbin/modprobe zfs + + # 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 $ZPOOL_CACHE ] ; then + log_begin_msg "Importing ZFS pools" + $ZPOOL import -c $ZPOOL_CACHE -aN 2>/dev/null + log_end_msg $? + + log_begin_msg "Mounting ZFS filesystems" + $ZFS mount -a + log_end_msg $? + + log_begin_msg "Exporting ZFS filesystems" + $ZFS share -a + log_end_msg $? + fi + + touch $LOCKFILE +} + +stop() +{ + [ ! -f $LOCKFILE ] && return 3 + + log_begin_msg "Unmounting ZFS filesystems" + $ZFS umount -a + log_end_msg $? + + rm -f $LOCKFILE +} + +status() +{ + [ ! -f $LOCKFILE ] && return 3 + + $ZPOOL status && echo && $ZPOOL list +} + +case "$1" in + start) + start + RETVAL=$? + ;; + stop) + stop + RETVAL=$? + ;; + status) + status + RETVAL=$? + ;; + restart) + stop + start + ;; + condrestart) + if [ -f $LOCKFILE ]; then + stop + start + fi + ;; + *) + echo $"Usage: $0 {start|stop|status|restart|condrestart}" + ;; +esac + +exit $RETVAL diff --git a/etc/init.d/zfs.lunar b/etc/init.d/zfs.lunar deleted file mode 100644 index bdc461af8..000000000 --- a/etc/init.d/zfs.lunar +++ /dev/null @@ -1,91 +0,0 @@ -#!/bin/bash -# -# zfs This shell script takes care of starting (mount) and -# stopping (umount) zfs shares. -# -# chkconfig: 35 60 40 -# description: ZFS is a filesystem developed by Sun, ZFS is a -# combined file system and logical volume manager -# designed by Sun Microsystems. Made available to Linux -# using SPL (Solaris Porting Layer) by zfsonlinux.org. -# probe: true - -case $1 in - start) echo "$1ing ZFS filesystems" - - # Delay until all required block devices are present. - udevadm settle - - if ! grep "zfs" /proc/modules > /dev/null; then - echo "ZFS kernel module not loaded yet; loading..."; - if ! modprobe zfs; then - echo "Failed to load ZFS kernel module..."; - exit 0; - fi - fi - - if ! [ `uname -m` == "x86_64" ]; then - echo "Warning: You're not running 64bit. Currently native zfs in"; - echo " linux is only supported and tested on 64bit."; - # should we break here? People doing this should know what they - # do, thus i'm not breaking here. - fi - - # mount the filesystems - while IFS= read -r -d $'\n' dev; do - mdev=$(echo "$dev" | awk '{ print $1; }') - echo -n "mounting $mdev..." - if zfs mount $mdev; then - echo -e "done"; - else - echo -e "failed"; - fi - done < <(zfs list -H); - - # export the filesystems - echo -n "exporting ZFS filesystems..." - if zfs share -a; then - echo -e "done"; - else - echo -e "failed"; - fi - - - ;; - - stop) echo "$1ping ZFS filesystems" - - if grep "zfs" /proc/modules > /dev/null; then - # module is loaded, so we can try to umount filesystems - while IFS= read -r -d $'\n' dev; do - mdev=$(echo "$dev" | awk '{ print $1 }'); - echo -n "umounting $mdev..."; - if zfs umount $mdev; then - echo -e "done"; - else - echo -e "failed"; - fi - # the next line is, because i have to reverse the - # output, otherwise it wouldn't work as it should - done < <(zfs list -H | tac); - - # and finally let's rmmod the module - rmmod zfs - - - else - # module not loaded, no need to umount anything - exit 0 - fi - - ;; - - restart) echo "$1ing ZFS filesystems" - $0 stop - $0 start - ;; - - *) echo "Usage: $0 {start|stop|restart}" - ;; - -esac diff --git a/etc/init.d/zfs.lunar.in b/etc/init.d/zfs.lunar.in new file mode 100644 index 000000000..97384dc83 --- /dev/null +++ b/etc/init.d/zfs.lunar.in @@ -0,0 +1,95 @@ +#!/bin/bash +# +# zfs This shell script takes care of starting (mount) and +# stopping (umount) zfs shares. +# +# chkconfig: 35 60 40 +# description: ZFS is a filesystem developed by Sun, ZFS is a +# combined file system and logical volume manager +# designed by Sun Microsystems. Made available to Linux +# using SPL (Solaris Porting Layer) by zfsonlinux.org. +# probe: true + +ZFS="@sbindir@/zfs" +ZPOOL="@sbindir@/zpool" +ZPOOL_CACHE="@sysconfdir@/zfs/zpool.cache" + +case $1 in + start) echo "$1ing ZFS filesystems" + + # Delay until all required block devices are present. + udevadm settle + + if ! grep "zfs" /proc/modules > /dev/null; then + echo "ZFS kernel module not loaded yet; loading..."; + if ! modprobe zfs; then + echo "Failed to load ZFS kernel module..."; + exit 0; + fi + fi + + if ! [ `uname -m` == "x86_64" ]; then + echo "Warning: You're not running 64bit. Currently native zfs in"; + echo " linux is only supported and tested on 64bit."; + # should we break here? People doing this should know what they + # do, thus i'm not breaking here. + fi + + # mount the filesystems + while IFS= read -r -d $'\n' dev; do + mdev=$(echo "$dev" | awk '{ print $1; }') + echo -n "mounting $mdev..." + if $ZFS mount $mdev; then + echo -e "done"; + else + echo -e "failed"; + fi + done < <($ZFS list -H); + + # export the filesystems + echo -n "exporting ZFS filesystems..." + if $ZFS share -a; then + echo -e "done"; + else + echo -e "failed"; + fi + + + ;; + + stop) echo "$1ping ZFS filesystems" + + if grep "zfs" /proc/modules > /dev/null; then + # module is loaded, so we can try to umount filesystems + while IFS= read -r -d $'\n' dev; do + mdev=$(echo "$dev" | awk '{ print $1 }'); + echo -n "umounting $mdev..."; + if $ZFS umount $mdev; then + echo -e "done"; + else + echo -e "failed"; + fi + # the next line is, because i have to reverse the + # output, otherwise it wouldn't work as it should + done < <($ZFS list -H | tac); + + # and finally let's rmmod the module + rmmod zfs + + + else + # module not loaded, no need to umount anything + exit 0 + fi + + ;; + + restart) echo "$1ing ZFS filesystems" + $0 stop + $0 start + ;; + + *) echo "Usage: $0 {start|stop|restart}" + ;; + +esac diff --git a/etc/init.d/zfs.redhat b/etc/init.d/zfs.redhat deleted file mode 100644 index d3475f09d..000000000 --- a/etc/init.d/zfs.redhat +++ /dev/null @@ -1,175 +0,0 @@ -#!/bin/bash -# -# zfs This script will mount/umount the zfs filesystems. -# -# chkconfig: 2345 01 99 -# description: This script will mount/umount the zfs filesystems during -# system boot/shutdown. Configuration of which filesystems -# should be mounted is handled by the zfs 'mountpoint' and -# 'canmount' properties. See the zfs(8) man page for details. -# It is also responsible for all userspace zfs services. -# -### BEGIN INIT INFO -# Provides: zfs -# Required-Start: -# Required-Stop: -# Should-Start: -# Should-Stop: -# Default-Start: 2 3 4 5 -# Default-Stop: 1 -# Short-Description: Mount/umount the zfs filesystems -# Description: ZFS is an advanced filesystem designed to simplify managing -# and protecting your data. This service mounts the ZFS -# filesystems and starts all related zfs services. -### END INIT INFO - -export PATH=/usr/local/sbin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin - -# Source function library & LSB routines -. /etc/rc.d/init.d/functions - -# script variables -RETVAL=0 -ZPOOL=zpool -ZFS=zfs -servicename=zfs -LOCKFILE=/var/lock/subsys/$servicename - -# functions -zfs_installed() { - modinfo zfs > /dev/null 2>&1 || return 5 - $ZPOOL > /dev/null 2>&1 - [ $? == 127 ] && return 5 - $ZFS > /dev/null 2>&1 - [ $? == 127 ] && return 5 - return 0 -} - -# i need a bash guru to simplify this, since this is copy and paste, but donno how -# to correctly dereference variable names in bash, or how to do this right - -# first parameter is a regular expression that filters fstab -read_fstab() { - unset FSTAB - n=0 - while read -r fs mntpnt fstype opts blah ; do - fs=`printf '%b\n' "$fs"` - FSTAB[$n]=$fs - let n++ - done < <(egrep "$1" /etc/fstab) -} - -start() -{ - # Disable lockfile check - # if [ -f "$LOCKFILE" ] ; then return 0 ; fi - - # check if ZFS is installed. If not, comply to FC standards and bail - zfs_installed || { - action $"Checking if ZFS is installed: not installed" /bin/false - return 5 - } - - # Requires selinux policy which has not been written. - if [ -r "/selinux/enforce" ] && - [ "$(cat /selinux/enforce)" = "1" ]; then - action $"SELinux ZFS policy required: " /bin/false || return 6 - fi - - # Delay until all required block devices are present. - if [ -x /sbin/udevadm ]; then - /sbin/udevadm settle - elif [ -x /sbin/udevsettle ]; then - /sbin/udevsettle - fi - - # load kernel module infrastructure - if ! grep -q zfs /proc/modules ; then - action $"Loading kernel ZFS infrastructure: " modprobe zfs || return 5 - fi - sleep 1 - - action $"Mounting automounted ZFS filesystems: " $ZFS mount -a || return 152 - - action $"Exporting ZFS filesystems: " $ZFS share -a || return 153 - - # Read fstab, try to mount zvols ignoring error - read_fstab "^/dev/(zd|zvol)" - template=$"Mounting volume %s registered in fstab: " - for volume in "${FSTAB[@]}" ; do - string=`printf "$template" "$volume"` - action "$string" mount "$volume" 2>/dev/null || /bin/true - done - - # touch "$LOCKFILE" -} - -stop() -{ - # Disable lockfile check - # if [ ! -f "$LOCKFILE" ] ; then return 0 ; fi - - # check if ZFS is installed. If not, comply to FC standards and bail - zfs_installed || { - action $"Checking if ZFS is installed: not installed" /bin/false - return 5 - } - - # the poweroff of the system takes care of this - # but it never unmounts the root filesystem itself - # shit - - action $"Syncing ZFS filesystems: " sync - # about the only thing we can do, and then we - # hope that the umount process will succeed - # unfortunately the umount process does not dismount - # the root file system, there ought to be some way - # we can tell zfs to just flush anything in memory - # when a request to remount,ro comes in - - #echo -n $"Unmounting ZFS filesystems: " - #$ZFS umount -a - #RETVAL=$? - #if [ $RETVAL -ne 0 ]; then - # failure - - # return 8 - #fi - #success - - rm -f "$LOCKFILE" -} - -# See how we are called -case "$1" in - start) - start - RETVAL=$? - ;; - stop) - stop - RETVAL=$? - ;; - status) - lsmod | grep -q zfs || RETVAL=3 - $ZPOOL status && echo && $ZFS list || { - [ -f "$LOCKFILE" ] && RETVAL=2 || RETVAL=4 - } - ;; - restart) - stop - start - ;; - condrestart) - if [ -f "$LOCKFILE" ] ; then - stop - start - fi - ;; - *) - echo $"Usage: $0 {start|stop|status|restart|condrestart}" - RETVAL=3 - ;; -esac - -exit $RETVAL diff --git a/etc/init.d/zfs.redhat.in b/etc/init.d/zfs.redhat.in new file mode 100644 index 000000000..ae797c11a --- /dev/null +++ b/etc/init.d/zfs.redhat.in @@ -0,0 +1,176 @@ +#!/bin/bash +# +# zfs This script will mount/umount the zfs filesystems. +# +# chkconfig: 2345 01 99 +# description: This script will mount/umount the zfs filesystems during +# system boot/shutdown. Configuration of which filesystems +# should be mounted is handled by the zfs 'mountpoint' and +# 'canmount' properties. See the zfs(8) man page for details. +# It is also responsible for all userspace zfs services. +# +### BEGIN INIT INFO +# Provides: zfs +# Required-Start: +# Required-Stop: +# Should-Start: +# Should-Stop: +# Default-Start: 2 3 4 5 +# Default-Stop: 1 +# Short-Description: Mount/umount the zfs filesystems +# Description: ZFS is an advanced filesystem designed to simplify managing +# and protecting your data. This service mounts the ZFS +# filesystems and starts all related zfs services. +### END INIT INFO + +export PATH=/usr/local/sbin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin + +# Source function library & LSB routines +. /etc/rc.d/init.d/functions + +# script variables +RETVAL=0 +ZFS="@sbindir@/zfs" +ZPOOL="@sbindir@/zpool" +ZPOOL_CACHE="@sysconfdir@/zfs/zpool.cache" +servicename=zfs +LOCKFILE=/var/lock/subsys/$servicename + +# functions +zfs_installed() { + modinfo zfs > /dev/null 2>&1 || return 5 + $ZPOOL > /dev/null 2>&1 + [ $? == 127 ] && return 5 + $ZFS > /dev/null 2>&1 + [ $? == 127 ] && return 5 + return 0 +} + +# i need a bash guru to simplify this, since this is copy and paste, but donno how +# to correctly dereference variable names in bash, or how to do this right + +# first parameter is a regular expression that filters fstab +read_fstab() { + unset FSTAB + n=0 + while read -r fs mntpnt fstype opts blah ; do + fs=`printf '%b\n' "$fs"` + FSTAB[$n]=$fs + let n++ + done < <(egrep "$1" /etc/fstab) +} + +start() +{ + # Disable lockfile check + # if [ -f "$LOCKFILE" ] ; then return 0 ; fi + + # check if ZFS is installed. If not, comply to FC standards and bail + zfs_installed || { + action $"Checking if ZFS is installed: not installed" /bin/false + return 5 + } + + # Requires selinux policy which has not been written. + if [ -r "/selinux/enforce" ] && + [ "$(cat /selinux/enforce)" = "1" ]; then + action $"SELinux ZFS policy required: " /bin/false || return 6 + fi + + # Delay until all required block devices are present. + if [ -x /sbin/udevadm ]; then + /sbin/udevadm settle + elif [ -x /sbin/udevsettle ]; then + /sbin/udevsettle + fi + + # load kernel module infrastructure + if ! grep -q zfs /proc/modules ; then + action $"Loading kernel ZFS infrastructure: " modprobe zfs || return 5 + fi + sleep 1 + + action $"Mounting automounted ZFS filesystems: " $ZFS mount -a || return 152 + + action $"Exporting ZFS filesystems: " $ZFS share -a || return 153 + + # Read fstab, try to mount zvols ignoring error + read_fstab "^/dev/(zd|zvol)" + template=$"Mounting volume %s registered in fstab: " + for volume in "${FSTAB[@]}" ; do + string=`printf "$template" "$volume"` + action "$string" mount "$volume" 2>/dev/null || /bin/true + done + + # touch "$LOCKFILE" +} + +stop() +{ + # Disable lockfile check + # if [ ! -f "$LOCKFILE" ] ; then return 0 ; fi + + # check if ZFS is installed. If not, comply to FC standards and bail + zfs_installed || { + action $"Checking if ZFS is installed: not installed" /bin/false + return 5 + } + + # the poweroff of the system takes care of this + # but it never unmounts the root filesystem itself + # shit + + action $"Syncing ZFS filesystems: " sync + # about the only thing we can do, and then we + # hope that the umount process will succeed + # unfortunately the umount process does not dismount + # the root file system, there ought to be some way + # we can tell zfs to just flush anything in memory + # when a request to remount,ro comes in + + #echo -n $"Unmounting ZFS filesystems: " + #$ZFS umount -a + #RETVAL=$? + #if [ $RETVAL -ne 0 ]; then + # failure + + # return 8 + #fi + #success + + rm -f "$LOCKFILE" +} + +# See how we are called +case "$1" in + start) + start + RETVAL=$? + ;; + stop) + stop + RETVAL=$? + ;; + status) + lsmod | grep -q zfs || RETVAL=3 + $ZPOOL status && echo && $ZFS list || { + [ -f "$LOCKFILE" ] && RETVAL=2 || RETVAL=4 + } + ;; + restart) + stop + start + ;; + condrestart) + if [ -f "$LOCKFILE" ] ; then + stop + start + fi + ;; + *) + echo $"Usage: $0 {start|stop|status|restart|condrestart}" + RETVAL=3 + ;; +esac + +exit $RETVAL -- cgit v1.2.3