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 for better maintainability.
  + Merge openzfs#2148 - Inform OpenRC that ZFS uses mtab.
  + Add a configurable ZFS_INITRD_POST_MODPROBE_SLEEP used in the initrd to sleep after the modprobe.
  + The import function, do_import(), imports pools by name instead of '-a' [all].
    + Test all '/dev/disk/by-*' dirs for import. Include /dev as a last ditch attempt.
  + Fallback on importing the pool using the cache file (if it exists) if the
    'by-id' didn't work.
  + Add exceptions to pool imports.
  + ZED script from the Debian GNU/Linux packages added.
  + Run all scripts through ShellCheck.

Signed-off-by: Turbo Fredriksson [email protected]
Closes: openzfs#2974, openzfs#2107.
  • Loading branch information
FransUrbo committed May 6, 2015
1 parent f3c517d commit 63285e0
Show file tree
Hide file tree
Showing 16 changed files with 1,087 additions and 790 deletions.
16 changes: 15 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,20 @@ 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
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 @@
common.init
zfs-import
zfs-mount
zfs-share
zfs-zed
zfs
48 changes: 32 additions & 16 deletions etc/init.d/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,22 +1,38 @@
initdir = $(DEFAULT_INIT_DIR)
init_SCRIPTS = zfs
init_SCRIPTS = zfs-import zfs-mount zfs-share zfs-zed

initcommondir = $(sysconfdir)/zfs
initcommon_SCRIPTS = common.init

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/common.init.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; \
$(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,@NFS_SRV\@,$$NFS_SRV,g" \
'[email protected]' >'$@'; \
[ '$@' = 'common.init' -o '$@' = 'zfs' ] || \
chmod +x '$@')

distclean-local::
-$(RM) $(init_SCRIPTS)
-$(RM) $(init_SCRIPTS) $(initcommon_SCRIPTS) $(initconf_SCRIPTS)
48 changes: 48 additions & 0 deletions etc/init.d/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
DESCRIPTION
These script was written with the primary intention to be 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.

It 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 a 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 to think 'portability'. 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 (proably) have is the part
at the beginning of the "common.init.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 18 S . stop 08 0 1 6 .
update-rc.d zfs-import start 11 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 03 2 3 4 5 . stop 05 0 1 6 .
Loading

0 comments on commit 63285e0

Please sign in to comment.