1#!@DEFAULT_INIT_SHELL@
2# shellcheck disable=SC2154
3#
4# zfs-share     This script will network share zfs filesystems and volumes.
5#
6# chkconfig:    2345 30 99
7# description:  Run the `zfs share -a` or `zfs unshare -a` commands
8#               for controlling iSCSI, NFS, or CIFS network shares.
9# probe: true
10#
11### BEGIN INIT INFO
12# Provides:          zfs-share
13# Required-Start:    $local_fs $network $remote_fs zfs-mount
14# Required-Stop:     $local_fs $network $remote_fs zfs-mount
15# Default-Start:     2 3 4 5
16# Default-Stop:      0 1 6
17# Should-Start:      iscsi iscsitarget istgt scst @DEFAULT_INIT_NFS_SERVER@ samba samba4 zfs-mount zfs-zed
18# Should-Stop:       iscsi iscsitarget istgt scst @DEFAULT_INIT_NFS_SERVER@ samba samba4 zfs-mount zfs-zed
19# Short-Description: Network share ZFS datasets and volumes.
20# Description:       Run the `zfs share -a` or `zfs unshare -a` commands
21#                    for controlling iSCSI, NFS, or CIFS network shares.
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
32# ----------------------------------------------------
33
34do_depend()
35{
36	after sysfs zfs-mount zfs-zed
37	keyword -lxc -openvz -prefix -vserver
38}
39
40do_start()
41{
42	check_boolean "$ZFS_SHARE" || exit 0
43
44	check_module_loaded "zfs" || exit 0
45
46	zfs_action "Sharing ZFS filesystems" "$ZFS" share -a
47}
48
49do_stop()
50{
51	check_boolean "$ZFS_UNSHARE" || exit 0
52
53	check_module_loaded "zfs" || exit 0
54
55	zfs_action "Unsharing ZFS filesystems" "$ZFS" unshare -a
56}
57
58# ----------------------------------------------------
59
60if @IS_SYSV_RC@
61then
62	case "$1" in
63		start)
64			do_start
65			;;
66		stop)
67			do_stop
68			;;
69		force-reload|reload|restart|status)
70			# no-op
71			;;
72		*)
73			[ -n "$1" ] && echo "Error: Unknown command $1."
74			echo "Usage: $0 {start|stop}"
75			exit 3
76			;;
77	esac
78
79	exit $?
80else
81	# Create wrapper functions since Gentoo don't use the case part.
82	depend() { do_depend; }
83	start() { do_start; }
84	stop() { do_stop; }
85fi
86