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