aboutsummaryrefslogtreecommitdiffstats
path: root/etc/init.d/zfs.lsb.in
blob: 0d0ffb4c42a844ceaa223b686b801f05bbc306a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/bin/bash
#
# zfs           This script will mount/umount the zfs filesystems.
#
# chkconfig:    2345 01 99
# description:  This script will mount/umount the zfs filesystems during
#               system boot/shutdown.  Configuration of which filesystems
#               should be mounted is handled by the zfs 'mountpoint' and
#               'canmount' properties.  See the zfs(8) man page for details.
#               It is also responsible for all userspace zfs services.
#
### BEGIN INIT INFO
# Provides: zfs
# Required-Start: $local_fs
# Required-Stop: $local_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Should-Stop:
# Short-Description: Mount/umount the zfs filesystems
# Description: ZFS is an advanced filesystem designed to simplify managing
#              and protecting your data.  This service mounts the ZFS
#              filesystems and starts all related zfs services.
### END INIT INFO

# Source function library.
. /lib/lsb/init-functions

LOCKFILE=/var/lock/zfs
ZFS="@sbindir@/zfs"
ZPOOL="@sbindir@/zpool"
ZPOOL_CACHE="@sysconfdir@/zfs/zpool.cache"

# Source zfs configuration.
[ -r '/etc/default/zfs' ] &&  . /etc/default/zfs

[ -x "$ZPOOL" ] || exit 1
[ -x "$ZFS" ] || exit 2

if [ -z "$init" ]; then
    # Not interactive
    grep -Eqi 'zfs=off|zfs=no' /proc/cmdline && exit 3
fi

start()
{
	[ -f "$LOCKFILE" ] && return 3

	# Requires selinux policy which has not been written.
	if [ -r "/selinux/enforce" ] &&
	   [ "$(cat /selinux/enforce)" = "1" ]; then

		log_failure_msg "SELinux ZFS policy required"
		return 4
	fi

	# Delay until all required block devices are present.
	udevadm settle

	# Load the zfs module stack
	/sbin/modprobe zfs

	# Ensure / exists in /etc/mtab, if not update mtab accordingly.
	# This should be handled by rc.sysinit but lets be paranoid.
	awk '$2 == "/" { exit 1 }' /etc/mtab
	RETVAL=$?
	if [ "$RETVAL" -eq 0 ]; then
		/bin/mount -f /
	fi

	# Import all pools described by the cache file, and then mount
	# all filesystem based on their properties.
	if [ -f "$ZPOOL_CACHE" ] ; then
		log_begin_msg "Importing ZFS pools"
		"$ZPOOL" import -c "$ZPOOL_CACHE" -aN 2>/dev/null
		log_end_msg $?

		log_begin_msg "Mounting ZFS filesystems"
		"$ZFS" mount -a
		log_end_msg $?

		log_begin_msg "Exporting ZFS filesystems"
		"$ZFS" share -a
		log_end_msg $?
	fi

	touch "$LOCKFILE"
}

stop()
{
	[ ! -f "$LOCKFILE" ] && return 3

	log_begin_msg "Unmounting ZFS filesystems"
	"$ZFS" umount -a
	log_end_msg $?

	rm -f "$LOCKFILE"
}

status()
{
	[ ! -f "$LOCKFILE" ] && return 3

	"$ZPOOL" status && echo "" && "$ZPOOL" list
}

case "$1" in
	start)
		start
		RETVAL=$?
		;;
	stop)
		stop
		RETVAL=$?
		;;
	status)
		status
		RETVAL=$?
		;;
	restart)
		stop
		start
		;;
	condrestart)
		if [ -f "$LOCKFILE" ]; then
			stop
			start
		fi
		;;
	*)
		echo $"Usage: $0 {start|stop|status|restart|condrestart}"
		;;
esac

exit $RETVAL