275160355c7b67ff6f83fd2636ffbf74e6d36160
[zfs.git] / etc / init.d / zfs.fedora
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 # 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 # Source function library.
27 . /etc/rc.d/init.d/functions
28
29 # Source zfs configuration.
30 [ -f /etc/sysconfig/zfs ] &&  . /etc/sysconfig/zfs
31
32 RETVAL=0
33
34 LOCKFILE=/var/lock/subsys/zfs
35 CACHEFILE=/etc/zfs/zpool.cache
36 ZPOOL=/usr/sbin/zpool
37 ZFS=/usr/sbin/zfs
38
39 [ -x $ZPOOL ] || exit 1
40 [ -x $ZFS ] || exit 2
41
42 start()
43 {
44         [ -f $LOCKFILE ] && return 3
45
46         # Requires selinux policy which has not been written.
47         if [ -r "/selinux/enforce" ] &&
48            [ "$(cat /selinux/enforce)" = "1" ]; then
49                 action "SELinux ZFS policy required: " /bin/false
50                 return 4
51         fi
52
53         # Load the zfs module stack
54         /sbin/modprobe zfs
55
56         # Ensure / exists in /etc/mtab, if not update mtab accordingly.
57         # This should be handled by rc.sysinit but lets be paranoid.
58         awk '$2 == "/" { exit 1 }' /etc/mtab
59         RETVAL=$?
60         if [ $RETVAL -eq 0 ]; then
61                 /bin/mount -f /
62         fi
63
64         # Import all pools described by the cache file, and then mount
65         # all filesystem based on their properties.
66         if [ -f $CACHEFILE ] ; then
67                 action $"Importing ZFS pools: " \
68                         $ZPOOL import -c $CACHEFILE -aN 2>/dev/null
69                 action $"Mounting ZFS filesystems: " \
70                         $ZFS mount -a
71         fi
72         
73         touch $LOCKFILE
74 }
75
76 stop()
77 {
78         [ ! -f $LOCKFILE ] && return 3
79
80         action $"Unmounting ZFS filesystems: " $ZFS umount -a
81
82         rm -f $LOCKFILE
83 }
84
85 status()
86 {
87         [ ! -f $LOCKFILE ] && return 3
88
89         $ZPOOL status && echo && $ZPOOL list
90 }
91
92 case "$1" in
93         start)
94                 start
95                 RETVAL=$?
96                 ;;
97         stop)
98                 stop
99                 RETVAL=$?
100                 ;;
101         status)
102                 status
103                 RETVAL=$?
104                 ;;
105         restart)
106                 stop
107                 start
108                 ;;
109         condrestart)
110                 if [ -f $LOCKFILE ]; then
111                         stop
112                         start
113                 fi
114                 ;;
115         *)
116                 echo $"Usage: $0 {start|stop|status|restart|condrestart}"
117                 ;;
118 esac
119
120 exit $RETVAL