]>
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 | |
ea04106b AX |
14 | # Required-Start: $local_fs |
15 | # Required-Stop: $local_fs | |
16 | # Default-Start: 2 3 4 5 | |
17 | # Default-Stop: 0 1 6 | |
712f8bd8 | 18 | # Should-Stop: |
712f8bd8 BB |
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 | ||
ea04106b | 25 | # Source function library. |
712f8bd8 BB |
26 | . /etc/rc.d/init.d/functions |
27 | ||
ea04106b AX |
28 | LOCKFILE=/var/lock/zfs |
29 | ZED="@sbindir@/zed" | |
30 | ZED_PIDFILE="@runstatedir@/zed.pid" | |
5faa9c03 KF |
31 | ZFS="@sbindir@/zfs" |
32 | ZPOOL="@sbindir@/zpool" | |
ea04106b AX |
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="" | |
712f8bd8 | 38 | |
ea04106b AX |
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 | |
712f8bd8 BB |
49 | |
50 | start() | |
51 | { | |
ea04106b | 52 | [ -f "$LOCKFILE" ] && return 3 |
712f8bd8 | 53 | |
ea04106b AX |
54 | # Delay until all required block devices are present. |
55 | udevadm settle | |
712f8bd8 | 56 | |
ea04106b AX |
57 | # Load the zfs module stack |
58 | /sbin/modprobe zfs | |
712f8bd8 | 59 | |
ea04106b AX |
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 / | |
3af2ce4d | 69 | fi |
2a005961 | 70 | |
ea04106b AX |
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 | |
712f8bd8 | 83 | fi |
712f8bd8 | 84 | |
ea04106b AX |
85 | if [ -n "$POOL_IMPORTED" ]; then |
86 | if [ "$VERBOSE_MOUNT" -eq 1 ]; then | |
87 | verbose=v | |
88 | fi | |
712f8bd8 | 89 | |
ea04106b AX |
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 | |
8b0cf399 | 96 | |
ea04106b AX |
97 | action $"Sharing ZFS filesystems" \ |
98 | "$ZFS" share -a | |
99 | fi | |
712f8bd8 | 100 | |
ea04106b | 101 | touch "$LOCKFILE" |
712f8bd8 BB |
102 | } |
103 | ||
104 | stop() | |
105 | { | |
ea04106b AX |
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" | |
712f8bd8 BB |
111 | |
112 | rm -f "$LOCKFILE" | |
113 | } | |
114 | ||
ea04106b AX |
115 | status() |
116 | { | |
117 | [ ! -f "$LOCKFILE" ] && return 3 | |
118 | ||
119 | "$ZPOOL" status && echo "" && "$ZPOOL" list | |
120 | } | |
121 | ||
712f8bd8 BB |
122 | case "$1" in |
123 | start) | |
124 | start | |
125 | RETVAL=$? | |
126 | ;; | |
127 | stop) | |
128 | stop | |
129 | RETVAL=$? | |
130 | ;; | |
131 | status) | |
ea04106b AX |
132 | status |
133 | RETVAL=$? | |
712f8bd8 BB |
134 | ;; |
135 | restart) | |
136 | stop | |
137 | start | |
138 | ;; | |
139 | condrestart) | |
ea04106b | 140 | if [ -f "$LOCKFILE" ]; then |
712f8bd8 BB |
141 | stop |
142 | start | |
143 | fi | |
144 | ;; | |
145 | *) | |
146 | echo $"Usage: $0 {start|stop|status|restart|condrestart}" | |
712f8bd8 BB |
147 | ;; |
148 | esac | |
149 | ||
150 | exit $RETVAL |