a84c1df239207260ef0aa8a30affa151861ad442
[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=/usr/sbin/zpool
36 ZFS=/usr/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         # 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                 log_begin_msg "Importing ZFS pools"
68                 $ZPOOL import -c $CACHEFILE -aN 2>/dev/null
69                 log_end_msg $?
70
71                 log_begin_msg "Mounting ZFS filesystems"
72                 $ZFS mount -a
73                 log_end_msg $?
74         fi
75         
76         touch $LOCKFILE
77 }
78
79 stop()
80 {
81         [ ! -f $LOCKFILE ] && return 3
82
83         log_begin_msg "Unmounting ZFS filesystems"
84         $ZFS umount -a
85         log_end_msg $?
86
87         rm -f $LOCKFILE
88 }
89
90 status()
91 {
92         [ ! -f $LOCKFILE ] && return 3
93
94         $ZPOOL status && echo && $ZPOOL list
95 }
96
97 case "$1" in
98         start)
99                 start
100                 RETVAL=$?
101                 ;;
102         stop)
103                 stop
104                 RETVAL=$?
105                 ;;
106         status)
107                 status
108                 RETVAL=$?
109                 ;;
110         restart)
111                 stop
112                 start
113                 ;;
114         condrestart)
115                 if [ -f $LOCKFILE ]; then
116                         stop
117                         start
118                 fi
119                 ;;
120         *)
121                 echo $"Usage: $0 {start|stop|status|restart|condrestart}"
122                 ;;
123 esac
124
125 exit $RETVAL