mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2024-12-28 03:49:38 +03:00
01c0e61da0
To support automatically mounting your zfs on filesystem on boot a basic init script is needed. Unfortunately, every distribution has their own idea of the _right_ way to do things. Rather than write one very complicated portable init script, which would be invariably replaced by the distributions own anyway. I have instead added support to provide multiple distribution specific init scripts. The correct init script for your distribution will be selected by ZFS_AC_DEFAULT_PACKAGE which will set DEFAULT_INIT_SCRIPT. During 'make install' the correct script for your system will be installed from zfs/etc/init.d/zfs.DEFAULT_INIT_SCRIPT to the usual /etc/init.d/zfs location. Currently, there is zfs.fedora and a more generic zfs.lsb init script. Hopefully, the distribution maintainers who know best how they want their init scripts to function will feedback their approved versions to be included in the project. This change does not consider upstart jobs but I'm not at all opposed to add that sort of thing.
121 lines
2.5 KiB
Bash
121 lines
2.5 KiB
Bash
#!/bin/bash
|
|
#
|
|
# zfs This script will mount/umount the zfs filesystems.
|
|
#
|
|
# chkconfig: 2345 01 99
|
|
# description: This script will mount/umount the zfs filesystems during
|
|
# system boot/shutdown. Configuration of which filesystems
|
|
# should be mounted is handled by the zfs 'mountpoint' and
|
|
# 'canmount' properties. See the zfs(8) man page for details.
|
|
# It is also responsible for all userspace zfs services.
|
|
#
|
|
### BEGIN INIT INFO
|
|
# Provides: zfs
|
|
# Required-Start: $local_fs
|
|
# Required-Stop: $local_fs
|
|
# Should-Start:
|
|
# Should-Stop:
|
|
# Default-Start: 2 3 4 5
|
|
# Default-Stop: 1
|
|
# Short-Description: Mount/umount the zfs filesystems
|
|
# Description: ZFS is an advanced filesystem designed to simplify managing
|
|
# and protecting your data. This service mounts the ZFS
|
|
# filesystems and starts all related zfs services.
|
|
### END INIT INFO
|
|
|
|
# Source function library.
|
|
. /etc/rc.d/init.d/functions
|
|
|
|
# Source zfs configuration.
|
|
[ -f /etc/sysconfig/zfs ] && . /etc/sysconfig/zfs
|
|
|
|
RETVAL=0
|
|
|
|
LOCKFILE=/var/lock/subsys/zfs
|
|
CACHEFILE=/etc/zfs/zpool.cache
|
|
ZPOOL=/usr/sbin/zpool
|
|
ZFS=/usr/sbin/zfs
|
|
|
|
[ -x $ZPOOL ] || exit 1
|
|
[ -x $ZFS ] || exit 2
|
|
|
|
start()
|
|
{
|
|
[ -f $LOCKFILE ] && return 3
|
|
|
|
# Requires selinux policy which has not been written.
|
|
if [ -r "/selinux/enforce" ] &&
|
|
[ "$(cat /selinux/enforce)" = "1" ]; then
|
|
action "SELinux ZFS policy required: " /bin/false
|
|
return 4
|
|
fi
|
|
|
|
# Load the zfs module stack
|
|
/sbin/modprobe zfs
|
|
|
|
# Ensure / exists in /etc/mtab, if not update mtab accordingly.
|
|
# This should be handled by rc.sysinit but lets be paranoid.
|
|
awk '$2 == "/" { exit 1 }' /etc/mtab
|
|
RETVAL=$?
|
|
if [ $RETVAL -eq 0 ]; then
|
|
/bin/mount -f /
|
|
fi
|
|
|
|
# Import all pools described by the cache file, and then mount
|
|
# all filesystem based on their properties.
|
|
if [ -f $CACHEFILE ] ; then
|
|
action $"Importing ZFS pools: " \
|
|
$ZPOOL import -c $CACHEFILE -aN 2>/dev/null
|
|
action $"Mounting ZFS filesystems: " \
|
|
$ZFS mount -a
|
|
fi
|
|
|
|
touch $LOCKFILE
|
|
}
|
|
|
|
stop()
|
|
{
|
|
[ ! -f $LOCKFILE ] && return 3
|
|
|
|
action $"Unmounting ZFS filesystems: " $ZFS umount -a
|
|
|
|
rm -f $LOCKFILE
|
|
}
|
|
|
|
status()
|
|
{
|
|
[ ! -f $LOCKFILE ] && return 3
|
|
|
|
$ZPOOL status && echo && $ZPOOL list
|
|
}
|
|
|
|
case "$1" in
|
|
start)
|
|
start
|
|
RETVAL=$?
|
|
;;
|
|
stop)
|
|
stop
|
|
RETVAL=$?
|
|
;;
|
|
status)
|
|
status
|
|
RETVAL=$?
|
|
;;
|
|
restart)
|
|
stop
|
|
start
|
|
;;
|
|
condrestart)
|
|
if [ -f $LOCKFILE ]; then
|
|
stop
|
|
start
|
|
fi
|
|
;;
|
|
*)
|
|
echo $"Usage: $0 {start|stop|status|restart|condrestart}"
|
|
;;
|
|
esac
|
|
|
|
exit $RETVAL
|