]> git.proxmox.com Git - mirror_zfs-debian.git/blob - etc/init.d/zfs-zed.in
New upstream version 0.7.9
[mirror_zfs-debian.git] / etc / init.d / zfs-zed.in
1 #!@SHELL@
2 #
3 # zfs-zed
4 #
5 # chkconfig: 2345 29 99
6 # description: This script will start and stop the ZFS Event Daemon.
7 # probe: true
8 #
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
21 #
22 # Released under the 2-clause BSD license.
23 #
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
28
29 # Source the common init script
30 . @sysconfdir@/zfs/zfs-functions
31
32 ZED_NAME="zed"
33 ZED_PIDFILE="@runstatedir@/$ZED_NAME.pid"
34
35 extra_started_commands="reload"
36
37 # Exit if the package is not installed
38 [ -x "$ZED" ] || exit 0
39
40 # ----------------------------------------------------
41
42 do_depend()
43 {
44 after zfs-mount localmount
45 }
46
47 do_start()
48 {
49 check_module_loaded "zfs" || exit 0
50
51 ZED_ARGS="$ZED_ARGS -p $ZED_PIDFILE"
52
53 zfs_action "Starting ZFS Event Daemon" zfs_daemon_start \
54 "$ZED_PIDFILE" "$ZED" "$ZED_ARGS"
55 return "$?"
56 }
57
58 do_stop()
59 {
60 local pools RET
61 check_module_loaded "zfs" || exit 0
62
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 spl
75 return "$?"
76 fi
77 else
78 return "$?"
79 fi
80 }
81
82 do_status()
83 {
84 check_module_loaded "zfs" || exit 0
85
86 zfs_daemon_status "$ZED_PIDFILE" "$ZED" "$ZED_NAME"
87 return "$?"
88 }
89
90 do_reload()
91 {
92 check_module_loaded "zfs" || exit 0
93
94 zfs_action "Reloading ZFS Event Daemon" zfs_daemon_reload \
95 "$ZED_PIDFILE" "$ZED_NAME"
96 return "$?"
97 }
98
99 # ----------------------------------------------------
100
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
125
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; }
134 fi