]>
Commit | Line | Data |
---|---|---|
2a34db1b TF |
1 | #!@SHELL@ |
2 | # | |
3 | # zfs-mount This script will mount/umount the zfs filesystems. | |
4 | # | |
5 | # chkconfig: 2345 06 99 | |
6 | # description: This script will mount/umount the zfs filesystems during | |
7 | # system boot/shutdown. Configuration of which filesystems | |
8 | # should be mounted is handled by the zfs 'mountpoint' and | |
9 | # 'canmount' properties. See the zfs(8) man page for details. | |
10 | # It is also responsible for all userspace zfs services. | |
11 | # probe: true | |
12 | # | |
13 | ### BEGIN INIT INFO | |
14 | # Provides: zfs-mount | |
15 | # Required-Start: $local_fs zfs-import | |
16 | # Required-Stop: $local_fs zfs-import | |
17 | # Default-Start: 2 3 4 5 | |
18 | # Default-Stop: 0 1 6 | |
19 | # X-Stop-After: zfs-share | |
20 | # Short-Description: Mount ZFS filesystems and volumes | |
21 | # Description: Run the `zfs mount -a` or `zfs umount -a` commands. | |
22 | ### END INIT INFO | |
23 | # | |
24 | # Released under the 2-clause BSD license. | |
25 | # | |
26 | # The original script that acted as a template for this script came from | |
27 | # the Debian GNU/Linux kFreeBSD ZFS packages (which did not include a | |
28 | # licensing stansa) in the commit dated Mar 24, 2011: | |
29 | # https://github.com/zfsonlinux/pkg-zfs/commit/80a3ae582b59c0250d7912ba794dca9e669e605a | |
30 | ||
31 | # Source the common init script | |
32 | . @sysconfdir@/zfs/zfs-functions | |
33 | ||
34 | # ---------------------------------------------------- | |
35 | ||
4f38c259 TF |
36 | chkroot() { |
37 | while read line; do | |
38 | set -- $line | |
39 | if [ "$2" = "/" ]; then | |
40 | return 0 | |
41 | fi | |
42 | done < /etc/mtab | |
43 | ||
44 | return 1 | |
45 | } | |
46 | ||
2a34db1b TF |
47 | do_depend() |
48 | { | |
49 | after procfs zfs-import sysfs procps | |
50 | use mtab | |
51 | keyword -lxc -openvz -prefix -vserver | |
52 | } | |
53 | ||
54 | # Mount all datasets/filesystems | |
55 | do_mount() | |
56 | { | |
57 | local verbose overlay i mntpt val | |
58 | ||
59 | [ "$VERBOSE_MOUNT" = 'yes' ] && verbose=v | |
60 | [ "$OVERLAY_MOUNTS" = 'yes' ] && overlay=O | |
61 | ||
62 | zfs_action "Mounting ZFS filesystem(s)" \ | |
63 | "$ZFS" mount -a$verbose$overlay "$MOUNT_EXTRA_OPTIONS" | |
64 | ||
65 | # Require each volume/filesytem to have 'noauto' and no fsck | |
66 | # option. This shouldn't really be necessary, as long as one | |
67 | # can get zfs-import to run sufficiently early on in the boot | |
68 | # process - before local mounts. This is just here in case/if | |
69 | # this isn't possible. | |
70 | [ "$VERBOSE_MOUNT" = 'yes' ] && \ | |
71 | zfs_log_begin_msg "Mounting volumes and filesystems registered in fstab" | |
72 | ||
73 | read_mtab "^/dev/(zd|zvol)" | |
74 | read_fstab "^/dev/(zd|zvol)" | |
75 | i=0; var=$(eval echo FSTAB_$i) | |
76 | while [ -n "$(eval echo "$""$var")" ] | |
77 | do | |
78 | mntpt=$(eval echo "$""$var") | |
79 | dev=$(eval echo "$"FSTAB_dev_$i) | |
80 | if ! in_mtab "$mntpt" && ! is_mounted "$mntpt" && [ -e "$dev" ] | |
81 | then | |
82 | [ "$VERBOSE_MOUNT" = 'yes' ] && \ | |
83 | zfs_log_progress_msg "$mntpt " | |
84 | fsck "$dev" && mount "$mntpt" | |
85 | fi | |
86 | ||
87 | i=$((i + 1)) | |
88 | var=$(eval echo FSTAB_$i) | |
89 | done | |
90 | ||
91 | read_mtab "[[:space:]]zfs[[:space:]]" | |
92 | read_fstab "[[:space:]]zfs[[:space:]]" | |
93 | i=0; var=$(eval echo FSTAB_$i) | |
94 | while [ -n "$(eval echo "$""$var")" ] | |
95 | do | |
96 | mntpt=$(eval echo "$""$var") | |
97 | if ! in_mtab "$mntpt" && ! is_mounted "$mntpt" | |
98 | then | |
99 | [ "$VERBOSE_MOUNT" = 'yes' ] && \ | |
100 | zfs_log_progress_msg "$mntpt " | |
101 | mount "$mntpt" | |
102 | fi | |
103 | ||
104 | i=$((i + 1)) | |
105 | var=$(eval echo FSTAB_$i) | |
106 | done | |
107 | [ "$VERBOSE_MOUNT" = 'yes' ] && zfs_log_end_msg 0 | |
108 | ||
109 | return 0 | |
110 | } | |
111 | ||
112 | # Unmount all filesystems | |
113 | do_unmount() | |
114 | { | |
115 | local i var mntpt | |
116 | ||
117 | # This shouldn't really be necessary, as long as one can get | |
118 | # zfs-import to run sufficiently late in the shutdown/reboot process | |
119 | # - after unmounting local filesystems. This is just here in case/if | |
120 | # this isn't possible. | |
121 | zfs_action "Unmounting ZFS filesystems" "$ZFS" unmount -a | |
122 | ||
123 | [ "$VERBOSE_MOUNT" = 'yes' ] && \ | |
124 | zfs_log_begin_msg "Unmounting volumes and filesystems registered in fstab" | |
125 | ||
126 | read_mtab "^/dev/(zd|zvol)" | |
127 | read_fstab "^/dev/(zd|zvol)" | |
128 | i=0; var=$(eval echo FSTAB_$i) | |
129 | while [ -n "$(eval echo "$""$var")" ] | |
130 | do | |
131 | mntpt=$(eval echo "$""$var") | |
132 | dev=$(eval echo "$"FSTAB_dev_$i) | |
133 | if in_mtab "$mntpt" | |
134 | then | |
135 | [ "$VERBOSE_MOUNT" = 'yes' ] && \ | |
136 | zfs_log_progress_msg "$mntpt " | |
137 | umount "$mntpt" | |
138 | fi | |
139 | ||
140 | i=$((i + 1)) | |
141 | var=$(eval echo FSTAB_$i) | |
142 | done | |
143 | ||
144 | read_mtab "[[:space:]]zfs[[:space:]]" | |
145 | read_fstab "[[:space:]]zfs[[:space:]]" | |
146 | i=0; var=$(eval echo FSTAB_$i) | |
147 | while [ -n "$(eval echo "$""$var")" ] | |
148 | do | |
149 | mntpt=$(eval echo "$""$var") | |
150 | if in_mtab "$mntpt"; then | |
151 | [ "$VERBOSE_MOUNT" = 'yes' ] && \ | |
152 | zfs_log_progress_msg "$mntpt " | |
153 | umount "$mntpt" | |
154 | fi | |
155 | ||
156 | i=$((i + 1)) | |
157 | var=$(eval echo FSTAB_$i) | |
158 | done | |
159 | [ "$VERBOSE_MOUNT" = 'yes' ] && zfs_log_end_msg 0 | |
160 | ||
161 | return 0 | |
162 | } | |
163 | ||
164 | do_start() | |
165 | { | |
48511ea6 | 166 | check_module_loaded "zfs" || exit 0 |
2a34db1b | 167 | |
16421a1d TF |
168 | case "$ZFS_MOUNT" in |
169 | [Oo][Ff][Ff]|[Nn][Oo]|''|0) | |
170 | exit 3 | |
171 | ;; | |
172 | esac | |
2a34db1b TF |
173 | |
174 | # Ensure / exists in /etc/mtab, if not update mtab accordingly. | |
175 | # This should be handled by rc.sysinit but lets be paranoid. | |
4f38c259 | 176 | if ! chkroot |
2a34db1b TF |
177 | then |
178 | mount -f / | |
179 | fi | |
180 | ||
2a34db1b TF |
181 | do_mount |
182 | } | |
183 | ||
184 | do_stop() | |
185 | { | |
186 | case "$ZFS_UNMOUNT" in | |
187 | [Oo][Ff][Ff]|[Nn][Oo]|''|0) | |
188 | exit 0 | |
189 | ;; | |
190 | esac | |
191 | ||
48511ea6 | 192 | check_module_loaded "zfs" || exit 0 |
2a34db1b TF |
193 | |
194 | do_unmount | |
195 | } | |
196 | ||
197 | # ---------------------------------------------------- | |
198 | ||
199 | if [ ! -e /etc/gentoo-release ] | |
200 | then | |
201 | case "$1" in | |
202 | start) | |
203 | do_start | |
204 | ;; | |
205 | stop) | |
206 | do_stop | |
207 | ;; | |
208 | force-reload|condrestart|reload|restart|status) | |
209 | # no-op | |
210 | ;; | |
211 | *) | |
212 | [ -n "$1" ] && echo "Error: Unknown command $1." | |
213 | echo "Usage: $0 {start|stop}" | |
214 | exit 3 | |
215 | ;; | |
216 | esac | |
217 | ||
218 | exit $? | |
219 | else | |
220 | # Create wrapper functions since Gentoo don't use the case part. | |
221 | depend() { do_depend; } | |
222 | start() { do_start; } | |
223 | stop() { do_stop; } | |
224 | fi |