mirror_zfs/etc/init.d/zfs-zed.in
Benda Xu 162cc80b81
etc/init.d: decide which variant to use at build time.
Let Debian use the sysv-rc variant of the script, even when OpenRC is
installed. Unlike on Gentoo, OpenRC on Debian consumes both the
sysv-rc scripts and OpenRC ones. ZFS initscripts on Debian should be
the sysv-rc version to provide most compatibility and to integrate
with the rest of initscripts for dependency tracking.

Restrict the substitution in the Makefile to the dedicated list.

This construct is inspired by Mo Zhou's detection of the execution
shell and follows the strategy of Peter in 6ef28c526b.

As of 2024, the initscripts are mostly relevant on Debian, Gentoo and
their derivatives.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Benda Xu <orv@debian.org>
Issue #8063
Issue #8204
Issue #8359
Closes #15977
2024-04-08 16:52:24 -07:00

131 lines
2.6 KiB
Plaintext
Executable File

#!@DEFAULT_INIT_SHELL@
# shellcheck disable=SC2154
#
# zfs-zed
#
# chkconfig: 2345 29 99
# description: This script will start and stop the ZFS Event Daemon.
# probe: true
#
### BEGIN INIT INFO
# Provides: zfs-zed
# Required-Start: zfs-mount
# Required-Stop: zfs-mount
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# X-Stop-After: zfs-share
# Short-Description: ZFS Event Daemon
# Description: zed monitors ZFS events. When a zevent is posted, zed
# will run any scripts that have been enabled for the
# corresponding zevent class.
### END INIT INFO
#
# Released under the 2-clause BSD license.
#
# This script is based on debian/zfsutils.zfs.init from the
# Debian GNU/kFreeBSD zfsutils 8.1-3 package, written by Aurelien Jarno.
# Source the common init script
. @sysconfdir@/zfs/zfs-functions
ZED_NAME="zed"
ZED_PIDFILE="@runstatedir@/$ZED_NAME.pid"
# shellcheck disable=SC2034
extra_started_commands="reload"
# Exit if the package is not installed
[ -x "$ZED" ] || exit 0
# ----------------------------------------------------
do_depend()
{
after zfs-mount localmount
}
do_start()
{
check_module_loaded "zfs" || exit 0
ZED_ARGS="$ZED_ARGS -p $ZED_PIDFILE"
zfs_action "Starting ZFS Event Daemon" zfs_daemon_start \
"$ZED_PIDFILE" "$ZED" "$ZED_ARGS"
return "$?"
}
do_stop()
{
local pools
check_module_loaded "zfs" || exit 0
zfs_action "Stopping ZFS Event Daemon" zfs_daemon_stop \
"$ZED_PIDFILE" "$ZED" "$ZED_NAME" || return "$?"
# Let's see if we have any pools imported
pools=$("$ZPOOL" list -H -oname)
if [ -z "$pools" ]
then
# No pools imported, it is/should be safe/possible to
# unload modules.
zfs_action "Unloading modules" rmmod zfs spl
return "$?"
fi
}
do_status()
{
check_module_loaded "zfs" || exit 0
zfs_daemon_status "$ZED_PIDFILE" "$ZED" "$ZED_NAME"
return "$?"
}
do_reload()
{
check_module_loaded "zfs" || exit 0
zfs_action "Reloading ZFS Event Daemon" zfs_daemon_reload \
"$ZED_PIDFILE" "$ZED_NAME"
return "$?"
}
# ----------------------------------------------------
if @IS_SYSV_RC@
then
case "$1" in
start)
do_start
;;
stop)
do_stop
;;
status)
do_status
;;
reload|force-reload)
do_reload
;;
restart)
do_stop
do_start
;;
*)
[ -n "$1" ] && echo "Error: Unknown command $1."
echo "Usage: $0 {start|stop|status|reload|restart}"
exit 1
;;
esac
exit $?
else
# Create wrapper functions since Gentoo don't use the case part.
depend() { do_depend; }
start() { do_start; }
stop() { do_stop; }
status() { do_status; }
reload() { do_reload; }
fi