Add a "try" operation for range locks
[zfs.git] / etc / init.d / zfs-zed.in
blobfe3c22594ce5bc6b54d01838eae7b5e0333aa9cd
1 #!@SHELL@
3 # zfs-zed
5 # chkconfig:    2345 29 99
6 # description:  This script will start and stop the ZFS Event Daemon.
7 # probe: true
9 ### BEGIN INIT INFO
10 # Provides:          zfs-zed
11 # Required-Start:    zfs-mount
12 # Required-Stop:     zfs-mount
13 # Default-Start:     2 3 4 5
14 # Default-Stop:      0 1 6
15 # X-Stop-After:      zfs-share
16 # Short-Description: ZFS Event Daemon
17 # Description:       zed monitors ZFS events. When a zevent is posted, zed
18 #                    will run any scripts that have been enabled for the
19 #                    corresponding zevent class.
20 ### END INIT INFO
22 # Released under the 2-clause BSD license.
24 # The original script that acted as a template for this script came from
25 # the Debian GNU/Linux kFreeBSD ZFS packages (which did not include a
26 # licensing stansa) in the commit dated Mar 24, 2011:
27 #   https://github.com/zfsonlinux/pkg-zfs/commit/80a3ae582b59c0250d7912ba794dca9e669e605a
29 # Source the common init script
30 . @sysconfdir@/zfs/zfs-functions
32 ZED_NAME="zed"
33 ZED_PIDFILE="@runstatedir@/$ZED_NAME.pid"
35 extra_started_commands="reload"
37 # Exit if the package is not installed
38 [ -x "$ZED" ] || exit 0
40 # ----------------------------------------------------
42 do_depend()
44         after zfs-mount localmount
47 do_start()
49         check_module_loaded "zfs" || exit 0
51         ZED_ARGS="$ZED_ARGS -p $ZED_PIDFILE"
53         zfs_action "Starting ZFS Event Daemon" zfs_daemon_start \
54             "$ZED_PIDFILE" "$ZED" "$ZED_ARGS"
55         return "$?"
58 do_stop()
60         local pools RET
61         check_module_loaded "zfs" || exit 0
63         zfs_action "Stopping ZFS Event Daemon" zfs_daemon_stop \
64            "$ZED_PIDFILE" "$ZED" "$ZED_NAME"
65         if [ "$?" -eq "0" ]
66         then
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 zunicode \
74                             zavl zcommon znvpair zlua spl
75                         return "$?"
76                 fi
77         else
78                 return "$?"
79         fi
82 do_status()
84         check_module_loaded "zfs" || exit 0
86         zfs_daemon_status "$ZED_PIDFILE" "$ZED" "$ZED_NAME"
87         return "$?"
90 do_reload()
92         check_module_loaded "zfs" || exit 0
94         zfs_action "Reloading ZFS Event Daemon" zfs_daemon_reload \
95             "$ZED_PIDFILE" "$ZED_NAME"
96         return "$?"
99 # ----------------------------------------------------
101 if [ ! -e /sbin/openrc-run ]; then
102         case "$1" in
103                 start)
104                         do_start
105                         ;;
106                 stop)
107                         do_stop
108                         ;;
109                 status)
110                         do_status
111                         ;;
112                 reload|force-reload)
113                         do_reload
114                         ;;
115                 restart)
116                         do_stop
117                         do_start
118                         ;;
119                 *)
120                         [ -n "$1" ] && echo "Error: Unknown command $1."
121                         echo "Usage: $0 {start|stop|status|reload|restart}"
122                         exit 1
123                         ;;
124         esac
126         exit $?
127 else
128         # Create wrapper functions since Gentoo don't use the case part.
129         depend() { do_depend; }
130         start() { do_start; }
131         stop() { do_stop; }
132         status() { do_status; }
133         reload() { do_reload; }