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