de2ea8a2d91da096a62e7b7f39af90d0c4bf1da1
[zfs.git] / etc / init.d / zfs.arch.in
1 #!/bin/bash
2
3 . /etc/rc.conf
4 . /etc/rc.d/functions
5
6 ZFS="@sbindir@/zfs"
7 ZPOOL="@sbindir@/zpool"
8 ZPOOL_CACHE="@sysconfdir@/zfs/zpool.cache"
9
10 case "$1" in
11   start)
12     stat_busy "Starting zfs"
13
14     if [ ! -c /dev/zfs ]; then
15       modprobe zfs
16       if [ $? -ne 0 ]; then
17         stat_fail
18         exit 1
19       fi
20     fi
21
22     # Import ZFS pools (via cache file)
23     if [ -f $ZPOOL_CACHE ]; then
24       $ZPOOL import -c $ZPOOL_CACHE -aN 2>/dev/null
25       if [ $? -ne 0 ]; then
26         stat_fail
27         exit 1
28       fi
29     fi
30
31     # Mount ZFS filesystems
32     $ZFS mount -a
33     if [ $? -ne 0 ]; then
34         stat_fail
35         exit 1
36     fi
37
38     # Export ZFS flesystems
39     $ZFS share -a
40     if [ $? -ne 0 ]; then
41         stat_fail
42         exit 1
43     fi
44
45     add_daemon zfs
46     stat_done
47     ;;
48   stop)
49     stat_busy "Stopping zfs"
50     $ZFS umount -a
51     rm_daemon zfs
52     stat_done
53     ;;
54   restart)
55     $0 stop
56     $0 start
57     ;;
58   *)
59     echo "usage: $0 {start|stop|restart}"
60 esac
61
62 exit 0