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