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