1#!@DEFAULT_INIT_SHELL@ 2# SPDX-License-Identifier: BSD-2-Clause 3# shellcheck disable=SC2154 4# 5# zfs-zed 6# 7# chkconfig: 2345 29 99 8# description: This script will start and stop the ZFS Event Daemon. 9# probe: true 10# 11### BEGIN INIT INFO 12# Provides: zfs-zed 13# Required-Start: zfs-mount 14# Required-Stop: zfs-mount 15# Default-Start: 2 3 4 5 16# Default-Stop: 0 1 6 17# X-Stop-After: zfs-share 18# Short-Description: ZFS Event Daemon 19# Description: zed monitors ZFS events. When a zevent is posted, zed 20# will run any scripts that have been enabled for the 21# corresponding zevent class. 22### END INIT INFO 23# 24# Released under the 2-clause BSD license. 25# 26# This script is based on debian/zfsutils.zfs.init from the 27# Debian GNU/kFreeBSD zfsutils 8.1-3 package, written by Aurelien Jarno. 28 29# Source the common init script 30. @sysconfdir@/zfs/zfs-functions 31 32ZED_NAME="zed" 33ZED_PIDFILE="@runstatedir@/$ZED_NAME.pid" 34 35# shellcheck disable=SC2034 36extra_started_commands="reload" 37 38# Exit if the package is not installed 39[ -x "$ZED" ] || exit 0 40 41# ---------------------------------------------------- 42 43do_depend() 44{ 45 after zfs-mount localmount 46} 47 48do_start() 49{ 50 check_module_loaded "zfs" || exit 0 51 52 ZED_ARGS="$ZED_ARGS -p $ZED_PIDFILE" 53 54 zfs_action "Starting ZFS Event Daemon" zfs_daemon_start \ 55 "$ZED_PIDFILE" "$ZED" "$ZED_ARGS" 56 return "$?" 57} 58 59do_stop() 60{ 61 local pools 62 check_module_loaded "zfs" || exit 0 63 64 zfs_action "Stopping ZFS Event Daemon" zfs_daemon_stop \ 65 "$ZED_PIDFILE" "$ZED" "$ZED_NAME" || return "$?" 66 67 # Let's see if we have any pools imported 68 pools=$("$ZPOOL" list -H -oname) 69 if [ -z "$pools" ] 70 then 71 # No pools imported, it is/should be safe/possible to 72 # unload modules. 73 zfs_action "Unloading modules" rmmod zfs spl 74 return "$?" 75 fi 76} 77 78do_status() 79{ 80 check_module_loaded "zfs" || exit 0 81 82 zfs_daemon_status "$ZED_PIDFILE" "$ZED" "$ZED_NAME" 83 return "$?" 84} 85 86do_reload() 87{ 88 check_module_loaded "zfs" || exit 0 89 90 zfs_action "Reloading ZFS Event Daemon" zfs_daemon_reload \ 91 "$ZED_PIDFILE" "$ZED_NAME" 92 return "$?" 93} 94 95# ---------------------------------------------------- 96 97if @IS_SYSV_RC@ 98then 99 case "$1" in 100 start) 101 do_start 102 ;; 103 stop) 104 do_stop 105 ;; 106 status) 107 do_status 108 ;; 109 reload|force-reload) 110 do_reload 111 ;; 112 restart) 113 do_stop 114 do_start 115 ;; 116 *) 117 [ -n "$1" ] && echo "Error: Unknown command $1." 118 echo "Usage: $0 {start|stop|status|reload|restart}" 119 exit 1 120 ;; 121 esac 122 123 exit $? 124else 125 # Create wrapper functions since Gentoo don't use the case part. 126 depend() { do_depend; } 127 start() { do_start; } 128 stop() { do_stop; } 129 status() { do_status; } 130 reload() { do_reload; } 131fi 132