xref: /freebsd/sys/contrib/openzfs/etc/init.d/zfs-share.in (revision 61145dc2b94f12f6a47344fb9aac702321880e43)
1#!@DEFAULT_INIT_SHELL@
2# SPDX-License-Identifier: BSD-2-Clause
3# shellcheck disable=SC2154
4#
5# zfs-share     This script will network share zfs filesystems and volumes.
6#
7# chkconfig:    2345 30 99
8# description:  Run the `zfs share -a` or `zfs unshare -a` commands
9#               for controlling iSCSI, NFS, or CIFS network shares.
10# probe: true
11#
12### BEGIN INIT INFO
13# Provides:          zfs-share
14# Required-Start:    $local_fs $network $remote_fs zfs-mount
15# Required-Stop:     $local_fs $network $remote_fs zfs-mount
16# Default-Start:     2 3 4 5
17# Default-Stop:      0 1 6
18# Should-Start:      iscsi iscsitarget istgt scst @DEFAULT_INIT_NFS_SERVER@ samba samba4 zfs-mount zfs-zed
19# Should-Stop:       iscsi iscsitarget istgt scst @DEFAULT_INIT_NFS_SERVER@ samba samba4 zfs-mount zfs-zed
20# Short-Description: Network share ZFS datasets and volumes.
21# Description:       Run the `zfs share -a` or `zfs unshare -a` commands
22#                    for controlling iSCSI, NFS, or CIFS network shares.
23### END INIT INFO
24#
25# Released under the 2-clause BSD license.
26#
27# This script is based on debian/zfsutils.zfs.init from the
28# Debian GNU/kFreeBSD zfsutils 8.1-3 package, written by Aurelien Jarno.
29
30# Source the common init script
31. @sysconfdir@/zfs/zfs-functions
32
33# ----------------------------------------------------
34
35do_depend()
36{
37	after sysfs zfs-mount zfs-zed
38	keyword -lxc -openvz -prefix -vserver
39}
40
41do_start()
42{
43	check_boolean "$ZFS_SHARE" || exit 0
44
45	check_module_loaded "zfs" || exit 0
46
47	zfs_action "Sharing ZFS filesystems" "$ZFS" share -a
48}
49
50do_stop()
51{
52	check_boolean "$ZFS_UNSHARE" || exit 0
53
54	check_module_loaded "zfs" || exit 0
55
56	zfs_action "Unsharing ZFS filesystems" "$ZFS" unshare -a
57}
58
59# ----------------------------------------------------
60
61if @IS_SYSV_RC@
62then
63	case "$1" in
64		start)
65			do_start
66			;;
67		stop)
68			do_stop
69			;;
70		force-reload|reload|restart|status)
71			# no-op
72			;;
73		*)
74			[ -n "$1" ] && echo "Error: Unknown command $1."
75			echo "Usage: $0 {start|stop}"
76			exit 3
77			;;
78	esac
79
80	exit $?
81else
82	# Create wrapper functions since Gentoo don't use the case part.
83	depend() { do_depend; }
84	start() { do_start; }
85	stop() { do_stop; }
86fi
87