]>
Commit | Line | Data |
---|---|---|
712f8bd8 BB |
1 | #!/bin/bash |
2 | # | |
3 | # zfs This script will mount/umount the zfs filesystems. | |
4 | # | |
5 | # chkconfig: 2345 01 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 | # | |
12 | ### BEGIN INIT INFO | |
13 | # Provides: zfs | |
14 | # Required-Start: | |
15 | # Required-Stop: | |
16 | # Should-Start: | |
17 | # Should-Stop: | |
18 | # Default-Start: 2 3 4 5 | |
19 | # Default-Stop: 1 | |
20 | # Short-Description: Mount/umount the zfs filesystems | |
21 | # Description: ZFS is an advanced filesystem designed to simplify managing | |
22 | # and protecting your data. This service mounts the ZFS | |
23 | # filesystems and starts all related zfs services. | |
24 | ### END INIT INFO | |
25 | ||
26 | export PATH=/usr/local/sbin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin | |
27 | ||
28 | # Source function library & LSB routines | |
29 | . /etc/rc.d/init.d/functions | |
30 | ||
31 | # script variables | |
32 | RETVAL=0 | |
33 | ZPOOL=zpool | |
34 | ZFS=zfs | |
35 | servicename=zfs | |
36 | LOCKFILE=/var/lock/subsys/$servicename | |
37 | ||
38 | # functions | |
39 | zfs_installed() { | |
40 | modinfo zfs > /dev/null 2>&1 || return 5 | |
41 | $ZPOOL > /dev/null 2>&1 | |
42 | [ $? == 127 ] && return 5 | |
43 | $ZFS > /dev/null 2>&1 | |
44 | [ $? == 127 ] && return 5 | |
45 | return 0 | |
46 | } | |
47 | ||
48 | # i need a bash guru to simplify this, since this is copy and paste, but donno how | |
49 | # to correctly dereference variable names in bash, or how to do this right | |
50 | ||
51 | # first parameter is a regular expression that filters fstab | |
52 | read_fstab() { | |
53 | unset FSTAB | |
54 | n=0 | |
55 | while read -r fs mntpnt fstype opts blah ; do | |
56 | fs=`printf '%b\n' "$fs"` | |
57 | FSTAB[$n]=$fs | |
58 | let n++ | |
59 | done < <(egrep "$1" /etc/fstab) | |
60 | } | |
61 | ||
62 | start() | |
63 | { | |
64 | # Disable lockfile check | |
65 | # if [ -f "$LOCKFILE" ] ; then return 0 ; fi | |
66 | ||
67 | # check if ZFS is installed. If not, comply to FC standards and bail | |
68 | zfs_installed || { | |
69 | action $"Checking if ZFS is installed: not installed" /bin/false | |
70 | return 5 | |
71 | } | |
72 | ||
73 | # Requires selinux policy which has not been written. | |
74 | if [ -r "/selinux/enforce" ] && | |
75 | [ "$(cat /selinux/enforce)" = "1" ]; then | |
76 | action $"SELinux ZFS policy required: " /bin/false || return 6 | |
77 | fi | |
78 | ||
2a005961 | 79 | # Delay until all required block devices are present. |
3af2ce4d FN |
80 | if [ -x /sbin/udevadm ]; then |
81 | /sbin/udevadm settle | |
82 | elif [ -x /sbin/udevsettle ]; then | |
83 | /sbin/udevsettle | |
84 | fi | |
2a005961 | 85 | |
712f8bd8 BB |
86 | # load kernel module infrastructure |
87 | if ! grep -q zfs /proc/modules ; then | |
88 | action $"Loading kernel ZFS infrastructure: " modprobe zfs || return 5 | |
89 | fi | |
90 | sleep 1 | |
91 | ||
92 | action $"Mounting automounted ZFS filesystems: " $ZFS mount -a || return 152 | |
93 | ||
8b0cf399 GB |
94 | action $"Exporting ZFS filesystems: " $ZFS share -a || return 153 |
95 | ||
712f8bd8 BB |
96 | # Read fstab, try to mount zvols ignoring error |
97 | read_fstab "^/dev/(zd|zvol)" | |
98 | template=$"Mounting volume %s registered in fstab: " | |
99 | for volume in "${FSTAB[@]}" ; do | |
100 | string=`printf "$template" "$volume"` | |
101 | action "$string" mount "$volume" 2>/dev/null || /bin/true | |
102 | done | |
103 | ||
104 | # touch "$LOCKFILE" | |
105 | } | |
106 | ||
107 | stop() | |
108 | { | |
109 | # Disable lockfile check | |
110 | # if [ ! -f "$LOCKFILE" ] ; then return 0 ; fi | |
111 | ||
112 | # check if ZFS is installed. If not, comply to FC standards and bail | |
113 | zfs_installed || { | |
114 | action $"Checking if ZFS is installed: not installed" /bin/false | |
115 | return 5 | |
116 | } | |
117 | ||
118 | # the poweroff of the system takes care of this | |
119 | # but it never unmounts the root filesystem itself | |
120 | # shit | |
121 | ||
122 | action $"Syncing ZFS filesystems: " sync | |
123 | # about the only thing we can do, and then we | |
124 | # hope that the umount process will succeed | |
125 | # unfortunately the umount process does not dismount | |
126 | # the root file system, there ought to be some way | |
127 | # we can tell zfs to just flush anything in memory | |
128 | # when a request to remount,ro comes in | |
129 | ||
130 | #echo -n $"Unmounting ZFS filesystems: " | |
131 | #$ZFS umount -a | |
132 | #RETVAL=$? | |
133 | #if [ $RETVAL -ne 0 ]; then | |
134 | # failure | |
135 | ||
136 | # return 8 | |
137 | #fi | |
138 | #success | |
139 | ||
140 | rm -f "$LOCKFILE" | |
141 | } | |
142 | ||
143 | # See how we are called | |
144 | case "$1" in | |
145 | start) | |
146 | start | |
147 | RETVAL=$? | |
148 | ;; | |
149 | stop) | |
150 | stop | |
151 | RETVAL=$? | |
152 | ;; | |
153 | status) | |
154 | lsmod | grep -q zfs || RETVAL=3 | |
155 | $ZPOOL status && echo && $ZFS list || { | |
156 | [ -f "$LOCKFILE" ] && RETVAL=2 || RETVAL=4 | |
157 | } | |
158 | ;; | |
159 | restart) | |
160 | stop | |
161 | start | |
162 | ;; | |
163 | condrestart) | |
164 | if [ -f "$LOCKFILE" ] ; then | |
165 | stop | |
166 | start | |
167 | fi | |
168 | ;; | |
169 | *) | |
170 | echo $"Usage: $0 {start|stop|status|restart|condrestart}" | |
171 | RETVAL=3 | |
172 | ;; | |
173 | esac | |
174 | ||
175 | exit $RETVAL |