]> git.proxmox.com Git - mirror_zfs.git/blame - etc/init.d/zfs-mount.in
Fix style checking error introduced by zfs-mount changes
[mirror_zfs.git] / etc / init.d / zfs-mount.in
CommitLineData
38e2e9ce 1#!@DEFAULT_INIT_SHELL@
ae66d3aa 2# shellcheck disable=SC2154
2a34db1b
TF
3#
4# zfs-mount This script will mount/umount the zfs filesystems.
5#
6# chkconfig: 2345 06 99
7# description: This script will mount/umount the zfs filesystems during
8# system boot/shutdown. Configuration of which filesystems
9# should be mounted is handled by the zfs 'mountpoint' and
10# 'canmount' properties. See the zfs(8) man page for details.
11# It is also responsible for all userspace zfs services.
12# probe: true
13#
14### BEGIN INIT INFO
15# Provides: zfs-mount
16# Required-Start: $local_fs zfs-import
17# Required-Stop: $local_fs zfs-import
18# Default-Start: 2 3 4 5
19# Default-Stop: 0 1 6
3f1cc17c 20# X-Stop-After: zfs-zed
2a34db1b
TF
21# Short-Description: Mount ZFS filesystems and volumes
22# Description: Run the `zfs mount -a` or `zfs umount -a` commands.
23### END INIT INFO
24#
25# Released under the 2-clause BSD license.
26#
adc851d9
AZ
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.
2a34db1b
TF
29
30# Source the common init script
31. @sysconfdir@/zfs/zfs-functions
32
33# ----------------------------------------------------
34
4f38c259 35chkroot() {
adc851d9
AZ
36 while read -r _ mp _; do
37 if [ "$mp" = "/" ]; then
4f38c259
TF
38 return 0
39 fi
79251738 40 done < /proc/self/mounts
4f38c259
TF
41
42 return 1
43}
44
2a34db1b
TF
45do_depend()
46{
da619f3a
RY
47 # Try to allow people to mix and match fstab with ZFS in a way that makes sense.
48 if [ "$(mountinfo -s /)" = 'zfs' ]
49 then
50 before localmount
51 else
52 after localmount
53 fi
54
55 # bootmisc will log to /var which may be a different zfs than root.
56 before bootmisc logger
57
3f1cc17c 58 after zfs-import sysfs
2a34db1b
TF
59 use mtab
60 keyword -lxc -openvz -prefix -vserver
61}
62
63# Mount all datasets/filesystems
64do_mount()
65{
4d462729 66 local verbose overlay
2a34db1b 67
57732964
TF
68 check_boolean "$VERBOSE_MOUNT" && verbose=v
69 check_boolean "$DO_OVERLAY_MOUNTS" && overlay=O
2a34db1b
TF
70
71 zfs_action "Mounting ZFS filesystem(s)" \
ae66d3aa 72 "$ZFS" mount "-a$verbose$overlay" "$MOUNT_EXTRA_OPTIONS"
2a34db1b 73
2a34db1b
TF
74 return 0
75}
76
77# Unmount all filesystems
78do_unmount()
79{
2a34db1b
TF
80 # This shouldn't really be necessary, as long as one can get
81 # zfs-import to run sufficiently late in the shutdown/reboot process
82 # - after unmounting local filesystems. This is just here in case/if
83 # this isn't possible.
84 zfs_action "Unmounting ZFS filesystems" "$ZFS" unmount -a
85
2a34db1b
TF
86 return 0
87}
88
89do_start()
90{
57732964 91 check_boolean "$ZFS_MOUNT" || exit 0
2a34db1b 92
57732964 93 check_module_loaded "zfs" || exit 0
2a34db1b 94
79251738 95 # Ensure / exists in /proc/self/mounts.
2a34db1b 96 # This should be handled by rc.sysinit but lets be paranoid.
4f38c259 97 if ! chkroot
2a34db1b
TF
98 then
99 mount -f /
100 fi
101
2a34db1b
TF
102 do_mount
103}
104
105do_stop()
106{
57732964 107 check_boolean "$ZFS_UNMOUNT" || exit 0
2a34db1b 108
48511ea6 109 check_module_loaded "zfs" || exit 0
2a34db1b
TF
110
111 do_unmount
112}
113
114# ----------------------------------------------------
115
c53fb011 116if [ ! -e /sbin/openrc-run ]
2a34db1b
TF
117then
118 case "$1" in
119 start)
120 do_start
121 ;;
122 stop)
123 do_stop
124 ;;
125 force-reload|condrestart|reload|restart|status)
126 # no-op
127 ;;
128 *)
129 [ -n "$1" ] && echo "Error: Unknown command $1."
130 echo "Usage: $0 {start|stop}"
131 exit 3
132 ;;
133 esac
134
135 exit $?
136else
137 # Create wrapper functions since Gentoo don't use the case part.
138 depend() { do_depend; }
139 start() { do_start; }
140 stop() { do_stop; }
141fi