]> git.proxmox.com Git - mirror_zfs-debian.git/blob - etc/init.d/zfs.redhat.in
Imported Upstream version 0.6.4.2
[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: $local_fs
15 # Required-Stop: $local_fs
16 # Default-Start: 2 3 4 5
17 # Default-Stop: 0 1 6
18 # Should-Stop:
19 # Short-Description: Mount/umount the zfs filesystems
20 # Description: ZFS is an advanced filesystem designed to simplify managing
21 # and protecting your data. This service mounts the ZFS
22 # filesystems and starts all related zfs services.
23 ### END INIT INFO
24
25 # Source function library.
26 . /etc/rc.d/init.d/functions
27
28 LOCKFILE=/var/lock/zfs
29 ZED="@sbindir@/zed"
30 ZED_PIDFILE="@runstatedir@/zed.pid"
31 ZFS="@sbindir@/zfs"
32 ZPOOL="@sbindir@/zpool"
33 ZPOOL_CACHE="/etc/zfs/zpool.cache"
34 USE_DISK_BY_ID=0
35 VERBOSE_MOUNT=0
36 DO_OVERLAY_MOUNTS=0
37 MOUNT_EXTRA_OPTIONS=""
38
39 # Source zfs configuration.
40 [ -r '/etc/sysconfig/zfs' ] && . /etc/sysconfig/zfs
41
42 [ -x "$ZPOOL" ] || exit 1
43 [ -x "$ZFS" ] || exit 2
44
45 if [ -z "$init" ]; then
46 # Not interactive
47 grep -qE '(^|[^\\](\\\\)* )zfs=(off|no)( |$)' /proc/cmdline && exit 3
48 fi
49
50 start()
51 {
52 [ -f "$LOCKFILE" ] && return 3
53
54 # Delay until all required block devices are present.
55 udevadm settle
56
57 # Load the zfs module stack
58 /sbin/modprobe zfs
59
60 # Start the ZED for event handling
61 action $"Starting ZFS Event Daemon" daemon --pidfile="$ZED_PIDFILE" "$ZED"
62
63 # Ensure / exists in /etc/mtab, if not update mtab accordingly.
64 # This should be handled by rc.sysinit but lets be paranoid.
65 awk '$2 == "/" { exit 1 }' /etc/mtab
66 RETVAL=$?
67 if [ "$RETVAL" -eq 0 ]; then
68 /bin/mount -f /
69 fi
70
71 # Import all pools described by the cache file, and then mount
72 # all filesystem based on their properties.
73 if [ "$USE_DISK_BY_ID" -eq 1 ]; then
74 action $"Importing ZFS pools" \
75 "$ZPOOL" import -d /dev/disk/by-id -aN 2>/dev/null
76 ret=$?
77 [ "$ret" -eq 0 ] && POOL_IMPORTED=1
78 elif [ -f "$ZPOOL_CACHE" ] ; then
79 action $"Importing ZFS pools" \
80 "$ZPOOL" import -c "$ZPOOL_CACHE" -aN 2>/dev/null
81 ret=$?
82 [ "$ret" -eq 0 ] && POOL_IMPORTED=1
83 fi
84
85 if [ -n "$POOL_IMPORTED" ]; then
86 if [ "$VERBOSE_MOUNT" -eq 1 ]; then
87 verbose=v
88 fi
89
90 if [ "$DO_OVERLAY_MOUNTS" -eq 1 ]; then
91 overlay=O
92 fi
93
94 action $"Mounting ZFS filesystems" \
95 "$ZFS" mount -a$verbose$overlay$MOUNT_EXTRA_OPTIONS
96
97 action $"Sharing ZFS filesystems" \
98 "$ZFS" share -a
99 fi
100
101 touch "$LOCKFILE"
102 }
103
104 stop()
105 {
106 [ ! -f "$LOCKFILE" ] && return 3
107
108 action $"Unsharing ZFS filesystems" "$ZFS" unshare -a
109 action $"Unmounting ZFS filesystems" "$ZFS" umount -a
110 action $"Shutting down ZFS Event Daemon" killproc -p "$ZED_PIDFILE" "$ZED"
111
112 rm -f "$LOCKFILE"
113 }
114
115 status()
116 {
117 [ ! -f "$LOCKFILE" ] && return 3
118
119 "$ZPOOL" status && echo "" && "$ZPOOL" list
120 }
121
122 case "$1" in
123 start)
124 start
125 RETVAL=$?
126 ;;
127 stop)
128 stop
129 RETVAL=$?
130 ;;
131 status)
132 status
133 RETVAL=$?
134 ;;
135 restart)
136 stop
137 start
138 ;;
139 condrestart)
140 if [ -f "$LOCKFILE" ]; then
141 stop
142 start
143 fi
144 ;;
145 *)
146 echo $"Usage: $0 {start|stop|status|restart|condrestart}"
147 ;;
148 esac
149
150 exit $RETVAL