Skip to content

Commit

Permalink
Base init scripts for SYSV systems
Browse files Browse the repository at this point in the history
* Based on the init scripts included with Debian GNU/Linux, then take code
  from the already existing ones, trying to merge them into one set of
  scripts that will work for 'everyone' for better maintainability.
  * Add configurable variables to control the workings of the init scripts:
    * ZFS_INITRD_PRE_MOUNTROOT_SLEEP
      Set a sleep time before we load the module (used primarily by initrd
      scripts to allow for slower media (such as  USB devices etc) to be
      availible before we load the zfs module).
    * ZFS_INITRD_POST_MODPROBE_SLEEP
      Set a timed sleep in the initrd to after the load of the zfs module.
    * ZFS_INITRD_ADDITIONAL_DATASETS
      To allow for mounting additional datasets in the initrd. Primarily used
      in initrd scripts to allow for when filesystem needed to boot (such as
      /usr, /opt, /var etc) isn't directly under the root dataset.
    * ZFS_POOL_EXCEPTIONS
      Exclude pools from being imported (in the initrd and/or init scripts).
    * ZFS_DKMS_ENABLE_DEBUG, ZFS_DKMS_ENABLE_DEBUG_DMU_TX, ZFS_DKMS_DISABLE_STRIP
      Set to control how dkms should build the dkms packages.
    * ZPOOL_IMPORT_PATH
      Set path(s) where "zpool import" should import pools from.
      This was previously the job of "USE_DISK_BY_ID" (which is still used
      for backwards compatibility) but was renamed to allow for better
      control of import path(s).
      * If old USE_DISK_BY_ID is set, but not new ZPOOL_IMPORT_PATH, then we
        set ZPOOL_IMPORT_PATH to sane defaults just to be on the safe side.
    * ZED_ARGS
      To allow for local options to zed without having to change the init script.
  * The import function, do_import(), imports pools by name instead of '-a'
    for better control of pools to import and from where.
    * If USE_DISK_BY_ID is set (for backwards compatibility), but isn't 'yes'
      then ignore it.
    * If pool(s) isn't found with a simple "zpool import" (seen it happen),
      try looking for them in /dev/disk/by-id (if it exists). Any duplicates
      (pools found with both commands) is filtered out.
      * IF we have found extra pool(s) this way, we must force USE_DISK_BY_ID
        so that the first, simple "zpool import $pool" is able to find it.
    * Fallback on importing the pool using the cache file (if it exists) only
      if 'simple' import (either with ZPOOL_IMPORT_PATH or the 'built in'
      defaults) didn't work.
  * The export function, do_export(), will export all pools imported, EXCEPT
    the root pool (if there is one).
  * ZED script from the Debian GNU/Linux packages added.
    * Refreshed ZED init script from behlendorf/zfs@5e7a660 to be portable so it
      may be used on both LSB and Redhat style systems.
    * If there is no pool(s) imported and zed successfully shut down, we will
      unload the zfs modules.
  * The function library file for the ZoL init script is installed as
    /etc/init.d/zfs-functions.
  * The four init scripts, the /etc/{defaults,sysconfig,conf.d}/zfs config file
    as well as the common function library is tagged as '%config(noreplace)' in
    the rpm rules file to make sure they are not replaced automatically if locally
    modifed.
  * Pitfals and workarounds:
    * If we're running from init, remove stale /etc/dfs/sharetab before importing
      pools in the zfs-import init script.
    * On Debian GNU/Linux, there's a 'sendsigs' script that will kill basically
      everything quite early in the shutdown phase and zed is/should be stopped
      much later than that. We don't want zed to be among the ones killed, so add
      the zed pid to list of pids for 'sendsigs' to ignore.
    * CentOS uses echo_success() and echo_failure() to print out status of
      command. These in turn uses "echo -n \0xx[etc]" to move cursor and choose
      colour etc. This doesn't work with the modified IFS variable we need to
      use in zfs-import for some reason, so work around that when we define
      zfs_log_{end,failure}_msg() for RedHat and derivative distributions.
  * All scripts passes ShellCheck (with one false positive in do_mount()).

Signed-off-by: Turbo Fredriksson [email protected]
Signed-off-by: Brian Behlendorf <[email protected]>
Reviewed by: Richard Yao <[email protected]>
Reviewed by: Chris Dunlap <[email protected]>
Closes #2974
Closes #2107
  • Loading branch information
FransUrbo authored and behlendorf committed May 28, 2015
1 parent 544f718 commit 2a34db1
Show file tree
Hide file tree
Showing 16 changed files with 1,473 additions and 792 deletions.
17 changes: 16 additions & 1 deletion config/zfs-build.m4
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ AC_DEFUN([ZFS_AC_RPM], [
])
RPM_DEFINE_COMMON='--define "$(DEBUG_ZFS) 1" --define "$(DEBUG_DMU_TX) 1"'
RPM_DEFINE_UTIL='--define "_dracutdir $(dracutdir)" --define "_udevdir $(udevdir)" --define "_udevruledir $(udevruledir)"'
RPM_DEFINE_UTIL='--define "_dracutdir $(dracutdir)" --define "_udevdir $(udevdir)" --define "_udevruledir $(udevruledir)" --define "_initconfdir $(DEFAULT_INITCONF_DIR)"'
RPM_DEFINE_KMOD='--define "kernels $(LINUX_VERSION)" --define "require_spldir $(SPL)" --define "require_splobj $(SPL_OBJ)" --define "ksrc $(LINUX)" --define "kobj $(LINUX_OBJ)"'
RPM_DEFINE_DKMS=
Expand Down Expand Up @@ -311,6 +311,21 @@ AC_DEFUN([ZFS_AC_DEFAULT_PACKAGE], [
AC_MSG_RESULT([$DEFAULT_INIT_SCRIPT])
AC_SUBST(DEFAULT_INIT_SCRIPT)
AC_MSG_CHECKING([default init config direectory])
case "$VENDOR" in
gentoo) DEFAULT_INITCONF_DIR=/etc/conf.d ;;
toss) DEFAULT_INITCONF_DIR=/etc/sysconfig ;;
redhat) DEFAULT_INITCONF_DIR=/etc/sysconfig ;;
fedora) DEFAULT_INITCONF_DIR=/etc/sysconfig ;;
sles) DEFAULT_INITCONF_DIR=/etc/sysconfig ;;
ubuntu) DEFAULT_INITCONF_DIR=/etc/default ;;
debian) DEFAULT_INITCONF_DIR=/etc/default ;;
*) DEFAULT_INITCONF_DIR=/etc/default ;;
esac
AC_MSG_RESULT([$DEFAULT_INITCONF_DIR])
AC_SUBST(DEFAULT_INITCONF_DIR)
])

dnl #
Expand Down
5 changes: 5 additions & 0 deletions etc/init.d/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
zfs-functions
zfs-import
zfs-mount
zfs-share
zfs-zed
zfs
54 changes: 38 additions & 16 deletions etc/init.d/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,22 +1,44 @@
initdir = $(DEFAULT_INIT_DIR)
init_SCRIPTS = zfs
init_SCRIPTS = zfs-import zfs-mount zfs-share zfs-zed

initcommondir = $(sysconfdir)/zfs
initcommon_SCRIPTS = zfs-functions

initconfdir = $(DEFAULT_INITCONF_DIR)
initconf_SCRIPTS = zfs

EXTRA_DIST = \
$(top_srcdir)/etc/init.d/zfs.fedora.in \
$(top_srcdir)/etc/init.d/zfs.gentoo.in \
$(top_srcdir)/etc/init.d/zfs.lsb.in \
$(top_srcdir)/etc/init.d/zfs.lunar.in \
$(top_srcdir)/etc/init.d/zfs.redhat.in
$(top_srcdir)/etc/init.d/zfs-functions.in \
$(top_srcdir)/etc/init.d/zfs-share.in \
$(top_srcdir)/etc/init.d/zfs-import.in \
$(top_srcdir)/etc/init.d/zfs-mount.in \
$(top_srcdir)/etc/init.d/zfs-zed.in \
$(top_srcdir)/etc/init.d/zfs.in

$(init_SCRIPTS): $(init_SCRIPTS).$(DEFAULT_INIT_SCRIPT).in
-$(SED) -e 's,@bindir\@,$(bindir),g' \
-e 's,@sbindir\@,$(sbindir),g' \
-e 's,@udevdir\@,$(udevdir),g' \
-e 's,@udevruledir\@,$(udevruledir),g' \
-e 's,@sysconfdir\@,$(sysconfdir),g' \
-e 's,@initdir\@,$(initdir),g' \
-e 's,@runstatedir\@,$(runstatedir),g' \
'$@.$(DEFAULT_INIT_SCRIPT).in' >'$@'
$(init_SCRIPTS) $(initconf_SCRIPTS) $(initcommon_SCRIPTS):
-(if [ -e /etc/debian_version ]; then \
NFS_SRV=nfs-kernel-server; \
else \
NFS_SRV=nfs; \
fi; \
if [ -e /etc/gentoo-release ]; then \
SHELL=/sbin/runscript; \
else \
SHELL=/bin/sh; \
fi; \
$(SED) -e 's,@bindir\@,$(bindir),g' \
-e 's,@sbindir\@,$(sbindir),g' \
-e 's,@udevdir\@,$(udevdir),g' \
-e 's,@udevruledir\@,$(udevruledir),g' \
-e 's,@sysconfdir\@,$(sysconfdir),g' \
-e 's,@initconfdir\@,$(initconfdir),g' \
-e 's,@initdir\@,$(initdir),g' \
-e 's,@runstatedir\@,$(runstatedir),g' \
-e "s,@SHELL\@,$$SHELL,g" \
-e "s,@NFS_SRV\@,$$NFS_SRV,g" \
'[email protected]' >'$@'; \
[ '$@' = 'zfs-functions' -o '$@' = 'zfs' ] || \
chmod +x '$@')

distclean-local::
-$(RM) $(init_SCRIPTS)
-$(RM) $(init_SCRIPTS) $(initcommon_SCRIPTS) $(initconf_SCRIPTS)
77 changes: 77 additions & 0 deletions etc/init.d/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
DESCRIPTION
These script were written with the primary intention of being portable and
usable on as many systems as possible.

This is, in practice, usually not possible. But the intention is there.
And it is a good one.

They have been tested successfully on:

* Debian GNU/Linux Wheezy
* Debian GNU/Linux Jessie
* Ubuntu Trusty
* CentOS 6.0
* CentOS 6.6
* Gentoo

SUPPORT
If you find that they don't work for your platform, please report this
at the ZFS On Linux issue tracker at https://github.com/zfsonlinux/zfs/issues.

Please include:

* Distribution name
* Distribution version
* Where to find an install CD image
* Architecture

If you have code to share that fixes the problem, that is much better.
But please remember to try your best keep portability in mind. If you
suspect that what you're writing/modifying won't work on anything else
than your distribution, please make sure to put that code in appropriate
if/else/fi code.

It currently MUST be bash (or fully compatible) for this to work.

If you're making your own distribution and you want the scripts to
work on that, the biggest problem you'll (probably) have is the part
at the beginning of the "zfs-functions.in" file which sets up the
logging output.

INSTALLING INIT SCRIPT LINKS
To setup the init script links in /etc/rc?.d manually on a Debian GNU/Linux
(or derived) system, run the following commands (the order is important!):

update-rc.d zfs-zed start 07 S . stop 08 0 1 6 .
update-rc.d zfs-import start 07 S . stop 07 0 1 6 .
update-rc.d zfs-mount start 02 2 3 4 5 . stop 06 0 1 6 .
update-rc.d zfs-share start 27 2 3 4 5 . stop 05 0 1 6 .

To do the same on RedHat, Fedora and/or CentOS:

chkconfig zfs-zed
chkconfig zfs-import
chkconfig zfs-mount
chkconfig zfs-share

On Gentoo:

rc-update add zfs-zed boot
rc-update add zfs-import boot
rc-update add zfs-mount boot
rc-update add zfs-share default


The idea here is to make sure ZED is started before the imports (so that
we can start consuming pool events before pools are imported).

Then import any/all pools (except the root pool which is mounted in the
initrd before the system even boots - basically before the S (single-user)
mode).

Then we mount all filesystems before we start any network service (such as
NFSd, AFSd, Samba, iSCSI targets and what not). Even if the share* in ZFS
isn't used, the filesystem must be mounted for the service to start properly.

Then, at almost the very end, we share filesystems configured with the
share* property in ZFS.
Loading

0 comments on commit 2a34db1

Please sign in to comment.